From af9d261376a3e9105c47c15c03385517ab917d51 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Thu, 13 Jun 2024 03:39:25 +0300 Subject: [PATCH 01/55] add new tests for aggregate , order by , UnWind , With --- .../polypheny/db/cypher/AggregateTest.java | 299 +++++++++++++++++- .../db/cypher/CypherTestTemplate.java | 1 + .../org/polypheny/db/cypher/OrderByTest.java | 146 +++++++++ .../org/polypheny/db/cypher/UnwindTest.java | 125 ++++++++ .../org/polypheny/db/cypher/WithTest.java | 233 +++++++++++++- 5 files changed, 786 insertions(+), 18 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java index c6632deb32..74e9cb8b2e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; public class AggregateTest extends CypherTestTemplate { @@ -47,13 +48,20 @@ public void singleCountAggregateTest() { GraphResult res = execute( "MATCH (n:Person) RETURN count(*)" ); - containsRows( res, true, true, - Row.of( TestLiteral.from( 4 ) ) ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 5 ) ) ); + execute( SINGLE_EDGE_2 ); + res = execute( "MATCH (n:Person) RETURN count(*)" ); + + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 7) ) ); + + + - containsRows( res, true, true, - Row.of( TestLiteral.from( 6 ) ) ); } @@ -66,12 +74,20 @@ public void countFieldAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN n.name, count(*)" ); - containsRows( res, true, false, + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 2 ) ) ); } + @Test + public void countNullAggregateTest() { + + GraphResult res = execute( "MATCH (n) RETURN count(*)" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 0))); + } @Test @@ -84,13 +100,27 @@ public void countRenameFieldAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN n.name, count(*) AS c" ); assert res.getHeader()[1].name.equals( "c" ); - containsRows( res, true, false, + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 2 ) ) ); } + @Test + public void countFieldRenameFieldAggregateTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2); + + GraphResult res = execute( "MATCH (n) RETURN n.name, count(n.age) AS c" ); + + + assert containsRows(res, true, false, + Row.of(TestLiteral.from("Hans") , TestLiteral.from( 0 )), + Row.of( TestLiteral.from( "Max"), TestLiteral.from( 1 ) )); + + } + @Test public void doubleCountRenameAggregateTest() { @@ -101,7 +131,7 @@ public void doubleCountRenameAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN n.name, n.age, count(*) AS c" ); - containsRows( res, true, false, + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( null ), TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 3 ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( null ), TestLiteral.from( 1 ) ), @@ -111,21 +141,109 @@ public void doubleCountRenameAggregateTest() { @Test - public void singleAvgAggregateTest() { + public void countPropertyAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute("MATCH (n) RETURN count(n.age)"); + assert containsRows(res, true, false, Row.of(TestLiteral.from(0))); + } + + @Test + public void countDistinctFunctionTest() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_1); + + + GraphResult res = execute("MATCH (n) RETURN count(DISTINCT n.name)"); + assert containsRows(res, true, false, Row.of(TestLiteral.from(1))); + + + + } + + + + @Test + public void singleAvgAggregateTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 + ); execute( SINGLE_EDGE_1 ); execute( SINGLE_EDGE_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); GraphResult res = execute( "MATCH (n) RETURN avg(n.age)" ); + // Printing the data using Arrays.deepToString + System.out.print( "Alyaa :" ); + String[][] data = res.getData(); + System.out.println( Arrays.deepToString(data)); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 26.333333333333333333333333333333 ) ) ); + + } + + @Test + public void avgNullAggregateTest() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_2); + GraphResult res = execute("MATCH (p:Person) RETURN avg(p.age)"); + + assert containsRows(res, true, false, Row.of(TestLiteral.from(null))); + } + + @Test + public void avgRenameAggregationTest() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute("MATCH (p:Person) RETURN avg(p.age) AS ages"); + assert containsRows(res, true, false, Row.of(TestLiteral.from(38))); + } + @Test + public void avgRenameFieldAggregationTest() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2 ); + execute(SINGLE_NODE_PERSON_COMPLEX_3 ); + + + GraphResult res = execute("MATCH (p:Person) RETURN p.depno As depNumber , avg(p.age) As avgAge"); + containsRows(res, true, false, + Row.of(TestLiteral.from(13) , TestLiteral.from( 38 )), + Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) )); + } + + @Test + public void singleCollectAggregationTest() { + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2 ); - containsRows( res, true, false, - Row.of( TestLiteral.from( 24 ) ) ); + GraphResult res = execute("MATCH (p:Person) RETURN collect(p.age) "); + } + @Test + public void collectRenameAggregationTest() { + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute("MATCH (p:Person) RETURN collect(p.age) AS ages"); } + @Test + public void collectRenameFieldAggregationTest() { + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute("MATCH (p:Person) RETURN collect(p.age) AS ages , p.depno AS depNumber"); + } + @Test + public void collectNullAggregationTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute("MATCH (p:Person) RETURN collect(p.age)"); + } @Test public void singleMinMaxAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -135,16 +253,75 @@ public void singleMinMaxAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); GraphResult res = execute( "MATCH (n) RETURN min(n.age)" ); - - containsRows( res, true, false, + assert containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ) ); - res = execute( "MATCH (n) RETURN max(n.age)" ); - containsRows( res, true, false, + + res = execute( "MATCH (n) RETURN max(n.age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); } + @Test void minMaxNullAggregateTest() + { execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from(null ) ) ); + + res = execute( "MATCH (n) RETURN max(n.age) as ageMax" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( null ) ) ); + + + } + + + + @Test + public void minMaxRenameAggregateTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from(31) )); + + + res = execute( "MATCH (n) RETURN max(n.age) as ageMax" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from(45) )); + + + } + + @Test + public void minMaxRenameFieldAggregateTest() { + + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (n) RETURN n.depno as depNumber , min(n.age) as ageMin" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from(13 ), TestLiteral.from(31) ), + Row.of( TestLiteral.from(14 ), TestLiteral.from(32) )); + + + res = execute( "MATCH (n) RETURN n.depno as depNumber , max(n.age) as ageMax" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from(13 ), TestLiteral.from(45) ), + Row.of( TestLiteral.from(14 ), TestLiteral.from(32) )); + + } @Test @@ -154,7 +331,99 @@ public void singleSumAggregateTest() { execute( SINGLE_EDGE_1 ); execute( SINGLE_EDGE_2 ); - execute( "MATCH (n) RETURN sum(n.age)" ); + GraphResult res = execute( "MATCH (n) RETURN sum(n.age)" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 34 ) ) ); + } + + @Test + public void sumNullAggregationTest () + { + execute(SINGLE_NODE_PERSON_1); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (n) RETURN sum(n.age)" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 0 ) ) ); + + /// Printing the data using Arrays.deepToString + System.out.print( "Alyaa :" ); + String[][] data = res.getData(); + System.out.println( Arrays.deepToString(data)); + } + @Test + public void sumRenameAggregationTest() { + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + + GraphResult res = execute("MATCH (p:Person) RETURN sum(p.age) As totalAge "); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 76 ) ) ); + + + } + @Test + public void sumRenameFieldAggregationTest() { + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_3); + + GraphResult res = execute("MATCH (p:Person) RETURN sum(p.age) AS totalAge, p.depno AS depNumber,"); + assert containsRows(res, true, false, + Row.of(TestLiteral.from(13) , TestLiteral.from( 76 )), + Row.of(TestLiteral.from(14) , TestLiteral.from( 32 ))); + + + + } + @Test + public void singleStDevAggregateTest() + { execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + GraphResult res = execute("MATCH (p:Person) RETURN stdev(p.age) "); + assert containsRows(res, true, false, + Row.of( TestLiteral.from( 9.8994949))); + + + } + @Test + public void stDevNullAggregateTest() + { execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_2); + GraphResult res = execute("MATCH (p:Person) RETURN stdev(p.age) "); + assert containsRows(res, true, false, + Row.of( TestLiteral.from( null))); + } + @Test + public void stDevRenameAggregateTest() + { + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + GraphResult res = execute("MATCH (p:Person) RETURN stdev(p.age) AS Stdev "); + assert containsRows(res, true, false, + Row.of( TestLiteral.from( 9.8994949))); + + } + @Test + public void stDevRenameFieldAggregateTest() + { + execute(SINGLE_NODE_PERSON_COMPLEX_1); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + + GraphResult res = execute("MATCH (p:Person) RETURN stdev(p.age) AS Stdev , n.depno As department"); + assert containsRows(res, true, false, + Row.of( TestLiteral.from( 9.8994949) , TestLiteral.from( 13 ))); + } + + + + + + + + + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java index 90e7e5d9f4..b934717d8d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java @@ -58,6 +58,7 @@ public class CypherTestTemplate { protected static final String SINGLE_NODE_PERSON_COMPLEX_1 = "CREATE (p:Person {name: 'Ann', age: 45, depno: 13})"; protected static final String SINGLE_NODE_PERSON_COMPLEX_2 = "CREATE (p:Person {name: 'Bob', age: 31, depno: 13})"; + protected static final String SINGLE_NODE_PERSON_COMPLEX_3 = "CREATE (p:Person {name: 'Alex', age: 32, depno: 14})"; protected static final String SINGLE_NODE_ANIMAL = "CREATE (a:Animal {name:'Kira', age:3, type:'dog'})"; protected static final String SINGLE_EDGE_1 = "CREATE (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'})"; protected static final String SINGLE_EDGE_2 = "CREATE (p:Person {name: 'Max'})-[rel:KNOWS {since: 1994}]->(a:Person {name:'Hans', age:31})"; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java b/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java index 089dd2ce6e..1247269a31 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java @@ -20,8 +20,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.adapter.java.Array; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; public class OrderByTest extends CypherTestTemplate { @@ -206,5 +208,149 @@ assert containsRows( res, true, true, Row.of( KIRA ), Row.of( KIRA ) ); } + @Test + public void renameWithClauseSortTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + GraphResult res = execute( "MATCH (p:Person) WITH p.age AS personAge RETURN personAge ORDER BY personAge" ); + assert containsRows( res , true ,true , + Row.of( TestLiteral.from( 31 ) ), + Row.of(TestLiteral.from( 45 )) ); + + } + @Test + public void renameWithClauseOrderByWithLimitTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC LIMIT 2 RETURN age" ); + + assert containsRows( res , true ,true , + Row.of( TestLiteral.from( 45 ) ), + Row.of(TestLiteral.from( 32 )) ); + + + + } + + @Test + public void renameWithClauseDoubleOrderByWithLimitTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC LIMIT 3 RETURN department , name " ); + + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Ann" ) ), + Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ) , + Row.of( TestLiteral.from( 14 ),TestLiteral.from( "Alex" ))); + + + + + } + + @Test + public void renameWithClauseDoubleOrderByTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC RETURN department , name" ); + + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Ann" ) ), + Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ) , + Row.of( TestLiteral.from( 14 ),TestLiteral.from( "Alex" ))); + + + + + } + @Test + public void renameUnwindSortTest() { + GraphResult res = execute( "UNWIND [1, true,3.14] AS i RETURN i ORDER BY i" ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( true ) ), + Row.of( TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( 3.14 ) ) ); + + + } + @Test + public void renameWithClauseWithRenameUnwindSortTest () + { + + GraphResult res = execute( "WITH [1 ,2 ,3] AS number UNWIND number AS n RETURN n ORDER BY n" ); + + assert containsRows( res , true , true , + Row.of( TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( 3 ) ) ); + } + + @Test + public void renameWithMixedTypesWithRenameUnwindSortTest () + { + + + GraphResult res = execute( "WITH [1 ,2 ,'4'] AS number UNWIND number AS n RETURN n ORDER BY n" ); + + assert containsRows( res , true , true , + Row.of( TestLiteral.from( '4') ), + Row.of( TestLiteral.from( 1) ), + Row.of( TestLiteral.from( 2 ) ) ); + } + + @Test + public void renameAvgAggregateFieldSortTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person)RETURN p.depno As Department ,avg(p.age) AS averageAge ORDER BY averageAge" ); + assert containsRows( res , true , true , + Row.of( TestLiteral.from( 14) , TestLiteral.from( 32 )), + Row.of( TestLiteral.from( 13 ) ,TestLiteral.from( 38 ))); + + } + + @Test + public void renameWithClauseOrderByWithSkipTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC SKIP 1 Limit 1 RETURN age" ); + + assert containsRows( res , true ,true , + Row.of( TestLiteral.from( 32 ) ), + Row.of(TestLiteral.from( 31)) ); + + } + + @Test + public void renameWithClauseOrderByWithSkipLimitTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC SKIP 1 Limit 1 RETURN age" ); + + assert containsRows( res , true ,true , + Row.of( TestLiteral.from( 32 ) )); + + + } + + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java index 8790c7d29f..f2ee7ac441 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java @@ -16,10 +16,18 @@ package org.polypheny.db.cypher; +import com.fasterxml.jackson.databind.introspect.AnnotationCollector.TwoAnnotations; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.polypheny.db.cypher.helper.TestGraphObject; import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; +import java.util.List; public class UnwindTest extends CypherTestTemplate { @@ -80,4 +88,121 @@ public void nodePropertyUnwind() { Row.of( TestLiteral.from( 1 ) ) ); } + + @Test + public void minMaxAggregateSimpleUnWind() { + GraphResult res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] AS val RETURN min(val)" ); + containsRows( res, true, false, Row.of( TestLiteral.from( '1' ) ) ); + + res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] As val RETURN max(val)" ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); + + } + + + + @Test + public void minMaxAggregateListOfListUnwind() { + GraphResult res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN min(val)" ); + + res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN max(val)" ); + + + } + + + @Test + public void maxMinAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); + res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); + + } + + + @Test + public void sumAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN sum(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); + + } + + + @Test + public void AvgAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); + + } + + + @Test + public void CollectAggregateUnWind () + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); + + } + + + + + + @Test + public void countUnWind() { + GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); + + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 3))); + + } + + @Test + public void distinctUnWind() { + GraphResult res = execute( "UNWIND [3, 3 ,2 ,1 ] AS i RETURN DISTINCT i" ); + assert res.getData().length == 3; + assert containsRows( res , true , false , + Row.of(TestLiteral.from(3)) , + Row.of( TestLiteral.from( 2 )) ,Row.of( TestLiteral.from( 1) )); + + + } + + + + + @Test + public void ConditionalLogicUnWind() + { + GraphResult res = execute( "UNWIND [1, 2, 3, 4, 5] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); + + } + + + + + @Test + public void mapStructureUnWind() + { + GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); + assert containsRows( res , true , false , Row.of( TestLiteral.from( "Alice" ) ),Row.of( TestLiteral.from( 30 ) ) ); + + } + + + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java index 068f3e9dd4..5a3ac8ccba 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java @@ -30,13 +30,56 @@ public void reset() { createGraph(); } + @Test + public void singleVariableWithTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (n:Person) WITH n.name RETURN n.name" ); + + + } @Test - public void addVariableTest() { + public void multipleVariablesWithTest() + { + + GraphResult res = execute( "MATCH (p:Person) WITH p.name , p.age , p.depno AS person_age RETURN person_name, person_age;" ); + } + + @Test + public void renameWithTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (n:Person) WITH n.name AS name, n RETURN name, n" ); + assertNode( res, 2); + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( "Max" ), MAX ), + Row.of( TestLiteral.from( "Hans" ),HANS )); + + } + + @Test + public void startWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person) WITH n.name, n WHERE n.name STARTS WITH 'H' RETURN n" ); + + + assert containsRows( res, true, true, + Row.of( HANS ) ); + + } + + @Test + public void startRenameWithTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (n:Person) WITH n.name as name , n WHERE name STARTS WITH 'H' RETURN n" ); assertNode( res, 0 ); assert containsRows( res, true, true, @@ -44,9 +87,20 @@ assert containsRows( res, true, true, } + @Test + public void endWithTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (n:Person) WITH n.name , n WHERE n.name ENDS WITH 'x' RETURN name, n" ); + assertNode( res, 1 ); + + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); + + } @Test - public void renameVariableTest() { + public void endRenameWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); @@ -59,7 +113,7 @@ public void renameVariableTest() { @Test - public void starTest() { + public void containsWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_EDGE_1 ); @@ -73,5 +127,178 @@ public void starTest() { } // aggregate + @Test + public void avgAggregationRenameWithTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) WITH avg(p.age) as ageAvg RETURN ageAvg " ); + + assert containsRows( res, true, true, Row.of( TestLiteral.from(38 )) ); + + } + + @Test + public void maxMinAggregationRenameWithTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) WITH MAX(p.age) as ageMax RETURN ageMax " ); + + assert containsRows( res, true, true, Row.of( TestLiteral.from(45 )) ); + res = execute( "MATCH (p:Person) WITH MIN(p.age) as ageMin RETURN ageMin " ); + + assert containsRows( res, true, true, Row.of( TestLiteral.from(31 )) ); + } + @Test + public void countAggregationWithTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) WITH COUNT(*) as count RETURN count " ); + + assert containsRows( res, true, true, Row.of( TestLiteral.from(2 )) ); + + } + @Test + public void stDevAggregationWithTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) WITH STDEV(p.age) as ageStdev RETURN ageStdev " ); + + assert containsRows( res, true, true, Row.of( TestLiteral.from(9.8994949)) ); + + } + + @Test + public void collectAggregationWithTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) WITH COLLECT(p.age) as ageList RETURN ageList " ); + + assert containsRows( res, true, true, Row.of( TestLiteral.from(45) ,TestLiteral.from( 31 ) ) ); + + } + + @Test + public void mapStructureRenameWithTest() + { + GraphResult res = execute( "WITH {person: {name: 'Anne', age: 25}} AS p RETURN p" ); + } + + @Test + public void filterWithTest() + { execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person) WITH p WHERE p.age > 31 RETURN p.name, p.age" ); + + } + @Test + public void calculationWithTest() + { execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (p:Person) WITH p, p.age * 2 AS double_age RETURN p.name, double_age;" ); + } + + @Test + public void listWithTest() + { + GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers RETURN numbers" ); + + } + @Test + public void unWindListWithTest() + { + GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number RETURN number;" ); + } + @Test + public void unWindAndFilterListWithTest() + { + GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number WITH number WHERE number > 3 RETURN number" ); + } + @Test + public void unWindAndStartListWithTest() + { + GraphResult res = execute( "WITH ['John', 'Mark', 'Jonathan', 'Bill'] AS somenames UNWIND somenames AS names WITH names AS candidate WHERE candidate STARTS WITH 'Jo' RETURN candidate" ); + assert containsRows( res , true , false , Row.of( TestLiteral.from( "John" ) ),Row.of( TestLiteral.from( "Jonathan" ) ) ); + } + + @Test + public void unWindAndLogicalOperatorsListWithTest() { + GraphResult res = execute( "WITH [2, 4, 7, 9, 12] AS numberlist UNWIND numberlist AS number WITH number WHERE number = 4 OR (number > 6 AND number < 10) RETURN number" ); + assert containsRows( res, false, false, + Row.of( TestLiteral.from( 4 ) ), + Row.of( TestLiteral.from( 7 ) ), + Row.of( TestLiteral.from( 9 ) ) ); + } + + @Test + public void unWindAndWhereInListWithTest() + { + GraphResult res = execute( "WITH [2, 3, 4, 5] AS numberlist UNWIND numberlist AS number WITH number WHERE number IN [2, 3, 8] RETURN number" ) ; + assert containsRows( res , true , false , Row.of( TestLiteral.from( 2 ) ) , Row.of( TestLiteral.from( 3 ) )); + + } + + @Test + public void createNodeWithTest() + { + GraphResult res = execute( "WITH [1, 1.0] AS list CREATE ({l: list})" ); + + } + + @Test + public void distinctWithTest() + { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_PERSON_1); + + GraphResult res = execute( "MATCH (p:Person) WITH Distinct(p) Return p " ); + + } + @Test + public void existsWithTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age;" ); + + } + + @Test + public void limitWithTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (n) WITH n LIMIT 2 RETURN n.name, n.age;" ); + } + + @Test + public void SkipWithTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (n) WITH n SKIP 2 RETURN n.name, n.age;" ); + } + + @Test + public void conditionalLogicWithTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person) WITH p, CASE WHEN p.age < 30 THEN 'Young' HEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' ELSE 'Elderly END AS ageGroup RETURN p.name, p.age, ageGroup;" ) ; + + } } From df7321aba7850a793be1489d313bcfdcf89fa75c Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Thu, 13 Jun 2024 06:08:55 +0300 Subject: [PATCH 02/55] add new tests for merge test file , --- .../org/polypheny/db/cypher/MergeTest.java | 104 ++++++++++++++++++ .../org/polypheny/db/cypher/WithTest.java | 16 ++- 2 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java new file mode 100644 index 0000000000..4c457da547 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java @@ -0,0 +1,104 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.webui.models.results.GraphResult; + +@Slf4j +public class MergeTest extends CypherTestTemplate{ + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + @Test + public void singleNodeWithLabelMergeTest () + { + // new node + GraphResult res = execute( "MERGE (n:SomeOne ) RETURN n " ); + + // Exist node + + res = execute( "MERGE (n:Person) RETURN n" ); + } + + @Test + public void singleNodeWithPropertiesMergeTest() + { + GraphResult res = execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})RETURN charlie" ); + } + @Test + public void singleNodeWithPropertiesAndLabelMergeTest() + { + GraphResult res = execute( "MERGE (michael:Person {name: 'Michael Douglas'}) RETURN michael.name, michael.bornIn" ); + } + + @Test + public void singleNodeDerivedFromExistingNodeMergeTest() + { + GraphResult res = execute( "MATCH (p:Person {name: 'Max'}), (p:Person {name: 'Hans'}) MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:ACTED_IN]-(reiner) RETURN movie" ); + } + + @Test + public void createOrMatchNodeMergeTest () + { + // Create new node + GraphResult res = execute( "MERGE (n:Person {name: 'Alice'}) ON CREATE SET n.age = 30 ON MATCH SET n.age = 35 RETURN n" ); + + // Updated the Matched node + res = execute( "MERGE (n:Person {name: 'MAX'}) ON CREATE SET n.age = 30 ON MATCH SET n.age = 35 RETURN n" ); + } + + @Test + public void singleRelationShipMergeTest() + { + GraphResult res = execute( "MERGE (n1:Person {name: 'Alice'}) MERGE (n2:Person {name: 'Bob'}) MERGE (n1)-[r:KNOWS]->(n2) RETURN n1, n2, r" ); + + res = execute("MERGE (n1:Person {name: 'Hans'}) MERGE (n2:Person {name: 'Max'}) MERGE (n1)-[r:KNOWS ]->(n2) RETURN n1, n2, r"); + } + + @Test + public void multipleRelationShipsMergeTest() + { + GraphResult res = execute( "MATCH (p:Person {name: 'Max'}),(a:Animal {name:'Kira') MERGE (person)-[:Owner]->(movie:Movie)<-[:belong]-(Animal) RETURN movie" ); + + + } + @Test + public void undirectedRelationShipMergeTest() + { + GraphResult res = execute( "MERGE (n1:Person {name: 'Hans'}) MERGE (n2:Person {name: 'Max'}) MERGE (n1)-[r:KNOWS ]-(n2) RETURN n1, n2, r" ); + } + + @Test + public void MatchMergeMergeTest() + { + GraphResult res = execute( "MATCH (person:Person) MERGE (age:Age {name: person.age}) MERGE (person)-[r:Have]->(age) RETURN person.name, person.age, age" ); + } + @Test + public void createAndRelationShipMergeTest() + { + GraphResult res = execute( "MERGE (n:Person {name: 'MAX'}) ON CREATE SET n.created = timestamp() MERGE (m:Person {name: 'Bob'})ON CREATE SET m.created = timestamp()" ); + + res = execute("MERGE (n:Person {name: 'Bob'}) ON CREATE SET n.age = 30 MERGE (m:Person {name: 'Ann'})ON CREATE SET m.age = 50"); + } + + +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java index 5a3ac8ccba..69e506c653 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java @@ -35,16 +35,18 @@ public void singleVariableWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n:Person) WITH n.name RETURN n.name" ); + GraphResult res = execute( "MATCH (n:Person) WITH n RETURN n.name" ); } @Test - public void multipleVariablesWithTest() + public void multipleRenameVariablesWithTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH p.name , p.age , p.depno AS person_age RETURN person_name, person_age;" ); + GraphResult res = execute( "MATCH (p:Person) WITH p.name AS person_name , p.age AS person_age , p RETURN person_name, person_age , p.depno;" ); } @Test @@ -53,8 +55,6 @@ public void renameWithTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person) WITH n.name AS name, n RETURN name, n" ); - assertNode( res, 2); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ), Row.of( TestLiteral.from( "Hans" ),HANS )); @@ -301,4 +301,10 @@ public void conditionalLogicWithTest() } + @Test + public void orderByWithTest() + { + GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p" ); + } + } From 7f8ee4fe3c0364d0f01ca9458901941713f92e5c Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Fri, 14 Jun 2024 01:09:12 +0300 Subject: [PATCH 03/55] add tests for merge , delete and remove --- .../db/cypher/CypherTestTemplate.java | 7 ++ .../polypheny/db/cypher/DmlDeleteTest.java | 26 +++++ .../org/polypheny/db/cypher/MergeTest.java | 62 +++++++++--- .../org/polypheny/db/cypher/RemoveTest.java | 96 +++++++++++++++++++ 4 files changed, 179 insertions(+), 12 deletions(-) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java index b934717d8d..6ad8e70d44 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java @@ -54,11 +54,18 @@ public class CypherTestTemplate { private static final String GRAPH_NAME = "test"; protected static final String SINGLE_NODE_PERSON_1 = "CREATE (p:Person {name: 'Max'})"; protected static final String SINGLE_NODE_PERSON_2 = "CREATE (p:Person {name: 'Hans'})"; + protected static final String SINGLE_NODE_PERSON_EMPLOYEE = "CREATE (p:Person:Employee {name: 'Max'})"; protected static final String SINGLE_NODE_PERSON_COMPLEX_1 = "CREATE (p:Person {name: 'Ann', age: 45, depno: 13})"; protected static final String SINGLE_NODE_PERSON_COMPLEX_2 = "CREATE (p:Person {name: 'Bob', age: 31, depno: 13})"; + protected static final String SINGLE_NODE_PERSON_COMPLEX_3 = "CREATE (p:Person {name: 'Alex', age: 32, depno: 14})"; + protected static final String SINGLE_NODE_PERSON_COMPLEX_4 = "CREATE (charlie:Person {name: 'Charlie Sheen', bornIn: 'New York', chauffeurName: 'John Brown'})"; + protected static final String SINGLE_NODE_PERSON_COMPLEX_5 = "CREATE (martin:Person {name: 'Martin Sheen', bornIn: 'Ohio', chauffeurName: 'Bob Brown'})"; + protected static final String SINGLE_NODE_PERSON_COMPLEX_6 = "CREATE (michael:Person {name: 'Michael Douglas', bornIn: 'New Jersey', chauffeurName: 'John Brown'})"; + + protected static final String SINGLE_NODE_MOVIE = "CREATE (wallStreet:Movie {title: 'Wall Street'})"; protected static final String SINGLE_NODE_ANIMAL = "CREATE (a:Animal {name:'Kira', age:3, type:'dog'})"; protected static final String SINGLE_EDGE_1 = "CREATE (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'})"; protected static final String SINGLE_EDGE_2 = "CREATE (p:Person {name: 'Max'})-[rel:KNOWS {since: 1994}]->(a:Person {name:'Hans', age:31})"; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java index 8dc5ae6e95..d62843e292 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java @@ -92,5 +92,31 @@ assert containsRows( res, true, false, } + @Test + public void relationshipWithPropertiesDeleteTest() { + + } + + @Test + public void pathDeleteTest() + { + execute( "MATCH (p:Person {name: 'Alice'})-[r:WORKS_AT]->(c:Company {name: 'TechCorp'})\n" + + "DELETE r, p\n" ); + } + + @Test + public void NodeWithRelationshipsDeleteTest() + { + execute( "MATCH (n:Person {name: 'Carrie-Anne Moss'})\n" + + "DETACH DELETE n" ); + } + @Test + public void allNodesAndRelationshipsDeleteTest () + { + execute( "MATCH (n)\n" + + "DETACH DELETE n" ) ; + } + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java index 4c457da547..1abf01a4b9 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java @@ -38,11 +38,19 @@ public void singleNodeWithLabelMergeTest () res = execute( "MERGE (n:Person) RETURN n" ); } + @Test + public void singleNodeWithMultipleLabelsMergeTest() + { + GraphResult res = execute( "MERGE (robert:Critic:Viewer) RETURN labels(robert)" ); + } + + @Test public void singleNodeWithPropertiesMergeTest() { - GraphResult res = execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})RETURN charlie" ); + + GraphResult res = execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})RETURN charlie" ); } @Test public void singleNodeWithPropertiesAndLabelMergeTest() @@ -53,11 +61,21 @@ public void singleNodeWithPropertiesAndLabelMergeTest() @Test public void singleNodeDerivedFromExistingNodeMergeTest() { - GraphResult res = execute( "MATCH (p:Person {name: 'Max'}), (p:Person {name: 'Hans'}) MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:ACTED_IN]-(reiner) RETURN movie" ); + GraphResult res = execute( "MATCH (person:Person) MERGE (age:Age {ageNumber : person.age}) RETURN person.name, person.age, age" ); } + @Test + public void createWithMergeTest() + { + } @Test - public void createOrMatchNodeMergeTest () + public void matchWithMergeTest() + { + + } + + @Test + public void createOrMatchNodeWithMergeTest () { // Create new node GraphResult res = execute( "MERGE (n:Person {name: 'Alice'}) ON CREATE SET n.age = 30 ON MATCH SET n.age = 35 RETURN n" ); @@ -65,40 +83,60 @@ public void createOrMatchNodeMergeTest () // Updated the Matched node res = execute( "MERGE (n:Person {name: 'MAX'}) ON CREATE SET n.age = 30 ON MATCH SET n.age = 35 RETURN n" ); } + @Test + public void matchMultiplePropertiesMergeTest() + { + + } @Test - public void singleRelationShipMergeTest() + public void singleRelationshipMergeTest() { - GraphResult res = execute( "MERGE (n1:Person {name: 'Alice'}) MERGE (n2:Person {name: 'Bob'}) MERGE (n1)-[r:KNOWS]->(n2) RETURN n1, n2, r" ); + GraphResult res = execute( "MATCH (n1:Person {name: 'Alice'}) , (n2:Person {name: 'Bob'}) MERGE (n1)-[r:KNOWS]->(n2) RETURN n1, n2, r" ); - res = execute("MERGE (n1:Person {name: 'Hans'}) MERGE (n2:Person {name: 'Max'}) MERGE (n1)-[r:KNOWS ]->(n2) RETURN n1, n2, r"); + res = execute("MATCH (n1:Person {name: 'Hans'}) , (n2:Person {name: 'Max'}) MERGE (n1)-[r:KNOWS ]->(n2) RETURN n1, n2, r"); } @Test - public void multipleRelationShipsMergeTest() + public void multipleRelationshipsMergeTest() { GraphResult res = execute( "MATCH (p:Person {name: 'Max'}),(a:Animal {name:'Kira') MERGE (person)-[:Owner]->(movie:Movie)<-[:belong]-(Animal) RETURN movie" ); } @Test - public void undirectedRelationShipMergeTest() + public void undirectedRelationshipMergeTest() { - GraphResult res = execute( "MERGE (n1:Person {name: 'Hans'}) MERGE (n2:Person {name: 'Max'}) MERGE (n1)-[r:KNOWS ]-(n2) RETURN n1, n2, r" ); + + GraphResult res = execute( "MATCH (n1:Person {name: 'Hans'}) , (n2:Person {name: 'Max'}) MERGE (n1)-[r:KNOWS ]-(n2) RETURN n1, n2, r" ); } @Test - public void MatchMergeMergeTest() + public void relationshipOnTwoExistingNodeMergeTest() + { + GraphResult res = execute( "MATCH (n1:Person {name: 'Hans'}) MERGE (n2:Person {name: 'Bob'}) MERGE (n1)-[r:Knows]->(n2) RETURN person.name, person.age" ); + } + @Test + public void relationshipOnExistingNodeAndMergeNodeDerivedFromAnodeProperty () { - GraphResult res = execute( "MATCH (person:Person) MERGE (age:Age {name: person.age}) MERGE (person)-[r:Have]->(age) RETURN person.name, person.age, age" ); + GraphResult res = execute( "MATCH (person:Person) MERGE (person)-[r:Has_Age]->(age:Age {ageNumber: person.age}) RETURN person.name, person.age, age" ); } @Test - public void createAndRelationShipMergeTest() + public void createAndRelationshipMergeTest() { GraphResult res = execute( "MERGE (n:Person {name: 'MAX'}) ON CREATE SET n.created = timestamp() MERGE (m:Person {name: 'Bob'})ON CREATE SET m.created = timestamp()" ); res = execute("MERGE (n:Person {name: 'Bob'}) ON CREATE SET n.age = 30 MERGE (m:Person {name: 'Ann'})ON CREATE SET m.age = 50"); } + // do you want me to test this ?? + @Test + public void UniqueConstrainsMergeTest() + { + + } + + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java b/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java new file mode 100644 index 0000000000..fb93c7252f --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java @@ -0,0 +1,96 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.webui.models.results.GraphResult; + +@Slf4j +public class RemoveTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void labelRemoveTest() + { + GraphResult res = execute( "MATCH (n : Person {name: 'Max'}) REMOVE n:person RETURN n.name" ); + } + + + @Test + public void multipleLabelsRemoveTest() + { + GraphResult res = execute( "MATCH (n {name: 'Max'}) REMOVE n:Person:Employee RETURN n.name" ); + } + @Test + public void allLabelsRemoveTest(){ + + GraphResult res = execute( "MATCH (n:Person) SET n = {}" ); + } + + @Test + public void singlePropertyNodeRemoveTest() + { + GraphResult res = execute( "MATCH (n : Person {name: 'Bob'}) REMOVE a.age RETURN a.name, a.age" ); + + } + + @Test + public void multiplePropertiesRemoveTest() + { + GraphResult res = execute( "MATCH (n:Person {name: 'John'})\n" + + "REMOVE n.age, n.email, n.phone\n" + + "RETURN n\n" ) ; + } + @Test + public void allPropertiesNodeRemoveTest(){ + execute( SINGLE_NODE_PERSON_1 ); + GraphResult res = execute( "MATCH (n:Person) SET n = {}" ); + } + + @Test + public void singlePropertyRelationshipRemoveTest() + { + + } + + @Test + public void multiplePropertiesRelationshipRemoveTest() + { + GraphResult res = execute( "MATCH (p:Person)-[r:WORKS_AT]->(c:Company)\n" + + "WHERE p.name = 'John' AND c.name = 'TechCorp'\n" + + "REMOVE r.startDate, r.endDate, r.position\n" + + "RETURN r\n" ) ; + } + @Test + public void allPropertiesRelationshipRemoveTest(){ + + GraphResult res = execute( "MATCH (n:Person) SET n = {}" ); + } + + + + + +} From a767348d83ba3ed480c782496ad65e532708a0f0 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Fri, 14 Jun 2024 04:20:27 +0300 Subject: [PATCH 04/55] add tests for Case,Skip ,Union files --- .../org/polypheny/db/cypher/CaseTest.java | 83 ++++++++++++++++ .../org/polypheny/db/cypher/OrderByTest.java | 79 ---------------- .../org/polypheny/db/cypher/SkipTest.java | 94 +++++++++++++++++++ .../org/polypheny/db/cypher/UnionTest.java | 60 ++++++++++++ .../org/polypheny/db/cypher/WithTest.java | 16 ---- 5 files changed, 237 insertions(+), 95 deletions(-) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java new file mode 100644 index 0000000000..fe8d48b9c4 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + + +public class CaseTest extends CypherTestTemplate{ + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + @Test + public void simpleCaseTest() + { + execute( "MATCH (n:Person)\n" + + "RETURN\n" + + "CASE n.eyes\n" + + " WHEN 'blue' THEN 1\n" + + " WHEN 'brown', 'hazel' THEN 2\n" + + " ELSE 3\n" + + "END AS result, n.eyes" ); + } + + + @Test + public void GenericCaseTest() + { + execute( "MATCH (n:Person)\n" + + "RETURN\n" + + "CASE\n" + + " WHEN n.eyes = 'blue' THEN 1\n" + + " WHEN n.age < 40 THEN 2\n" + + " ELSE 3\n" + + "END AS result, n.eyes, n.age" ) ; + } + + @Test + + public void nullWithCaseTest() + { + execute( "MATCH (n:Person)\n" + + "RETURN n.name,\n" + + "CASE n.age\n" + + " WHEN null THEN -1\n" + + " ELSE n.age - 10\n" + + "END AS age_10_years_ago" ); + } + + + @Test + public void expressionsAndSucceedingClauses() + { + execute( "MATCH (n:Person)\n" + + "WITH n,\n" + + "CASE n.eyes\n" + + " WHEN 'blue' THEN 1\n" + + " WHEN 'brown' THEN 2\n" + + " ELSE 3\n" + + "END AS colorCode\n" + + "SET n.colorCode = colorCode\n" + + "RETURN n.name, n.colorCode" ); + } +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java b/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java index 1247269a31..8e3a8b8aac 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java @@ -96,85 +96,6 @@ public void nullOrderByTest() { } - - @Test - public void limitWithoutSortTest() { - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_1 ); - - GraphResult res = execute( "MATCH (n) RETURN n.name, n.age LIMIT 3" ); - - assert res.getData().length == 3; - } - - - @Test - public void limitWithSortTest() { - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_1 ); - - GraphResult res = execute( "MATCH (n) RETURN n.name ORDER BY n.name DESC LIMIT 3" ); - - assert res.getData().length == 3; - - assert containsRows( res, true, true, - Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Kira" ) ) ); - - } - - - @Test - public void skipWithoutSortTest() { - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_1 ); - - GraphResult res = execute( "MATCH (n) RETURN n.name, n.age SKIP 3" ); - - assert res.getData().length == 2; - } - - - @Test - public void skipWithSortTest() { - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_1 ); - - GraphResult res = execute( "MATCH (n) RETURN n.name ORDER BY n.name DESC SKIP 3" ); - - assert containsRows( res, true, true, - Row.of( TestLiteral.from( "Kira" ) ), - Row.of( TestLiteral.from( "Kira" ) ) ); - } - - - @Test - public void skipAndLimitWithoutSortTest() { - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_ANIMAL ); - execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_1 ); - - GraphResult res = execute( "MATCH (n) RETURN n.name SKIP 3 LIMIT 1" ); - - assert res.getData().length == 1; - } - - @Test public void skipAndLimitWithSortTest() { execute( SINGLE_NODE_ANIMAL ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java b/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java new file mode 100644 index 0000000000..7556750287 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java @@ -0,0 +1,94 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class SkipTest extends CypherTestTemplate{ + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + @Test + public void simpleSkipTest() { + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (n) RETURN n.name, n.age SKIP 3" ); + + assert res.getData().length == 2; + } + + @Test + public void orderBySkipTest() { + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (n) RETURN n.name ORDER BY n.name DESC SKIP 3" ); + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( "Kira" ) ), + Row.of( TestLiteral.from( "Kira" ) ) ); + } + + @Test + public void withAndSkipTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (n) WITH n SKIP 2 RETURN n.name, n.age;" ); + } + + @Test + public void returnSubsetSkipTest() + { + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (n) RETURN n.name SKIP 3 LIMIT 1" ); + + assert res.getData().length == 1; + } + + @Test + public void expressionAndSkipTest() + { + execute( "MATCH (n)\n" + + "RETURN n.name\n" + + "ORDER BY n.name\n" + + "SKIP 1 + toInteger(3*rand())" ); + } + + +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java new file mode 100644 index 0000000000..35f5cc8dbf --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class UnionTest extends CypherTestTemplate{ + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } +@Test + public void retainDuplicatesUnionTest() + { + execute( "MATCH (n:Actor)\n" + + "RETURN n.name AS name\n" + + "UNION ALL\n" + + "MATCH (n:Movie)\n" + + "RETURN n.title AS name" ); + + } + + @Test + public void removeDuplicatesUnionTest() + { + execute( "MATCH (n:Actor)\n" + + "RETURN n.name AS name\n" + + "UNION DISTINCT\n" + + "MATCH (n:Movie)\n" + + "RETURN n.title AS name" ); + } + + @Test + public void distinctUnionTest() + { + execute( "MATCH (n:Actor)\n" + + "RETURN n.name AS name\n" + + "UNION DISTINCT\n" + + "MATCH (n:Movie)\n" + + "RETURN n.title AS name" ); + } + +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java index 69e506c653..28a691215b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java @@ -272,24 +272,8 @@ public void existsWithTest() } - @Test - public void limitWithTest() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - - GraphResult res = execute( "MATCH (n) WITH n LIMIT 2 RETURN n.name, n.age;" ); - } - @Test - public void SkipWithTest() - { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (n) WITH n SKIP 2 RETURN n.name, n.age;" ); - } @Test public void conditionalLogicWithTest() From 8da8e4a04cdca7d1d569b57bf57083d44adf5e89 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sat, 15 Jun 2024 06:03:19 +0300 Subject: [PATCH 05/55] update test cases --- .../db/cypher/CypherTestTemplate.java | 7 +- .../polypheny/db/cypher/DmlInsertTest.java | 15 + .../org/polypheny/db/cypher/MergeTest.java | 371 +++++++++++++++--- .../org/polypheny/db/cypher/RemoveTest.java | 119 ++++-- 4 files changed, 418 insertions(+), 94 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java index 6ad8e70d44..876cb2d629 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java @@ -54,18 +54,15 @@ public class CypherTestTemplate { private static final String GRAPH_NAME = "test"; protected static final String SINGLE_NODE_PERSON_1 = "CREATE (p:Person {name: 'Max'})"; protected static final String SINGLE_NODE_PERSON_2 = "CREATE (p:Person {name: 'Hans'})"; - protected static final String SINGLE_NODE_PERSON_EMPLOYEE = "CREATE (p:Person:Employee {name: 'Max'})"; + protected static final String SINGLE_NODE_PERSON_COMPLEX_1 = "CREATE (p:Person {name: 'Ann', age: 45, depno: 13})"; protected static final String SINGLE_NODE_PERSON_COMPLEX_2 = "CREATE (p:Person {name: 'Bob', age: 31, depno: 13})"; protected static final String SINGLE_NODE_PERSON_COMPLEX_3 = "CREATE (p:Person {name: 'Alex', age: 32, depno: 14})"; - protected static final String SINGLE_NODE_PERSON_COMPLEX_4 = "CREATE (charlie:Person {name: 'Charlie Sheen', bornIn: 'New York', chauffeurName: 'John Brown'})"; - protected static final String SINGLE_NODE_PERSON_COMPLEX_5 = "CREATE (martin:Person {name: 'Martin Sheen', bornIn: 'Ohio', chauffeurName: 'Bob Brown'})"; - protected static final String SINGLE_NODE_PERSON_COMPLEX_6 = "CREATE (michael:Person {name: 'Michael Douglas', bornIn: 'New Jersey', chauffeurName: 'John Brown'})"; - protected static final String SINGLE_NODE_MOVIE = "CREATE (wallStreet:Movie {title: 'Wall Street'})"; + protected static final String SINGLE_NODE_ANIMAL = "CREATE (a:Animal {name:'Kira', age:3, type:'dog'})"; protected static final String SINGLE_EDGE_1 = "CREATE (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'})"; protected static final String SINGLE_EDGE_2 = "CREATE (p:Person {name: 'Max'})-[rel:KNOWS {since: 1994}]->(a:Person {name:'Hans', age:31})"; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java index 87b7ead1cf..b855d93d5f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java @@ -66,6 +66,21 @@ public void insertNodeTest() { assert containsNodes( res, true, TestNode.from( Pair.of( "name", "Max Muster" ) ) ); } + @Test + public void insertNodeWithManyLabelsTest() { + execute( "CREATE (p:Person :Employee )" ); + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, TestNode.from(List.of("Person" , "Employee") )); + } + @Test + public void insertNodeWithManyLabelsAndPropertyTest () + { + execute( "CREATE (n:Person:Employee {name :'MAX'})" ); + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, TestNode.from(List.of("Person" , "Employee") ,Pair.of( "name" , "Max" ))); + + } + @Test public void insertTwoNodeTest() { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java index 1abf01a4b9..aec158eb6d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java @@ -19,124 +19,383 @@ import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.helper.TestEdge; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; +import java.util.List; @Slf4j -public class MergeTest extends CypherTestTemplate{ +public class MergeTest extends CypherTestTemplate { + + + protected static final String SINGLE_NODE_PERSON_COMPLEX_4 = "CREATE (charlie:Person {name: 'Charlie Sheen', bornIn: 'New York', chauffeurName: 'John Brown'})"; + protected static final String SINGLE_NODE_PERSON_COMPLEX_5 = "CREATE (martin:Person {name: 'Martin Sheen', bornIn: 'Ohio', chauffeurName: 'Bob Brown'})"; + protected static final String SINGLE_NODE_PERSON_COMPLEX_6 = "CREATE (michael:Person {name: 'Michael Douglas', bornIn: 'New Jersey', chauffeurName: 'John Brown'})"; + + protected static final String SINGLE_NODE_MOVIE = "CREATE (wallStreet:Movie {title: 'Wall Street'})"; + + @BeforeEach public void reset() { tearDown(); createGraph(); } - @Test - public void singleNodeWithLabelMergeTest () - { - // new node - GraphResult res = execute( "MERGE (n:SomeOne ) RETURN n " ); - // Exist node - res = execute( "MERGE (n:Person) RETURN n" ); - } @Test - public void singleNodeWithMultipleLabelsMergeTest() - { - GraphResult res = execute( "MERGE (robert:Critic:Viewer) RETURN labels(robert)" ); + public void singleNodeMergeTest() { + execute( "MERGE (P)" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of() ) ); } + @Test + public void returnSingleNodeMergeTest() { + GraphResult res = execute( "MERGE (P) Return P " ); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of() ) ); + + + } + @Test - public void singleNodeWithPropertiesMergeTest() - { + public void singleNodeWithLabelMergeTest() { + // new node + execute( "MERGE (p:Person)" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); + // System.out.print( res.getData().length ); return zero + + // exist node + execute( "MERGE (n:Person)" ); + res = matchAndReturnAllNodes(); - GraphResult res = execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})RETURN charlie" ); + // num of nodes should be one + assert res.getData().length == 1; } + + @Test - public void singleNodeWithPropertiesAndLabelMergeTest() - { - GraphResult res = execute( "MERGE (michael:Person {name: 'Michael Douglas'}) RETURN michael.name, michael.bornIn" ); + public void singleNodeWithMultipleLabelsMergeTest() { + + // new node + execute( "MERGE (robert:Critic:Viewer)" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of( "Critic", "Viewer" ) ) ); + + // exist node + execute( "MERGE (robert:Critic:Viewer)" ); + GraphResult allNodes = matchAndReturnAllNodes(); + assert allNodes.getData().length == 1; + } + @Test - public void singleNodeDerivedFromExistingNodeMergeTest() - { - GraphResult res = execute( "MATCH (person:Person) MERGE (age:Age {ageNumber : person.age}) RETURN person.name, person.age, age" ); + public void singleNodeWithSinglePropertyMergeTest() { + + execute( "MERGE (charlie {name: 'Charlie Sheen'})" ); + GraphResult res = matchAndReturnAllNodes(); + System.out.print("hello: "); + // Printing the data using Arrays.deepToString + String[][] data = res.getData(); + System.out.println( Arrays.deepToString(data)); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of(), + Pair.of( "name", "Charlie Sheen" ) ) ); + + execute( "MERGE (charlie {name: 'Charlie Sheen'})" ); + res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + } + + @Test - public void createWithMergeTest() - { + public void singleNodeWithMultiplePropertiesMergeTest() { + + execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of(), + Pair.of( "name", "Charlie Sheen" ), + Pair.of( "age", 10 ) ) ); + + execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})" ); + res = matchAndReturnAllNodes(); + assert res.getData().length == 1; } + + @Test - public void matchWithMergeTest() - { + public void singleNodeWithPropertiesAndLabelMergeTest() { + + execute( "MERGE (michael:Person {name: 'Michael Douglas' , age : 10})" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of( "Person" ), + Pair.of( "name", "Michael Douglas" ), + Pair.of( "age", 10 ) ) ); + execute( "MERGE (michael:Person {name: 'Michael Douglas' , age : 10})" ); + res = matchAndReturnAllNodes(); + + assert res.getData().length == 1; } + @Test - public void createOrMatchNodeWithMergeTest () - { - // Create new node - GraphResult res = execute( "MERGE (n:Person {name: 'Alice'}) ON CREATE SET n.age = 30 ON MATCH SET n.age = 35 RETURN n" ); + public void singleNodeDerivedFromExistingNodeMergeTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_4 ); + execute( SINGLE_NODE_PERSON_COMPLEX_5 ); + execute( SINGLE_NODE_PERSON_COMPLEX_6 ); - // Updated the Matched node - res = execute( "MERGE (n:Person {name: 'MAX'}) ON CREATE SET n.age = 30 ON MATCH SET n.age = 35 RETURN n" ); + execute( "MATCH (person:Person)\n" + + "MERGE (location:Location {name: person.bornIn})\n" ); + + GraphResult res = execute( "MATCH (location:Location) RETURN location.name" ); + containsRows( res, true, true, + Row.of( TestLiteral.from( "New York" ) ), + Row.of( TestLiteral.from( "Ohio" ) ), + Row.of( TestLiteral.from( "New Jersey" ) ) ); + + execute( "MATCH (person:Person)\n" + + "MERGE (location:Location {name: person.bornIn})\n" ); + + res = execute( "MATCH (location:Location) RETURN location" ); + + assert res.getData().length == 1; } + + @Test - public void matchMultiplePropertiesMergeTest() - { + public void createWithMergeTest() { + + execute( "MERGE (keanu:Person {name: 'Keanu Reeves', bornIn: 'Beirut', chauffeurName: 'Eric Brown'})\n" + + "ON CREATE SET keanu.age = 20" + ); + + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + containsNodes( res, true, + (TestNode.from( List.of( "Person" ), Pair.of( "name", "Keanu Reeves" ), Pair.of( "age", 20 ) )) ); + execute( "MERGE (keanu:Person {name: 'Keanu Reeves', bornIn: 'Beirut', chauffeurName: 'Eric Brown'})\n" + + "ON CREATE SET keanu.age = 20" + ); + res = matchAndReturnAllNodes(); + assert res.getData().length == 1; } + @Test - public void singleRelationshipMergeTest() - { - GraphResult res = execute( "MATCH (n1:Person {name: 'Alice'}) , (n2:Person {name: 'Bob'}) MERGE (n1)-[r:KNOWS]->(n2) RETURN n1, n2, r" ); + public void matchWithMergeTest() { + execute( "MERGE (person:Person{ found : false})\n" + + "ON MATCH SET person.found = true\n" ); + + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + containsNodes( res, true, TestNode.from( + List.of( "Person" ), + Pair.of( "found", false ) ) ); + + execute( "MERGE (person:Person{ found : false})\n" + + "ON MATCH SET person.found = true\n" ); + + res = matchAndReturnAllNodes(); + containsNodes( res, true, TestNode.from( + List.of( "Person" ), + Pair.of( "found", true ) ) ); + + assert res.getData().length == 1; + - res = execute("MATCH (n1:Person {name: 'Hans'}) , (n2:Person {name: 'Max'}) MERGE (n1)-[r:KNOWS ]->(n2) RETURN n1, n2, r"); } + @Test - public void multipleRelationshipsMergeTest() - { - GraphResult res = execute( "MATCH (p:Person {name: 'Max'}),(a:Animal {name:'Kira') MERGE (person)-[:Owner]->(movie:Movie)<-[:belong]-(Animal) RETURN movie" ); + public void createOrMatchNodeWithMergeTest() { + // Create new node + execute( "MERGE (n:Person {name: 'Alice'}) ON CREATE SET n.age = 30 ON MATCH SET n.age = 35" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + containsNodes( res, true, TestNode.from( + List.of( "Person" ), + Pair.of( "age", 30 ), + Pair.of( "name", "Alice" ) ) ); + // Updated the Matched node + execute( "MERGE (n:Person {name: 'Alice'}) ON CREATE SET n.age = 30 ON MATCH SET n.age = 35 " ); + res = matchAndReturnAllNodes(); + containsNodes( res, true, TestNode.from( + List.of( "Person" ), + Pair.of( "age", 35 ), + Pair.of( "name", "Alice" ) ) ); + assert res.getData().length == 1; } + + @Test - public void undirectedRelationshipMergeTest() - { + public void singleRelationshipMergeTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_4 ); + execute( SINGLE_NODE_MOVIE ); + + execute( "MATCH\n" + + " (charlie:Person {name: 'Charlie Sheen'}),\n" + + " (wallStreet:Movie {title: 'Wall Street'})\n" + + "MERGE (charlie)-[r:ACTED_IN]->(wallStreet)\n" ); + + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, + TestNode.from( List.of( "Person" ), Pair.of( "name", "Charlie Sheen" ) ), + TestNode.from( List.of( "Person" ), Pair.of( "name", "Wall Street" ) ) ); + + res = execute( "MATCH ()-[r]->() RETURN r" ); + assert containsEdges( res, true, TestEdge.from( List.of( "ACTED_IN" ) ) ); + execute( "MATCH\n" + + " (charlie:Person {name: 'Charlie Sheen'}),\n" + + " (wallStreet:Movie {title: 'Wall Street'})\n" + + "MERGE (charlie)-[r:ACTED_IN]->(wallStreet)\n" ); + + res = execute( "MATCH ()-[r]->() RETURN r" ); + assert res.getData().length == 1; + - GraphResult res = execute( "MATCH (n1:Person {name: 'Hans'}) , (n2:Person {name: 'Max'}) MERGE (n1)-[r:KNOWS ]-(n2) RETURN n1, n2, r" ); } + @Test - public void relationshipOnTwoExistingNodeMergeTest() - { - GraphResult res = execute( "MATCH (n1:Person {name: 'Hans'}) MERGE (n2:Person {name: 'Bob'}) MERGE (n1)-[r:Knows]->(n2) RETURN person.name, person.age" ); + public void multipleRelationshipsMergeTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_4 ); + execute( SINGLE_NODE_PERSON_COMPLEX_5 ); + + execute( "MATCH\n" + + " (charlie:Person {name: 'Charlie Sheen'}),\n" + + " (martin:Person {name: 'Martin Sheen'})\n" + + "MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(reiner)\n" ); + + GraphResult res = execute( "MATCH (p1:Person)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(p2:Person)\n" + + "RETURN p1, p2, movie\n" ); + + assert containsNodes( res, true, + TestNode.from( Pair.of( "name", "Charlie Sheen" ) ), + TestNode.from( Pair.of( "name", "Martin Sheen" ) ), + TestNode.from( List.of( "Movie" ) ) ); + + execute( "MATCH\n" + + " (charlie:Person {name: 'Charlie Sheen'}),\n" + + " (martin:Person {name: 'Martin Sheen'})\n" + + "MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(reiner)\n" ); + + res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + } + + @Test - public void relationshipOnExistingNodeAndMergeNodeDerivedFromAnodeProperty () - { - GraphResult res = execute( "MATCH (person:Person) MERGE (person)-[r:Has_Age]->(age:Age {ageNumber: person.age}) RETURN person.name, person.age, age" ); + public void undirectedRelationshipMergeTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_4 ); + execute( SINGLE_NODE_PERSON_COMPLEX_5 ); + + execute( "MATCH\n" + + " (charlie:Person {name: 'Charlie Sheen'}),\n" + + " (martin:Person {name: 'Martin Sheen'})\n" + + "MERGE (charlie)-[r:KNOWS]-(oliver)\n" ); + + GraphResult res = execute( "MATCH (p1:Person)-[r:KNOWS]-(p2:Person)\n" + + "RETURN KNOWS" ); + + assert containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ) ) ); + + execute( "MATCH\n" + + " (charlie:Person {name: 'Charlie Sheen'}),\n" + + " (martin:Person {name: 'Martin Sheen'})\n" + + "MERGE (charlie)-[r:KNOWS]-(oliver)\n" ); + + res = execute( "MATCH (p1:Person)-[r:KNOWS]-(p2:Person)\n" + + "RETURN KNOWS" ); + + assert res.getData().length == 1; } + + @Test - public void createAndRelationshipMergeTest() - { - GraphResult res = execute( "MERGE (n:Person {name: 'MAX'}) ON CREATE SET n.created = timestamp() MERGE (m:Person {name: 'Bob'})ON CREATE SET m.created = timestamp()" ); + public void relationshipOnTwoExistingNodeMergeTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_4 ); + execute( SINGLE_NODE_PERSON_COMPLEX_5 ); + execute( SINGLE_NODE_PERSON_COMPLEX_6 ); + + execute( "MATCH (person:Person)\n" + + "MERGE (location:Location {name: person.bornIn})\n" + + "MERGE (person)-[r:BORN_IN]->(location)\n" ); + + GraphResult res = execute( "MATCH (location:Location) RETURN location.name" ); + containsRows( res, true, true, + Row.of( TestLiteral.from( "New York" ) ), + Row.of( TestLiteral.from( "Ohio" ) ), + Row.of( TestLiteral.from( "New Jersey" ) ) ); + + res = execute( "MATCH ()-[BORN_IN]->() RETURN BORN_IN" ); + assert res.getData().length == 3; + assert containsEdges( res, true, TestEdge.from( List.of( "BORN_IN" ) ) ); + + execute( "MATCH (person:Person)\n" + + "MERGE (location:Location {name: person.bornIn})\n" + + "MERGE (person)-[r:BORN_IN]->(location)\n" ); + + GraphResult edges = execute( "MATCH ()-[BORN_IN]->() RETURN BORN_IN" ); + GraphResult nodes = execute( "MATCH (location:Location) RETURN Location " ); + + assert edges.getData().length == 3 && nodes.getData().length == 3; - res = execute("MERGE (n:Person {name: 'Bob'}) ON CREATE SET n.age = 30 MERGE (m:Person {name: 'Ann'})ON CREATE SET m.age = 50"); } - // do you want me to test this ?? + @Test - public void UniqueConstrainsMergeTest() - { + public void relationshipOnExistingNodeAndMergeNodeDerivedFromAnodeProperty() { + execute( SINGLE_NODE_PERSON_COMPLEX_4 ); + execute( SINGLE_NODE_PERSON_COMPLEX_5 ); + execute( SINGLE_NODE_PERSON_COMPLEX_6 ); + + execute( "MATCH (person:Person)\n" + + "MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName})\n" ); + + GraphResult res = execute( "MATCH ( chauffeur :Chauffeur) Return Chauffeur.name" ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( "John Brown" ) ), + Row.of( TestLiteral.from( "Bob Brown" ) ), + Row.of( TestLiteral.from( "John Brown" ) ) ); + + res = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); + assert res.getData().length == 3; + assert containsEdges( res, true, TestEdge.from( List.of( "HAS_CHAUFFEUR" ) ) ); + execute( "MATCH (person:Person)\n" + + "MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName})\n" ); + GraphResult edges = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); + GraphResult nodes = execute( "MATCH (n:Chauffeur) RETURN Chauffeur" ); + assert edges.getData().length == 3 && nodes.getData().length == 3 ; } + // do you want me to test this ?? + @Test + public void UniqueConstrainsMergeTest() { + + } + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java b/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java index fb93c7252f..5df4bfc1ef 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java @@ -16,14 +16,24 @@ package org.polypheny.db.cypher; +import io.activej.codegen.expression.impl.Null; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.helper.TestEdge; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; +import java.util.List; @Slf4j public class RemoveTest extends CypherTestTemplate { + protected static final String SINGLE_NODE_PERSON_EMPLOYEE = "CREATE (n:Person:Employee) "; + + @BeforeEach public void reset() { tearDown(); @@ -32,65 +42,108 @@ public void reset() { @Test - public void labelRemoveTest() - { - GraphResult res = execute( "MATCH (n : Person {name: 'Max'}) REMOVE n:person RETURN n.name" ); - } + public void labelRemoveTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( "MATCH (n:Person {name: 'Max'})\n" + + "REMOVE n:Person " ); + GraphResult res = execute( "MATCH (n :Person) RETURN n" ); + assert res.getData().length == 0; - @Test - public void multipleLabelsRemoveTest() - { - GraphResult res = execute( "MATCH (n {name: 'Max'}) REMOVE n:Person:Employee RETURN n.name" ); } + + @Test - public void allLabelsRemoveTest(){ + public void returnWithRemoveTest() { + execute( SINGLE_NODE_PERSON_1 ); + GraphResult res = execute( "MATCH (n:Person {name: 'Max'})\n" + + "REMOVE n:Person RETURN n " ); + + assert res.getData().length == 1; + - GraphResult res = execute( "MATCH (n:Person) SET n = {}" ); } + @Test - public void singlePropertyNodeRemoveTest() - { - GraphResult res = execute( "MATCH (n : Person {name: 'Bob'}) REMOVE a.age RETURN a.name, a.age" ); + public void multipleLabelsRemoveTest() { + execute( SINGLE_NODE_PERSON_EMPLOYEE ); + + GraphResult res = matchAndReturnAllNodes() ; + assert containsNodes( res, true, TestNode.from(List.of("Person" , "Employee") )); + + execute( "MATCH (n) REMOVE n:Person:Employee " ); + res = execute( "MATCH (n :Person:Employee) RETURN n" ); + assert res.getData().length == 0 ; + } + @Test - public void multiplePropertiesRemoveTest() - { - GraphResult res = execute( "MATCH (n:Person {name: 'John'})\n" - + "REMOVE n.age, n.email, n.phone\n" - + "RETURN n\n" ) ; + public void singlePropertyNodeRemoveTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( "MATCH (n : Person {name: 'Ann'}) REMOVE a.age " ); + GraphResult res = execute( "MATCH (n : Person) RETURN n.age , n.name" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); + + } - @Test - public void allPropertiesNodeRemoveTest(){ - execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (n:Person) SET n = {}" ); - } + @Test - public void singlePropertyRelationshipRemoveTest() - { + public void multiplePropertiesRemoveTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( "MATCH (n:Person {name: 'Ann'})\n" + + "REMOVE n.age, n.depno\n" ); + + GraphResult res = execute( "MATCH (n : Person) RETURN n.age , n.depno , n.name " ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); } + @Test - public void multiplePropertiesRelationshipRemoveTest() - { - GraphResult res = execute( "MATCH (p:Person)-[r:WORKS_AT]->(c:Company)\n" - + "WHERE p.name = 'John' AND c.name = 'TechCorp'\n" - + "REMOVE r.startDate, r.endDate, r.position\n" - + "RETURN r\n" ) ; + public void allPropertiesNodeRemoveTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( "MATCH (n:Person) SET n = {}" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 0; + } + + @Test - public void allPropertiesRelationshipRemoveTest(){ + public void singlePropertyRelationshipRemoveTest() { + execute( SINGLE_EDGE_2 ); + execute( "MATCH(p1:Person)-[rel:KNOWS]->(p2:Person)\n" + + "REMOVE rel.since" ); + GraphResult res = execute( "MATCH ()-[r:KNOWS]->() RETURN r.since" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); + - GraphResult res = execute( "MATCH (n:Person) SET n = {}" ); } + @Test + public void multiplePropertiesRelationshipRemoveTest() { + execute( "Create (p:Person {name: 'Max'})-[rel:KNOWS {since: 1994 , relation : 'friend'}]->(a:Person {name:'Hans', age:31})" ); + execute( "MATCH(p1:Person)-[rel:KNOWS]->(p2:Person)\n" + + "REMOVE rel.since , rel.relation" ); + GraphResult res = execute( "MATCH ()-[r:KNOWS]->() RETURN r.since , r.relation" ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( null ) ), + Row.of( TestLiteral.from( null ) ) ); + } + + @Test + public void allPropertiesRelationshipRemoveTest() { + execute( SINGLE_EDGE_2 ); + execute( "MATCH ()-[r:KNOWS]->() RETURN SET r = {}" ); + GraphResult res = execute( "MATCH ()-[r:KNOWS]->() RETURN r.since" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); + } } From b819164300dd484f6c40733ec9e985b4b2a94f42 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 16 Jun 2024 01:31:38 +0300 Subject: [PATCH 06/55] update test cases --- .../polypheny/db/cypher/AggregateTest.java | 16 +------- .../polypheny/db/cypher/DmlDeleteTest.java | 40 +++++++++++++++++-- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java index 74e9cb8b2e..ae9ab2c92d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java @@ -107,20 +107,6 @@ assert containsRows( res, true, false, } - @Test - public void countFieldRenameFieldAggregateTest() { - execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2); - - GraphResult res = execute( "MATCH (n) RETURN n.name, count(n.age) AS c" ); - - - assert containsRows(res, true, false, - Row.of(TestLiteral.from("Hans") , TestLiteral.from( 0 )), - Row.of( TestLiteral.from( "Max"), TestLiteral.from( 1 ) )); - - } - @Test public void doubleCountRenameAggregateTest() { @@ -178,7 +164,7 @@ public void singleAvgAggregateTest() { String[][] data = res.getData(); System.out.println( Arrays.deepToString(data)); assert containsRows( res, true, false, - Row.of( TestLiteral.from( 26.333333333333333333333333333333 ) ) ); + Row.of( TestLiteral.from( 26.33333333333333 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java index d62843e292..df770ff985 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java @@ -94,29 +94,61 @@ assert containsRows( res, true, false, @Test public void relationshipWithPropertiesDeleteTest() { + execute( SINGLE_EDGE_2 ); + execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) \n" + + "DELETE rel" ); + + GraphResult res = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal)"); + assertEmpty( res ); } + @Test public void pathDeleteTest() { - execute( "MATCH (p:Person {name: 'Alice'})-[r:WORKS_AT]->(c:Company {name: 'TechCorp'})\n" - + "DELETE r, p\n" ); + + execute( SINGLE_EDGE_1 ); + + execute( "MATCH p = (person:Person {name: 'Max'})-[rel:OWNER_OF]->( animal :Animal {name: 'Kira'})\n" + + "DELETE p\n" ); + + GraphResult res = matchAndReturnAllNodes() ; + GraphResult edges = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal)"); + assert res.getData().length == 0 && edges.getData().length == 0 ; + + } @Test - public void NodeWithRelationshipsDeleteTest() + public void NodeWithAllRelationshipsDeleteTest() { - execute( "MATCH (n:Person {name: 'Carrie-Anne Moss'})\n" + execute( SINGLE_EDGE_2 ); + execute( "MATCH (n:Person {name: 'MAX'})\n" + "DETACH DELETE n" ); + + + GraphResult res = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal)"); + assert res.getData().length == 0 ; + } @Test public void allNodesAndRelationshipsDeleteTest () { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_EDGE_1 ); execute( "MATCH (n)\n" + "DETACH DELETE n" ) ; + + + GraphResult res = matchAndReturnAllNodes() ; + GraphResult edges = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal)"); + assert res.getData().length == 0 && edges.getData().length == 0 ; + } + } From 14f1b9a88d302eb3aff1798d5c32fd0a2f0a4305 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 16 Jun 2024 03:54:34 +0300 Subject: [PATCH 07/55] update test cases --- .../org/polypheny/db/cypher/CaseTest.java | 129 ++++++++++++------ .../org/polypheny/db/cypher/SkipTest.java | 33 ++++- .../org/polypheny/db/cypher/UnionTest.java | 76 +++++++++-- 3 files changed, 177 insertions(+), 61 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java index fe8d48b9c4..b7b3c914e5 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java @@ -19,9 +19,11 @@ import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; -public class CaseTest extends CypherTestTemplate{ +public class CaseTest extends CypherTestTemplate { @BeforeEach public void reset() { @@ -29,55 +31,102 @@ public void reset() { createGraph(); } + + protected static final String PERSON_NODE_ALICE = "CREATE (:Person {name:'Alice', age: 38, eyes: 'brown'})"; + protected static final String PERSON_NODE_BOB = "CREATE (:Person {name: 'Bob', age: 25, eyes: 'blue'})"; + protected static final String PERSON_NODE_CHARLIE = "CREATE (:Person {name: 'Charlie', age: 53, eyes: 'green'})"; + + @Test - public void simpleCaseTest() - { - execute( "MATCH (n:Person)\n" - + "RETURN\n" - + "CASE n.eyes\n" - + " WHEN 'blue' THEN 1\n" - + " WHEN 'brown', 'hazel' THEN 2\n" - + " ELSE 3\n" - + "END AS result, n.eyes" ); + public void simpleCaseTest() { + execute( PERSON_NODE_ALICE ); + execute( PERSON_NODE_BOB ); + execute( PERSON_NODE_CHARLIE ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN\n" + + "CASE n.eyes\n" + + " WHEN 'blue' THEN 1\n" + + " WHEN 'brown' THEN 2\n" + + " ELSE 3\n" + + "END AS result, n.eyes" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); + + } @Test - public void GenericCaseTest() - { - execute( "MATCH (n:Person)\n" - + "RETURN\n" - + "CASE\n" - + " WHEN n.eyes = 'blue' THEN 1\n" - + " WHEN n.age < 40 THEN 2\n" - + " ELSE 3\n" - + "END AS result, n.eyes, n.age" ) ; + public void GenericCaseTest() { + execute( PERSON_NODE_ALICE ); + execute( PERSON_NODE_BOB ); + execute( PERSON_NODE_CHARLIE ); + + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN\n" + + "CASE\n" + + " WHEN n.eyes = 'blue' THEN 1\n" + + " WHEN n.age < 40 THEN 2\n" + + " ELSE 3\n" + + "END AS result, n.eyes, n.age" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); + } + @Test - public void nullWithCaseTest() - { - execute( "MATCH (n:Person)\n" - + "RETURN n.name,\n" - + "CASE n.age\n" - + " WHEN null THEN -1\n" - + " ELSE n.age - 10\n" - + "END AS age_10_years_ago" ); + public void nullWithCaseTest() { + execute( PERSON_NODE_ALICE ); + execute( PERSON_NODE_BOB ); + execute( PERSON_NODE_CHARLIE ); + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN n.name,\n" + + "CASE n.age\n" + + " WHEN null THEN -1\n" + + " ELSE n.age - 10\n" + + "END AS age_10_years_ago" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 28 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 15 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 43 ) ), + Row.of( TestLiteral.from( "MAX" ), TestLiteral.from( null ) ) ); + + } - @Test - public void expressionsAndSucceedingClauses() - { - execute( "MATCH (n:Person)\n" - + "WITH n,\n" - + "CASE n.eyes\n" - + " WHEN 'blue' THEN 1\n" - + " WHEN 'brown' THEN 2\n" - + " ELSE 3\n" - + "END AS colorCode\n" - + "SET n.colorCode = colorCode\n" - + "RETURN n.name, n.colorCode" ); - } + @Test + public void expressionsAndSucceedingClauses() { + execute( PERSON_NODE_ALICE ); + execute( PERSON_NODE_BOB ); + execute( PERSON_NODE_CHARLIE ); + + GraphResult res = execute( "MATCH (n:Person)\n" + + "WITH n,\n" + + "CASE n.eyes\n" + + " WHEN 'blue' THEN 1\n" + + " WHEN 'brown' THEN 2\n" + + " ELSE 3\n" + + "END AS colorCode\n" + + "SET n.colorCode = colorCode\n" + + "RETURN n.name, n.colorCode" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) )); + + } + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java b/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java index 7556750287..166314420e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java @@ -19,7 +19,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; public class SkipTest extends CypherTestTemplate{ @@ -64,7 +67,10 @@ public void withAndSkipTest() execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (n) WITH n SKIP 2 RETURN n.name, n.age;" ); + GraphResult res = execute( "MATCH (n) WITH n SKIP 2 RETURN n.name, n.age" ); + + assert res.getData().length == 1; + } @Test @@ -79,15 +85,28 @@ public void returnSubsetSkipTest() GraphResult res = execute( "MATCH (n) RETURN n.name SKIP 3 LIMIT 1" ); assert res.getData().length == 1; + + + } @Test - public void expressionAndSkipTest() - { - execute( "MATCH (n)\n" - + "RETURN n.name\n" - + "ORDER BY n.name\n" - + "SKIP 1 + toInteger(3*rand())" ); + public void withAndOrderBySkipTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n)\n" + + "WITH n ORDER BY n.name SKIP 1\n" + + "RETURN n" ); + + assert res.getData().length == 1; + + assert containsNodes( res, true, + TestNode.from( Pair.of( "name" , "Bob" ) , + Pair.of( "age" , 31 ) , + Pair.of( "depno" , 13 )) ); + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java index 35f5cc8dbf..9233088bed 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java @@ -18,43 +18,91 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; + +public class UnionTest extends CypherTestTemplate { + -public class UnionTest extends CypherTestTemplate{ @BeforeEach public void reset() { tearDown(); createGraph(); } -@Test - public void retainDuplicatesUnionTest() - { - execute( "MATCH (n:Actor)\n" + + @Test + public void simpleUnionTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_ANIMAL); + execute( SINGLE_NODE_ANIMAL); + + + GraphResult res = execute( "MATCH (n:Actor)\n" + "RETURN n.name AS name\n" - + "UNION ALL\n" + + "UNION \n" + "MATCH (n:Movie)\n" + "RETURN n.title AS name" ); - } + + containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Hans" ) ), + Row.of( TestLiteral.from( "Kira" ) )); + } @Test - public void removeDuplicatesUnionTest() - { - execute( "MATCH (n:Actor)\n" + public void allUnionTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_ANIMAL); + execute( SINGLE_NODE_ANIMAL); + + GraphResult res = execute( "MATCH (n:Actor)\n" + "RETURN n.name AS name\n" - + "UNION DISTINCT\n" + + "UNION ALL\n" + "MATCH (n:Movie)\n" + "RETURN n.title AS name" ); + + + containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Hans" ) ), + Row.of( TestLiteral.from( "Kira" ) ), + Row.of( TestLiteral.from( "Kira" ) ) ); + + } + + + + @Test - public void distinctUnionTest() - { - execute( "MATCH (n:Actor)\n" + public void distinctUnionTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_ANIMAL); + execute( SINGLE_NODE_ANIMAL); + + GraphResult res = execute( "MATCH (n:Actor)\n" + "RETURN n.name AS name\n" + "UNION DISTINCT\n" + "MATCH (n:Movie)\n" + "RETURN n.title AS name" ); + + + containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Hans" ) ), + Row.of( TestLiteral.from( "Kira" ) )); + } } From 976462fec2b4f09479987bc9d7d3b06a4aa6dedc Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 16 Jun 2024 05:27:33 +0300 Subject: [PATCH 08/55] update test cases --- .../polypheny/db/cypher/DmlInsertTest.java | 8 +++++ .../org/polypheny/db/cypher/OrderByTest.java | 31 ++++++----------- .../org/polypheny/db/cypher/UnwindTest.java | 8 +++-- .../org/polypheny/db/cypher/WithTest.java | 33 +++++++++++++++---- 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java index b855d93d5f..a204f2e046 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java @@ -80,6 +80,14 @@ public void insertNodeWithManyLabelsAndPropertyTest () assert containsNodes( res, true, TestNode.from(List.of("Person" , "Employee") ,Pair.of( "name" , "Max" ))); } + @Test + public void insertNodeWithPropertyContainsListTest() + { + execute( "CREATE ({l: [1 ,2,3]})" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1 ; + + } @Test diff --git a/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java b/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java index 8e3a8b8aac..6b5f76548c 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java @@ -156,14 +156,16 @@ assert containsRows( res , true ,true , } + + @Test - public void renameWithClauseDoubleOrderByWithLimitTest() + public void renameWithClauseDoubleOrderByTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute(SINGLE_NODE_PERSON_COMPLEX_2); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC LIMIT 3 RETURN department , name " ); + GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC RETURN department , name" ); assert containsRows( res, true, true, @@ -175,15 +177,14 @@ assert containsRows( res, true, true, } - @Test - public void renameWithClauseDoubleOrderByTest() + public void renameWithClauseDoubleOrderByWithLimitTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute(SINGLE_NODE_PERSON_COMPLEX_2); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC RETURN department , name" ); + GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC LIMIT 3 RETURN department , name " ); assert containsRows( res, true, true, @@ -196,7 +197,7 @@ assert containsRows( res, true, true, } @Test - public void renameUnwindSortTest() { + public void UnwindSortTest() { GraphResult res = execute( "UNWIND [1, true,3.14] AS i RETURN i ORDER BY i" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( true ) ), @@ -206,7 +207,7 @@ assert containsRows( res, true, true, } @Test - public void renameWithClauseWithRenameUnwindSortTest () + public void renameWithClauseWithUnwindSortTest () { GraphResult res = execute( "WITH [1 ,2 ,3] AS number UNWIND number AS n RETURN n ORDER BY n" ); @@ -218,7 +219,7 @@ assert containsRows( res , true , true , } @Test - public void renameWithMixedTypesWithRenameUnwindSortTest () + public void renameWithMixedTypesWithUnwindSortTest () { @@ -231,7 +232,7 @@ assert containsRows( res , true , true , } @Test - public void renameAvgAggregateFieldSortTest() + public void AvgAggregateFieldSortTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); @@ -243,19 +244,7 @@ assert containsRows( res , true , true , } - @Test - public void renameWithClauseOrderByWithSkipTest() - { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC SKIP 1 Limit 1 RETURN age" ); - - assert containsRows( res , true ,true , - Row.of( TestLiteral.from( 32 ) ), - Row.of(TestLiteral.from( 31)) ); - } @Test public void renameWithClauseOrderByWithSkipLimitTest() diff --git a/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java index f2ee7ac441..bee6a69376 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java @@ -118,7 +118,7 @@ public void maxMinAggregateNodePropertyUnWind() { GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); - res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); + res = execute( "MATCH (n) UNWIND n.age AS age RETURN min(age)" ); assert containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); @@ -187,7 +187,11 @@ assert containsRows( res , true , false , @Test public void ConditionalLogicUnWind() { - GraphResult res = execute( "UNWIND [1, 2, 3, 4, 5] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); + GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); + assert containsRows( res , true , true , + Row.of( TestLiteral.from( 1 ) ,TestLiteral.from("odd" ) ), + Row.of( TestLiteral.from( 2 ) ,TestLiteral.from( "even" )), + Row.of( TestLiteral.from( 3 ) ,TestLiteral.from( "odd"))); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java index 28a691215b..b3d8cfff05 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java @@ -19,7 +19,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.AbstractSequentialList; +import java.util.Arrays; public class WithTest extends CypherTestTemplate { @@ -248,7 +252,9 @@ public void unWindAndWhereInListWithTest() @Test public void createNodeWithTest() { - GraphResult res = execute( "WITH [1, 1.0] AS list CREATE ({l: list})" ); + execute( "WITH [1, 1.0] AS list CREATE ({l: list})" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1 ; } @@ -260,15 +266,19 @@ public void distinctWithTest() execute( SINGLE_NODE_PERSON_1); GraphResult res = execute( "MATCH (p:Person) WITH Distinct(p) Return p " ); + assert res.getData().length == 2 ; + } @Test public void existsWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age;" ); + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age;" ); + assert containsRows( res , true , true , Row.of( TestLiteral.from( "Ann" ),TestLiteral.from( 45 ) )); + } @@ -281,14 +291,25 @@ public void conditionalLogicWithTest() execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p, CASE WHEN p.age < 30 THEN 'Young' HEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' ELSE 'Elderly END AS ageGroup RETURN p.name, p.age, ageGroup;" ) ; + GraphResult res = execute( "MATCH (p:Person) WITH p, CASE WHEN p.age < 30 THEN 'Young' THEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' ELSE 'Elderly END AS ageGroup RETURN p.name, ageGroup;" ) ; + assert containsRows( res , true , true , + Row.of( TestLiteral.from( "Ana" ) , TestLiteral.from( "Middle-aged" ) ) , + Row.of( TestLiteral.from( "Bob" ) , TestLiteral.from( "Middle-aged" ) ), + Row.of( TestLiteral.from( "Alex" ) , TestLiteral.from( "Middle-aged" ) )); } @Test public void orderByWithTest() { - GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p" ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p.name" ); + + assert containsRows( res , true ,true , + Row.of( TestLiteral.from( "Hans" )) , + Row.of( TestLiteral.from( "Max" )) ); + } } From b0916f5cd378c714bd438be9fba39fbf2944f178 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Wed, 26 Jun 2024 23:06:45 +0300 Subject: [PATCH 09/55] add new tests cases for : list functions , Numeric functions , Temporal functions --- .../org/polypheny/db/cypher/ListFunTest.java | 83 ++++++++++++++++++ .../polypheny/db/cypher/NumericFunTest.java | 84 +++++++++++++++++++ .../org/polypheny/db/cypher/TemporalTest.java | 69 +++++++++++++++ 3 files changed, 236 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/ListFunTest.java create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/NumericFunTest.java create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/TemporalTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/ListFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/ListFunTest.java new file mode 100644 index 0000000000..4223aeae8c --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/ListFunTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class ListFunTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + @Test + public void simpleSizeFunTest() + { + GraphResult res = execute( "RETURN size([1, 2, 3])" ); + containsRows( res , true , true , + Row.of( TestLiteral.from( 3)) ); + } + + @Test + public void nullSizeFunTest() + { + GraphResult res = execute( "RETURN size(null)" ); + containsRows( res , true , true , + Row.of( TestLiteral.from( null ) ) ); + } + + @Test + public void patternExpressionSizeFunTest() + { + execute( SINGLE_EDGE_1); + execute( SINGLE_EDGE_1); + GraphResult res = execute( "MATCH (a)\n" + + "WHERE a.name = 'Max'\n" + + "RETURN size((a)-[]->())) AS fof" ); + + containsRows( res , true , true , + Row.of( TestLiteral.from( 2 ) ) ); + + } + + @Test + public void stringSizeFunTest() + { + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (a) RETURN size(a.name)" ); + + containsRows( res , true , true , + Row.of( TestLiteral.from( 3 ) ) ); + } + + + @Test + public void simpleRangeFunTest() + { + + GraphResult res = execute( "RETURN RANGE(1, 3)" ); + + containsRows( res , true , true , + Row.of( TestLiteral.from( 1 ) , TestLiteral.from( 2 ) , TestLiteral.from( 3 ) ) ); + } +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/NumericFunTest.java new file mode 100644 index 0000000000..a1eeab692a --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/NumericFunTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class NumericFunTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void absFunTest() { + GraphResult res = execute( "RETURN ABS(-5) " ); + + containsRows( res , true , true , Row.of( TestLiteral.from( 5 ) ) ); + + + res = execute( "RETURN ABS(5)" ); + containsRows( res , true , true , Row.of( TestLiteral.from( 5 ) ) ); + + } + + + @Test + public void roundFunTest() + { + GraphResult res = execute( "RETURN ROUND(3.4)" ); + containsRows( res , true , true , Row.of( TestLiteral.from( 3 ) ) ); + + res = execute( "RETURN ROUND(3.5)" ); + containsRows( res , true , true , Row.of( TestLiteral.from( 4 ) ) ); + + } + + @Test + public void floorFunTest(){ + GraphResult res = execute( "RETURN FLOOR(3.16)" ); + containsRows( res , true , true , Row.of( TestLiteral.from( 3 ) ) ); + + res = execute( "RETURN FLOOR(3.9)" ); + containsRows( res , true , true , Row.of( TestLiteral.from( 3 ) ) ); + + } + + @Test + public void ceilFunTest() + { + GraphResult res = execute( "RETURN CEIL(3.16)" ); + containsRows( res , true , true , Row.of( TestLiteral.from( 4 ) ) ); + + res = execute( "RETURN CEIL(3.5)" ); + containsRows( res , true , true , Row.of( TestLiteral.from( 4 ) ) ); + + } + + @Test + public void sqrtFunTest() + { + GraphResult res = execute( "RETURN SQRT(9)" ); + containsRows( res , true , true , Row.of( TestLiteral.from( 3 ) ) ); + } +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/TemporalTest.java b/dbms/src/test/java/org/polypheny/db/cypher/TemporalTest.java new file mode 100644 index 0000000000..5097a42124 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/TemporalTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class TemporalTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void dateFunTest() { + + GraphResult res = execute( "RETURN DATE('2023-05-18')\n" ); + + + } + + + @Test + public void timeFunTest() { + + GraphResult res = execute( "RETURN TIME('12:34:56')" ); + + + } + + @Test + public void dateTimeFunTest() { + + GraphResult res = execute( "RETURN DATETIME('2023-05-18T12:34:56')" ); + + + } + + @Test + public void durationBetweenFunTest() { + + GraphResult res = execute( "RETURN duration.between(DATE('2023-05-18'), DATE('2023-06-18'))" ); + + + } + + + + +} From 5acaeffe6201402e7bbd1180867e27ce40605cac Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Wed, 26 Jun 2024 23:12:09 +0300 Subject: [PATCH 10/55] add list , numeric , temporal functions to new folder "functions" --- .../cypher/{ => Functions}/ListFunTest.java | 3 +- .../{ => Functions}/NumericFunTest.java | 3 +- .../db/cypher/Functions/TemporalFunTest.java | 69 +++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) rename dbms/src/test/java/org/polypheny/db/cypher/{ => Functions}/ListFunTest.java (96%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => Functions}/NumericFunTest.java (96%) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/ListFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java similarity index 96% rename from dbms/src/test/java/org/polypheny/db/cypher/ListFunTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java index 4223aeae8c..80570f4416 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/ListFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.Functions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java similarity index 96% rename from dbms/src/test/java/org/polypheny/db/cypher/NumericFunTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java index a1eeab692a..6483c30d3e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.Functions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java new file mode 100644 index 0000000000..c3666862ac --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Functions; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.webui.models.results.GraphResult; + +public class TemporalFunTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void dateFunTest() { + + GraphResult res = execute( "RETURN DATE('2023-05-18')\n" ); + + + } + + + @Test + public void timeFunTest() { + + GraphResult res = execute( "RETURN TIME('12:34:56')" ); + + + } + + @Test + public void dateTimeFunTest() { + + GraphResult res = execute( "RETURN DATETIME('2023-05-18T12:34:56')" ); + + + } + + @Test + public void durationBetweenFunTest() { + + GraphResult res = execute( "" ); + + + } + + + + +} From 0f1a2a5e28a03c9c82523a5434734fd498b8c576 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Thu, 27 Jun 2024 00:14:26 +0300 Subject: [PATCH 11/55] add new tests cases for string functions and other functions --- .../db/cypher/Functions/OtherFunTest.java | 70 ++++++++++++++++ .../db/cypher/Functions/StringFunTest.java | 81 +++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java new file mode 100644 index 0000000000..26a7dbf3db --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Functions; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class OtherFunTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void typeFunTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (a)-[r]->(b)\n" + + "RETURN TYPE(r)\n" ); + + containsRows( res, true, true, Row.of( TestLiteral.from( "OWNER_OF" ) ) ); + + } + + @Test + public void idFunTest() + { + execute( SINGLE_NODE_PERSON_1 ); + GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" + + "RETURN ID(p)\n" ); + +// containsRows( res, true, true, Row.of( TestLiteral.from( ) ) ); + } + + @Test + public void ExistFunTest() + { + execute( SINGLE_NODE_PERSON_1 ); + GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" + + "RETURN EXISTS(p.age)\n" ); + + containsRows( res, true, true, Row.of( TestLiteral.from( false ) ) ); + + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( "MATCH (p:Person { name: 'Ann' })\n" + + "RETURN EXISTS(p.age)\n" ); + containsRows( res, true, true, Row.of( TestLiteral.from( true ) ) ); + } + + +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java new file mode 100644 index 0000000000..410b760913 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java @@ -0,0 +1,81 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Functions; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class StringFunTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void upperFunTest() { + GraphResult res = execute( "RETURN UPPER('hello')" ); + containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + res = execute( "RETURN UPPER('hElLo')" ); + containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + + + + } + + + @Test + public void LowerFunTest() { + GraphResult res = execute( "RETURN LOWER('WORLD')" ); + containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + res = execute( "RETURN LOWER('WOrLd')" ); + containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + + + } + + @Test + public void substringFunTest() + { + GraphResult res = execute( "RETURN SUBSTRING('Hello, world!', 0, 5)" ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); + + } + + @Test + public void trimFunTest() + { + GraphResult res = execute( "RETURN TRIM(' hello ')" ); + containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); + + } + + @Test + public void replaceFunTest() + { + GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', 'Cypher') " ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); + + } + +} + From affd23a91749fcb34cf7f709c42b2eea3968023e Mon Sep 17 00:00:00 2001 From: nourhan-wannan Date: Thu, 27 Jun 2024 19:52:36 +0300 Subject: [PATCH 12/55] move the files to folders --- .../org/polypheny/db/cypher/CaseTest.java | 132 -------- .../java/org/polypheny/db/cypher/DdlTest.java | 1 + .../org/polypheny/db/cypher/UnwindTest.java | 212 ------------ .../db/cypher/clause/general/CaseTest.java | 313 ++++++++++++++++++ .../{ => clause/general}/FilterTest.java | 4 +- .../{ => clause/general}/OrderByTest.java | 3 +- .../cypher/{ => clause/general}/SkipTest.java | 5 +- .../{ => clause/general}/UnionTest.java | 3 +- .../cypher/{ => clause/general}/WithTest.java | 3 +- .../cypher/{ => clause/read}/MatchTest.java | 3 +- .../{ => clause/write}/DmlDeleteTest.java | 3 +- .../{ => clause/write}/DmlInsertTest.java | 3 +- .../{ => clause/write}/DmlUpdateTest.java | 3 +- .../write/ForeachTest.java} | 43 +-- .../cypher/{ => clause/write}/MergeTest.java | 3 +- .../cypher/{ => clause/write}/RemoveTest.java | 3 +- 16 files changed, 341 insertions(+), 396 deletions(-) delete mode 100644 dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java delete mode 100644 dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/general}/FilterTest.java (93%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/general}/OrderByTest.java (98%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/general}/SkipTest.java (95%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/general}/UnionTest.java (96%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/general}/WithTest.java (99%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/read}/MatchTest.java (99%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/write}/DmlDeleteTest.java (97%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/write}/DmlInsertTest.java (98%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/write}/DmlUpdateTest.java (97%) rename dbms/src/test/java/org/polypheny/db/cypher/{TemporalTest.java => clause/write/ForeachTest.java} (51%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/write}/MergeTest.java (99%) rename dbms/src/test/java/org/polypheny/db/cypher/{ => clause/write}/RemoveTest.java (97%) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java deleted file mode 100644 index b7b3c914e5..0000000000 --- a/dbms/src/test/java/org/polypheny/db/cypher/CaseTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2019-2024 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.polypheny.db.cypher; - -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.polypheny.db.cypher.helper.TestLiteral; -import org.polypheny.db.webui.models.results.GraphResult; - - -public class CaseTest extends CypherTestTemplate { - - @BeforeEach - public void reset() { - tearDown(); - createGraph(); - } - - - protected static final String PERSON_NODE_ALICE = "CREATE (:Person {name:'Alice', age: 38, eyes: 'brown'})"; - protected static final String PERSON_NODE_BOB = "CREATE (:Person {name: 'Bob', age: 25, eyes: 'blue'})"; - protected static final String PERSON_NODE_CHARLIE = "CREATE (:Person {name: 'Charlie', age: 53, eyes: 'green'})"; - - - @Test - public void simpleCaseTest() { - execute( PERSON_NODE_ALICE ); - execute( PERSON_NODE_BOB ); - execute( PERSON_NODE_CHARLIE ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN\n" - + "CASE n.eyes\n" - + " WHEN 'blue' THEN 1\n" - + " WHEN 'brown' THEN 2\n" - + " ELSE 3\n" - + "END AS result, n.eyes" ); - - assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); - - - } - - - @Test - public void GenericCaseTest() { - execute( PERSON_NODE_ALICE ); - execute( PERSON_NODE_BOB ); - execute( PERSON_NODE_CHARLIE ); - - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN\n" - + "CASE\n" - + " WHEN n.eyes = 'blue' THEN 1\n" - + " WHEN n.age < 40 THEN 2\n" - + " ELSE 3\n" - + "END AS result, n.eyes, n.age" ); - - assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); - - } - - - @Test - - public void nullWithCaseTest() { - execute( PERSON_NODE_ALICE ); - execute( PERSON_NODE_BOB ); - execute( PERSON_NODE_CHARLIE ); - execute( SINGLE_NODE_PERSON_1 ); - - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN n.name,\n" - + "CASE n.age\n" - + " WHEN null THEN -1\n" - + " ELSE n.age - 10\n" - + "END AS age_10_years_ago" ); - - assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 28 ) ), - Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 15 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 43 ) ), - Row.of( TestLiteral.from( "MAX" ), TestLiteral.from( null ) ) ); - - - } - - - @Test - public void expressionsAndSucceedingClauses() { - execute( PERSON_NODE_ALICE ); - execute( PERSON_NODE_BOB ); - execute( PERSON_NODE_CHARLIE ); - - GraphResult res = execute( "MATCH (n:Person)\n" - + "WITH n,\n" - + "CASE n.eyes\n" - + " WHEN 'blue' THEN 1\n" - + " WHEN 'brown' THEN 2\n" - + " ELSE 3\n" - + "END AS colorCode\n" - + "SET n.colorCode = colorCode\n" - + "RETURN n.name, n.colorCode" ); - - assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) )); - - } - -} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java b/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java index e66b00a72d..cb6cb5f7d0 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java @@ -34,6 +34,7 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalGraph; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; +import org.polypheny.db.cypher.clause.write.DmlInsertTest; import org.polypheny.db.webui.models.results.GraphResult; @Tag("adapter") diff --git a/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java deleted file mode 100644 index bee6a69376..0000000000 --- a/dbms/src/test/java/org/polypheny/db/cypher/UnwindTest.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright 2019-2024 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.polypheny.db.cypher; - -import com.fasterxml.jackson.databind.introspect.AnnotationCollector.TwoAnnotations; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.polypheny.db.cypher.helper.TestGraphObject; -import org.polypheny.db.cypher.helper.TestLiteral; -import org.polypheny.db.cypher.helper.TestNode; -import org.polypheny.db.util.Pair; -import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; -import java.util.List; - -public class UnwindTest extends CypherTestTemplate { - - @BeforeEach - public void reset() { - tearDown(); - createGraph(); - } - - - @Test - public void simpleUnwindTest() { - GraphResult res = execute( "UNWIND [1, 3, null] AS x RETURN x, 'val' AS y" ); - - assert containsRows( res, true, true, - Row.of( TestLiteral.from( 1 ), TestLiteral.from( "val" ) ), - Row.of( TestLiteral.from( 3 ), TestLiteral.from( "val" ) ), - Row.of( TestLiteral.from( null ), TestLiteral.from( "val" ) ) ); - - } - - - @Test - public void emptyUnwind() { - GraphResult res = execute( "UNWIND [] AS x RETURN x, 'val' AS y" ); - - assertEmpty( res ); - } - - - @Test - public void nullUnwind() { - GraphResult res = execute( "UNWIND null AS x RETURN x, 'val' AS y" ); - - assertEmpty( res ); - } - - - @Test - public void listOfListUnwind() { - GraphResult res = execute( "WITH [[1], [2, 4], 3] AS nested UNWIND nested AS x UNWIND x AS y RETURN y" ); - - containsRows( res, true, true, - Row.of( TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( 4 ) ), - Row.of( TestLiteral.from( 3 ) ) ); - } - - - @Test - public void nodePropertyUnwind() { - execute( "CREATE (n {key: [3,1]})" ); - GraphResult res = execute( "MATCH (n) UNWIND n.key AS x RETURN x" ); - - containsRows( res, true, false, - Row.of( TestLiteral.from( 3 ) ), - Row.of( TestLiteral.from( 1 ) ) ); - } - - - @Test - public void minMaxAggregateSimpleUnWind() { - GraphResult res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] AS val RETURN min(val)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( '1' ) ) ); - - res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] As val RETURN max(val)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); - - } - - - - @Test - public void minMaxAggregateListOfListUnwind() { - GraphResult res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN min(val)" ); - - res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN max(val)" ); - - - } - - - @Test - public void maxMinAggregateNodePropertyUnWind() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); - res = execute( "MATCH (n) UNWIND n.age AS age RETURN min(age)" ); - - assert containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); - - } - - - @Test - public void sumAggregateNodePropertyUnWind() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN sum(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); - - } - - - @Test - public void AvgAggregateNodePropertyUnWind() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); - - } - - - @Test - public void CollectAggregateUnWind () - { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); - - } - - - - - - @Test - public void countUnWind() { - GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); - - - assert containsRows( res, true, false, - Row.of( TestLiteral.from( 3))); - - } - - @Test - public void distinctUnWind() { - GraphResult res = execute( "UNWIND [3, 3 ,2 ,1 ] AS i RETURN DISTINCT i" ); - assert res.getData().length == 3; - assert containsRows( res , true , false , - Row.of(TestLiteral.from(3)) , - Row.of( TestLiteral.from( 2 )) ,Row.of( TestLiteral.from( 1) )); - - - } - - - - - @Test - public void ConditionalLogicUnWind() - { - GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); - assert containsRows( res , true , true , - Row.of( TestLiteral.from( 1 ) ,TestLiteral.from("odd" ) ), - Row.of( TestLiteral.from( 2 ) ,TestLiteral.from( "even" )), - Row.of( TestLiteral.from( 3 ) ,TestLiteral.from( "odd"))); - - } - - - - - @Test - public void mapStructureUnWind() - { - GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); - assert containsRows( res , true , false , Row.of( TestLiteral.from( "Alice" ) ),Row.of( TestLiteral.from( 30 ) ) ); - - } - - - - -} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java new file mode 100644 index 0000000000..34311aefbd --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java @@ -0,0 +1,313 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.clause.general; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + + +public class CaseTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + protected static final String PERSON_NODE_ALICE = "CREATE (:Person {name:'Alice', age: 38, eyes: 'brown'})"; + protected static final String PERSON_NODE_BOB = "CREATE (:Person {name: 'Bob', age: 25, eyes: 'blue'})"; + protected static final String PERSON_NODE_CHARLIE = "CREATE (:Person {name: 'Charlie', age: 53, eyes: 'green'})"; + + + @Test + public void simpleCaseTest() { + execute( PERSON_NODE_ALICE ); + execute( PERSON_NODE_BOB ); + execute( PERSON_NODE_CHARLIE ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN\n" + + "CASE n.eyes\n" + + " WHEN 'blue' THEN 1\n" + + " WHEN 'brown' THEN 2\n" + + " ELSE 3\n" + + "END AS result, n.eyes" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); + + + } + + + @Test + public void GenericCaseTest() { + execute( PERSON_NODE_ALICE ); + execute( PERSON_NODE_BOB ); + execute( PERSON_NODE_CHARLIE ); + + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN\n" + + "CASE\n" + + " WHEN n.eyes = 'blue' THEN 1\n" + + " WHEN n.age < 40 THEN 2\n" + + " ELSE 3\n" + + "END AS result, n.eyes, n.age" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); + + } + + + @Test + + public void nullWithCaseTest() { + execute( PERSON_NODE_ALICE ); + execute( PERSON_NODE_BOB ); + execute( PERSON_NODE_CHARLIE ); + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN n.name,\n" + + "CASE n.age\n" + + " WHEN null THEN -1\n" + + " ELSE n.age - 10\n" + + "END AS age_10_years_ago" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 28 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 15 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 43 ) ), + Row.of( TestLiteral.from( "MAX" ), TestLiteral.from( null ) ) ); + + + } + + + @Test + public void expressionsAndSucceedingClauses() { + execute( PERSON_NODE_ALICE ); + execute( PERSON_NODE_BOB ); + execute( PERSON_NODE_CHARLIE ); + + GraphResult res = execute( "MATCH (n:Person)\n" + + "WITH n,\n" + + "CASE n.eyes\n" + + " WHEN 'blue' THEN 1\n" + + " WHEN 'brown' THEN 2\n" + + " ELSE 3\n" + + "END AS colorCode\n" + + "SET n.colorCode = colorCode\n" + + "RETURN n.name, n.colorCode" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) )); + + } + + public static class UnwindTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void simpleUnwindTest() { + GraphResult res = execute( "UNWIND [1, 3, null] AS x RETURN x, 'val' AS y" ); + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 1 ), TestLiteral.from( "val" ) ), + Row.of( TestLiteral.from( 3 ), TestLiteral.from( "val" ) ), + Row.of( TestLiteral.from( null ), TestLiteral.from( "val" ) ) ); + + } + + + @Test + public void emptyUnwind() { + GraphResult res = execute( "UNWIND [] AS x RETURN x, 'val' AS y" ); + + assertEmpty( res ); + } + + + @Test + public void nullUnwind() { + GraphResult res = execute( "UNWIND null AS x RETURN x, 'val' AS y" ); + + assertEmpty( res ); + } + + + @Test + public void listOfListUnwind() { + GraphResult res = execute( "WITH [[1], [2, 4], 3] AS nested UNWIND nested AS x UNWIND x AS y RETURN y" ); + + containsRows( res, true, true, + Row.of( TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( 4 ) ), + Row.of( TestLiteral.from( 3 ) ) ); + } + + + @Test + public void nodePropertyUnwind() { + execute( "CREATE (n {key: [3,1]})" ); + GraphResult res = execute( "MATCH (n) UNWIND n.key AS x RETURN x" ); + + containsRows( res, true, false, + Row.of( TestLiteral.from( 3 ) ), + Row.of( TestLiteral.from( 1 ) ) ); + } + + + @Test + public void minMaxAggregateSimpleUnWind() { + GraphResult res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] AS val RETURN min(val)" ); + containsRows( res, true, false, Row.of( TestLiteral.from( '1' ) ) ); + + res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] As val RETURN max(val)" ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); + + } + + + + @Test + public void minMaxAggregateListOfListUnwind() { + GraphResult res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN min(val)" ); + + res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN max(val)" ); + + + } + + + @Test + public void maxMinAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); + res = execute( "MATCH (n) UNWIND n.age AS age RETURN min(age)" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); + + } + + + @Test + public void sumAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN sum(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); + + } + + + @Test + public void AvgAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); + + } + + + @Test + public void CollectAggregateUnWind () + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); + + } + + + + + + @Test + public void countUnWind() { + GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); + + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 3))); + + } + + @Test + public void distinctUnWind() { + GraphResult res = execute( "UNWIND [3, 3 ,2 ,1 ] AS i RETURN DISTINCT i" ); + assert res.getData().length == 3; + assert containsRows( res , true , false , + Row.of(TestLiteral.from(3)) , + Row.of( TestLiteral.from( 2 )) ,Row.of( TestLiteral.from( 1) )); + + + } + + + + + @Test + public void ConditionalLogicUnWind() + { + GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); + assert containsRows( res , true , true , + Row.of( TestLiteral.from( 1 ) ,TestLiteral.from("odd" ) ), + Row.of( TestLiteral.from( 2 ) ,TestLiteral.from( "even" )), + Row.of( TestLiteral.from( 3 ) ,TestLiteral.from( "odd"))); + + } + + + + + @Test + public void mapStructureUnWind() + { + GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); + assert containsRows( res , true , false , Row.of( TestLiteral.from( "Alice" ) ),Row.of( TestLiteral.from( 30 ) ) ); + + } + + + + + } +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java similarity index 93% rename from dbms/src/test/java/org/polypheny/db/cypher/FilterTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 1b5a90b207..1512d91d16 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.general; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.webui.models.results.GraphResult; public class FilterTest extends CypherTestTemplate { @@ -38,6 +39,7 @@ public void simplePropertyFilter() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "MATCH (p) WHERE p.age > 3 RETURN p" ); + assertNode( res, 0 ); assert containsRows( res, true, false ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java similarity index 98% rename from dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java index 6b5f76548c..c744c3949b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/OrderByTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java @@ -14,13 +14,14 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.general; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.adapter.java.Array; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; import java.util.Arrays; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java similarity index 95% rename from dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java index 166314420e..bc07b910bb 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/SkipTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java @@ -14,17 +14,18 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.general; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; import java.util.Arrays; -public class SkipTest extends CypherTestTemplate{ +public class SkipTest extends CypherTestTemplate { @BeforeEach public void reset() { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java similarity index 96% rename from dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java index 9233088bed..138ff1452b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/UnionTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.general; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; import java.util.Arrays; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java similarity index 99% rename from dbms/src/test/java/org/polypheny/db/cypher/WithTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java index b3d8cfff05..4a9664dc79 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.general; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/MatchTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java similarity index 99% rename from dbms/src/test/java/org/polypheny/db/cypher/MatchTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java index fd1aa3fe43..77f066101c 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/MatchTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.read; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java index df770ff985..94c2b1ce38 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java @@ -14,11 +14,12 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.write; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java similarity index 98% rename from dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java index a204f2e046..cd6b7be69e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.write; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DmlUpdateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/DmlUpdateTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java index cf72fa3761..a303e5b871 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DmlUpdateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.write; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/TemporalTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java similarity index 51% rename from dbms/src/test/java/org/polypheny/db/cypher/TemporalTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java index 5097a42124..799f52c8eb 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/TemporalTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java @@ -14,15 +14,13 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.write; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.polypheny.db.cypher.helper.TestLiteral; -import org.polypheny.db.webui.models.results.GraphResult; - -public class TemporalTest extends CypherTestTemplate { +import org.polypheny.db.cypher.CypherTestTemplate; +public class ForeachTest extends CypherTestTemplate { @BeforeEach public void reset() { tearDown(); @@ -30,40 +28,5 @@ public void reset() { } - @Test - public void dateFunTest() { - - GraphResult res = execute( "RETURN DATE('2023-05-18')\n" ); - - - } - - - @Test - public void timeFunTest() { - - GraphResult res = execute( "RETURN TIME('12:34:56')" ); - - - } - - @Test - public void dateTimeFunTest() { - - GraphResult res = execute( "RETURN DATETIME('2023-05-18T12:34:56')" ); - - - } - - @Test - public void durationBetweenFunTest() { - - GraphResult res = execute( "RETURN duration.between(DATE('2023-05-18'), DATE('2023-06-18'))" ); - - - } - - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java similarity index 99% rename from dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java index aec158eb6d..e9f3b71918 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java @@ -14,11 +14,12 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.write; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java index 5df4bfc1ef..e2f86c8801 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/RemoveTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.clause.write; import io.activej.codegen.expression.impl.Null; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; From 34e10c6411250dcfe153b49142e23ce9472e4ffa Mon Sep 17 00:00:00 2001 From: nourhan-wannan Date: Sat, 29 Jun 2024 22:50:37 +0300 Subject: [PATCH 13/55] add new test cases to string func file --- .../db/cypher/Functions/StringFunTest.java | 110 +++++++++++++++--- 1 file changed, 96 insertions(+), 14 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java index 410b760913..056b706042 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java @@ -34,48 +34,130 @@ public void reset() { @Test public void upperFunTest() { GraphResult res = execute( "RETURN UPPER('hello')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); - res = execute( "RETURN UPPER('hElLo')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + res = execute( "RETURN UPPER('hElLo')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + } + + + @Test + public void EmptyUpperFunTest() { + GraphResult res = execute( "RETURN UPPER('')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + } + + @Test + public void nullUpperFunTest() { + GraphResult res = execute( "RETURN UPPER(null)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } @Test public void LowerFunTest() { GraphResult res = execute( "RETURN LOWER('WORLD')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + res = execute( "RETURN LOWER('WOrLd')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + } + + + @Test + public void emptyLowerFunTest() { + GraphResult res = execute( "RETURN LOWER('')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + } + @Test + public void NullLowerFunTest() { + GraphResult res = execute( "RETURN LOWER(null)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } + @Test - public void substringFunTest() - { + public void normalSubstringFunTest() { GraphResult res = execute( "RETURN SUBSTRING('Hello, world!', 0, 5)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); + res = execute( "RETURN SUBSTRING('Hello, world!', 7, 5)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + + res = execute( "RETURN SUBSTRING('Hello, world!', 7, 0)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + } + + + @Test + public void exceedLengthSubstringFunTest() { + GraphResult res = execute( "RETURN SUBSTRING('Hello', 0, 10)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); } + @Test - public void trimFunTest() - { + public void trimFunTest() { GraphResult res = execute( "RETURN TRIM(' hello ')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); + + res = execute( "RETURN TRIM('hello')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); + + res = execute( "RETURN TRIM(' ')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + } + + @Test + public void EmptyTrimFunTest() { + GraphResult res = execute( "RETURN TRIM('')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } + @Test - public void replaceFunTest() - { + public void NormalReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', 'Cypher') " ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); + + } + + @Test + public void caseSensitiveReplaceFunTest() { + GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'WORLD', 'Cypher')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, world!" ) ) ); + } + + + @Test + public void removeSpacesReplaceFunTest() { + GraphResult res = execute( "RETURN REPLACE('Hello, world!', ' ', '')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello,world!" ) ) ); } + + @Test + public void removeSubstringReplaceFunTest() { + GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', '')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, !" ) ) ); + } +// @Test +// public void concatenateFunTest() { +// GraphResult res = execute("RETURN 'Hello' + ' ' + 'world!'"); +// assert containsRows(res, true, true, Row.of(TestLiteral.from("Hello world!"))); +// } +// @Test +// public void LengthFunTest() { +// GraphResult res = execute("RETURN LENGTH('Hello, world!')"); +// assert containsRows(res, true, true, Row.of(TestLiteral.from(13))); +// } + + } From 395c269a7b8088762b4b4ca63b46b38c85d26cbe Mon Sep 17 00:00:00 2001 From: nourhan-wannan Date: Sat, 29 Jun 2024 23:02:17 +0300 Subject: [PATCH 14/55] add new test cases for numeric fun file --- .../db/cypher/Functions/NumericFunTest.java | 91 ++++++++++++++----- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java index 6483c30d3e..430ea01b6b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java @@ -33,53 +33,96 @@ public void reset() { @Test public void absFunTest() { - GraphResult res = execute( "RETURN ABS(-5) " ); + GraphResult res = execute( "RETURN ABS(-5) " ); - containsRows( res , true , true , Row.of( TestLiteral.from( 5 ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); + res = execute( "RETURN ABS(5)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); - res = execute( "RETURN ABS(5)" ); - containsRows( res , true , true , Row.of( TestLiteral.from( 5 ) ) ); + res = execute("RETURN ABS(0)"); + assert containsRows(res, true, true, Row.of(TestLiteral.from(0))); } @Test - public void roundFunTest() - { - GraphResult res = execute( "RETURN ROUND(3.4)" ); - containsRows( res , true , true , Row.of( TestLiteral.from( 3 ) ) ); + public void roundFunTest() { + GraphResult res = execute("RETURN ROUND(3)"); + assert containsRows(res, true, true, Row.of(TestLiteral.from(3))); + + res = execute("RETURN ROUND(-3)"); + assert containsRows(res, true, true, Row.of(TestLiteral.from(-3))); + + res = execute( "RETURN ROUND(3.4)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + + res = execute( "RETURN ROUND(3.5)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + + res = execute("RETURN ROUND(-3.5)"); + assert containsRows(res, true, true, Row.of(TestLiteral.from(-4))); + - res = execute( "RETURN ROUND(3.5)" ); - containsRows( res , true , true , Row.of( TestLiteral.from( 4 ) ) ); } + @Test - public void floorFunTest(){ - GraphResult res = execute( "RETURN FLOOR(3.16)" ); - containsRows( res , true , true , Row.of( TestLiteral.from( 3 ) ) ); + public void floorFunTest() { + + GraphResult res = execute( "RETURN FLOOR(3)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + + res = execute( "RETURN FLOOR(-3)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); + + res = execute( "RETURN FLOOR(3.16)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN FLOOR(3.9)" ); - containsRows( res , true , true , Row.of( TestLiteral.from( 3 ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + + res = execute("RETURN FLOOR(-3.16)"); + assert containsRows(res, true, true, Row.of(TestLiteral.from(-4))); + } + + + @Test + public void ceilFunTest() { + GraphResult res = execute( "RETURN CEIL(3)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + + res = execute( "RETURN CEIL(-3)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + + res = execute( "RETURN CEIL(3.16)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + + res = execute( "RETURN CEIL(3.5)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); } + @Test - public void ceilFunTest() - { - GraphResult res = execute( "RETURN CEIL(3.16)" ); - containsRows( res , true , true , Row.of( TestLiteral.from( 4 ) ) ); + public void sqrtFunTest() { + GraphResult res = execute( "RETURN SQRT(9)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); - res = execute( "RETURN CEIL(3.5)" ); - containsRows( res , true , true , Row.of( TestLiteral.from( 4 ) ) ); + res = execute("RETURN SQRT(0)"); + assert containsRows(res, true, true, Row.of(TestLiteral.from(0))); + } + @Test + public void nonPerfectSquareSqrtFunTest() { + GraphResult res = execute("RETURN SQRT(8)"); + assert containsRows(res, true, true, Row.of(TestLiteral.from(Math.sqrt(8)))); } @Test - public void sqrtFunTest() - { - GraphResult res = execute( "RETURN SQRT(9)" ); - containsRows( res , true , true , Row.of( TestLiteral.from( 3 ) ) ); + public void sqrtFunTestNegative() { + GraphResult res = execute("RETURN SQRT(-9)"); + // assert containsRows(res, true, true, Row.of(TestLiteral.from(null))); } } From b9caf5ba6ea036bf0d0d1e7038d5ab4adbe7e482 Mon Sep 17 00:00:00 2001 From: nourhan-wannan Date: Sun, 30 Jun 2024 00:32:23 +0300 Subject: [PATCH 15/55] add changes --- .../db/cypher/Functions/TemporalFunTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java index c3666862ac..69f4110555 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java @@ -21,7 +21,7 @@ import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.webui.models.results.GraphResult; -public class TemporalFunTest extends CypherTestTemplate { +public class TemporalFunTest extends CypherTestTemplate { @BeforeEach public void reset() { @@ -38,6 +38,15 @@ public void dateFunTest() { } + @Test + public void dateeeFunTest() { + + GraphResult res = execute( "RETURN DATE('2023-05-18')\n" ); + + + } + + @Test public void timeFunTest() { @@ -47,6 +56,7 @@ public void timeFunTest() { } + @Test public void dateTimeFunTest() { @@ -55,15 +65,14 @@ public void dateTimeFunTest() { } + @Test public void durationBetweenFunTest() { - GraphResult res = execute( "" ); + GraphResult res = execute( "RETURN duration.between(DATE('2023-05-18'), DATE('2023-06-18'))" ); } - - } From 7002785adae52b220b80fa2f40592ee704f54e74 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 30 Jun 2024 00:36:40 +0300 Subject: [PATCH 16/55] add changes --- .../java/org/polypheny/db/cypher/Functions/TemporalFunTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java index 69f4110555..271f18a65d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java @@ -39,7 +39,7 @@ public void dateFunTest() { } @Test - public void dateeeFunTest() { + public void dateeFunTest() { GraphResult res = execute( "RETURN DATE('2023-05-18')\n" ); From c81c488bc50a1c1caea89c582527f41e0f12625d Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 30 Jun 2024 00:41:48 +0300 Subject: [PATCH 17/55] add changes --- .../db/cypher/Functions/ListFunTest.java | 54 ++--- .../db/cypher/Functions/NumericFunTest.java | 2 + .../db/cypher/Functions/OtherFunTest.java | 22 +- .../db/cypher/Functions/TemporalFunTest.java | 6 - .../db/cypher/clause/general/CaseTest.java | 180 ----------------- .../db/cypher/clause/general/UnwindTest.java | 189 ++++++++++++++++++ .../db/cypher/clause/read/MatchTest.java | 8 + 7 files changed, 237 insertions(+), 224 deletions(-) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java index 80570f4416..a0082e921f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java @@ -30,55 +30,55 @@ public void reset() { createGraph(); } + @Test - public void simpleSizeFunTest() - { - GraphResult res = execute( "RETURN size([1, 2, 3])" ); - containsRows( res , true , true , - Row.of( TestLiteral.from( 3)) ); + public void simpleSizeFunTest() { + GraphResult res = execute( "RETURN size([1, 2, 3])" ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 3 ) ) ); } + @Test - public void nullSizeFunTest() - { - GraphResult res = execute( "RETURN size(null)" ); - containsRows( res , true , true , - Row.of( TestLiteral.from( null ) ) ); + public void nullSizeFunTest() { + GraphResult res = execute( "RETURN size(null)" ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( null ) ) ); } + @Test - public void patternExpressionSizeFunTest() - { - execute( SINGLE_EDGE_1); - execute( SINGLE_EDGE_1); - GraphResult res = execute( "MATCH (a)\n" + public void patternExpressionSizeFunTest() { + execute( SINGLE_EDGE_1 ); + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (a)\n" + "WHERE a.name = 'Max'\n" + "RETURN size((a)-[]->())) AS fof" ); - containsRows( res , true , true , - Row.of( TestLiteral.from( 2 ) ) ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 2 ) ) ); } + @Test - public void stringSizeFunTest() - { + public void stringSizeFunTest() { execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (a) RETURN size(a.name)" ); + GraphResult res = execute( "MATCH (a) RETURN size(a.name)" ); - containsRows( res , true , true , - Row.of( TestLiteral.from( 3 ) ) ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 3 ) ) ); } @Test - public void simpleRangeFunTest() - { + public void simpleRangeFunTest() { - GraphResult res = execute( "RETURN RANGE(1, 3)" ); + GraphResult res = execute( "RETURN RANGE(1, 3)" ); - containsRows( res , true , true , - Row.of( TestLiteral.from( 1 ) , TestLiteral.from( 2 ) , TestLiteral.from( 3 ) ) ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 1 ), TestLiteral.from( 2 ), TestLiteral.from( 3 ) ) ); } + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java index 430ea01b6b..9594627451 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java @@ -126,3 +126,5 @@ public void sqrtFunTestNegative() { // assert containsRows(res, true, true, Row.of(TestLiteral.from(null))); } } + + diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java index 26a7dbf3db..9867b4ef4d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java @@ -37,33 +37,33 @@ public void typeFunTest() { GraphResult res = execute( "MATCH (a)-[r]->(b)\n" + "RETURN TYPE(r)\n" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "OWNER_OF" ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "OWNER_OF" ) ) ); } + @Test - public void idFunTest() - { + public void idFunTest() { execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" + GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" + "RETURN ID(p)\n" ); // containsRows( res, true, true, Row.of( TestLiteral.from( ) ) ); } + @Test - public void ExistFunTest() - { - execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" - + "RETURN EXISTS(p.age)\n" ); + public void ExistFunTest() { + execute( SINGLE_NODE_PERSON_1 ); + GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" + + "RETURN EXISTS(p.age)\n" ); - containsRows( res, true, true, Row.of( TestLiteral.from( false ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( false ) ) ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( "MATCH (p:Person { name: 'Ann' })\n" + "RETURN EXISTS(p.age)\n" ); - containsRows( res, true, true, Row.of( TestLiteral.from( true ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( true ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java index 271f18a65d..fd14452f51 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java @@ -38,14 +38,8 @@ public void dateFunTest() { } - @Test - public void dateeFunTest() { - - GraphResult res = execute( "RETURN DATE('2023-05-18')\n" ); - } - @Test diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java index 34311aefbd..bb34a49955 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java @@ -129,185 +129,5 @@ assert containsRows( res, true, false, } - public static class UnwindTest extends CypherTestTemplate { - @BeforeEach - public void reset() { - tearDown(); - createGraph(); - } - - - @Test - public void simpleUnwindTest() { - GraphResult res = execute( "UNWIND [1, 3, null] AS x RETURN x, 'val' AS y" ); - - assert containsRows( res, true, true, - Row.of( TestLiteral.from( 1 ), TestLiteral.from( "val" ) ), - Row.of( TestLiteral.from( 3 ), TestLiteral.from( "val" ) ), - Row.of( TestLiteral.from( null ), TestLiteral.from( "val" ) ) ); - - } - - - @Test - public void emptyUnwind() { - GraphResult res = execute( "UNWIND [] AS x RETURN x, 'val' AS y" ); - - assertEmpty( res ); - } - - - @Test - public void nullUnwind() { - GraphResult res = execute( "UNWIND null AS x RETURN x, 'val' AS y" ); - - assertEmpty( res ); - } - - - @Test - public void listOfListUnwind() { - GraphResult res = execute( "WITH [[1], [2, 4], 3] AS nested UNWIND nested AS x UNWIND x AS y RETURN y" ); - - containsRows( res, true, true, - Row.of( TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( 4 ) ), - Row.of( TestLiteral.from( 3 ) ) ); - } - - - @Test - public void nodePropertyUnwind() { - execute( "CREATE (n {key: [3,1]})" ); - GraphResult res = execute( "MATCH (n) UNWIND n.key AS x RETURN x" ); - - containsRows( res, true, false, - Row.of( TestLiteral.from( 3 ) ), - Row.of( TestLiteral.from( 1 ) ) ); - } - - - @Test - public void minMaxAggregateSimpleUnWind() { - GraphResult res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] AS val RETURN min(val)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( '1' ) ) ); - - res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] As val RETURN max(val)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); - - } - - - - @Test - public void minMaxAggregateListOfListUnwind() { - GraphResult res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN min(val)" ); - - res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN max(val)" ); - - - } - - - @Test - public void maxMinAggregateNodePropertyUnWind() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); - res = execute( "MATCH (n) UNWIND n.age AS age RETURN min(age)" ); - - assert containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); - - } - - - @Test - public void sumAggregateNodePropertyUnWind() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN sum(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); - - } - - - @Test - public void AvgAggregateNodePropertyUnWind() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); - - } - - - @Test - public void CollectAggregateUnWind () - { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); - - } - - - - - - @Test - public void countUnWind() { - GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); - - - assert containsRows( res, true, false, - Row.of( TestLiteral.from( 3))); - - } - - @Test - public void distinctUnWind() { - GraphResult res = execute( "UNWIND [3, 3 ,2 ,1 ] AS i RETURN DISTINCT i" ); - assert res.getData().length == 3; - assert containsRows( res , true , false , - Row.of(TestLiteral.from(3)) , - Row.of( TestLiteral.from( 2 )) ,Row.of( TestLiteral.from( 1) )); - - - } - - - - - @Test - public void ConditionalLogicUnWind() - { - GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); - assert containsRows( res , true , true , - Row.of( TestLiteral.from( 1 ) ,TestLiteral.from("odd" ) ), - Row.of( TestLiteral.from( 2 ) ,TestLiteral.from( "even" )), - Row.of( TestLiteral.from( 3 ) ,TestLiteral.from( "odd"))); - - } - - - - - @Test - public void mapStructureUnWind() - { - GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); - assert containsRows( res , true , false , Row.of( TestLiteral.from( "Alice" ) ),Row.of( TestLiteral.from( 30 ) ) ); - - } - - - - - } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java new file mode 100644 index 0000000000..25205af05d --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java @@ -0,0 +1,189 @@ +package org.polypheny.db.cypher.clause.general; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class UnwindTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void simpleUnwindTest() { + GraphResult res = execute( "UNWIND [1, 3, null] AS x RETURN x, 'val' AS y" ); + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 1 ), TestLiteral.from( "val" ) ), + Row.of( TestLiteral.from( 3 ), TestLiteral.from( "val" ) ), + Row.of( TestLiteral.from( null ), TestLiteral.from( "val" ) ) ); + + } + + + @Test + public void emptyUnwind() { + GraphResult res = execute( "UNWIND [] AS x RETURN x, 'val' AS y" ); + + assertEmpty( res ); + } + + + @Test + public void nullUnwind() { + GraphResult res = execute( "UNWIND null AS x RETURN x, 'val' AS y" ); + + assertEmpty( res ); + } + + + @Test + public void listOfListUnwind() { + GraphResult res = execute( "WITH [[1], [2, 4], 3] AS nested UNWIND nested AS x UNWIND x AS y RETURN y" ); + + containsRows( res, true, true, + Row.of( TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( 4 ) ), + Row.of( TestLiteral.from( 3 ) ) ); + } + + + @Test + public void nodePropertyUnwind() { + execute( "CREATE (n {key: [3,1]})" ); + GraphResult res = execute( "MATCH (n) UNWIND n.key AS x RETURN x" ); + + containsRows( res, true, false, + Row.of( TestLiteral.from( 3 ) ), + Row.of( TestLiteral.from( 1 ) ) ); + } + + + @Test + public void minMaxAggregateSimpleUnWind() { + GraphResult res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] AS val RETURN min(val)" ); + containsRows( res, true, false, Row.of( TestLiteral.from( '1' ) ) ); + + res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] As val RETURN max(val)" ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); + + } + + + + @Test + public void minMaxAggregateListOfListUnwind() { + GraphResult res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN min(val)" ); + + res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN max(val)" ); + + + } + + + @Test + public void maxMinAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); + res = execute( "MATCH (n) UNWIND n.age AS age RETURN min(age)" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); + + } + + + @Test + public void sumAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN sum(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); + + } + + + @Test + public void AvgAggregateNodePropertyUnWind() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); + + } + + + @Test + public void CollectAggregateUnWind () + { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute(SINGLE_NODE_PERSON_COMPLEX_2); + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); + + } + + + + + + @Test + public void countUnWind() { + GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); + + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 3))); + + } + + @Test + public void distinctUnWind() { + GraphResult res = execute( "UNWIND [3, 3 ,2 ,1 ] AS i RETURN DISTINCT i" ); + assert res.getData().length == 3; + assert containsRows( res , true , false , + Row.of(TestLiteral.from(3)) , + Row.of( TestLiteral.from( 2 )) ,Row.of( TestLiteral.from( 1) )); + + + } + + + + + @Test + public void ConditionalLogicUnWind() + { + GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); + assert containsRows( res , true , true , + Row.of( TestLiteral.from( 1 ) ,TestLiteral.from("odd" ) ), + Row.of( TestLiteral.from( 2 ) ,TestLiteral.from( "even" )), + Row.of( TestLiteral.from( 3 ) ,TestLiteral.from( "odd"))); + + } + + + + + @Test + public void mapStructureUnWind() + { + GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); + assert containsRows( res , true , false , Row.of( TestLiteral.from( "Alice" ) ),Row.of( TestLiteral.from( 30 ) ) ); + + } + + + + +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java index 77f066101c..e5f96757e3 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java @@ -354,6 +354,14 @@ assert containsRows( res, true, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ) ); + + res = execute( "MATCH Path = (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'}) RETURN Path " ); + assert containsRows( res, true, true, + Row.of( TestPath.of( + TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), + TestEdge.from( List.of( "OWNER_OF" ) ), + KIRA ) ) ); + } From f7e364b15c877f1cd2da9ca5784fa717cecd803c Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Fri, 5 Jul 2024 21:18:46 +0300 Subject: [PATCH 18/55] update testcases within delete test file --- .../db/cypher/clause/write/DmlDeleteTest.java | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java index 94c2b1ce38..63a10b2bd6 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java @@ -16,6 +16,7 @@ package org.polypheny.db.cypher.clause.write; +import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -69,9 +70,8 @@ assert containsRows( res, true, false, public void twoNodeDeleteTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - execute( "MATCH (p:Person {name: 'Max'}), (h:Person {name: 'Hans'})\n" + GraphResult res = execute( "MATCH (p:Person {name: 'Max'}), (h:Person {name: 'Hans'})\n" + "DELETE p, h" ); - GraphResult res = matchAndReturnAllNodes(); assertEmpty( res ); } @@ -81,8 +81,11 @@ public void simpleRelationshipDeleteTest() { execute( SINGLE_EDGE_1 ); execute( "MATCH (:Person {name: 'Max'})-[rel:OWNER_OF]->(:Animal {name: 'Kira'}) \n" + "DELETE rel" ); + GraphResult res = execute( "MATCH (n)-[rel:OWNER_OF]->(a) \n" + + "RETURN rel" ); + assertEmpty( res ); - GraphResult res = matchAndReturnAllNodes(); + res = matchAndReturnAllNodes(); assert containsRows( res, true, false, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ) ), Row.of( TestNode.from( @@ -93,63 +96,72 @@ assert containsRows( res, true, false, } + @Test public void relationshipWithPropertiesDeleteTest() { execute( SINGLE_EDGE_2 ); - execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) \n" + execute( "MATCH (:Person {name: 'Max'})-[rel:KNOWS {since: 1994}]->(:Person {name:'Hans'}) \n" + "DELETE rel" ); - GraphResult res = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal)"); - assertEmpty( res ); + GraphResult res = execute( "MATCH (p1)-[rel:KNOWS ]->(p2) RETURN rel " ); + assertEmpty( res ); + + res = matchAndReturnAllNodes(); + assert containsRows( res, true, false, + Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ) ), + Row.of( TestNode.from( + List.of( "Person" ), + Pair.of( "name", "Hans" ), + Pair.of( "age", 31 )))); + + + } @Test - public void pathDeleteTest() - { + public void pathDeleteTest() { execute( SINGLE_EDGE_1 ); - execute( "MATCH p = (person:Person {name: 'Max'})-[rel:OWNER_OF]->( animal :Animal {name: 'Kira'})\n" - + "DELETE p\n" ); + execute( "MATCH p = (person:Person {name: 'Max'})-[rel:OWNER_OF]->( animal :Animal {name: 'Kira'})\n" + + "DELETE p\n" ); - GraphResult res = matchAndReturnAllNodes() ; - GraphResult edges = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal)"); - assert res.getData().length == 0 && edges.getData().length == 0 ; + GraphResult res = matchAndReturnAllNodes(); + GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) RETURN rel " ); + assert res.getData().length == 0 && relations.getData().length == 0; } + @Test - public void NodeWithAllRelationshipsDeleteTest() - { + public void NodeWithAllRelationshipsDeleteTest() { execute( SINGLE_EDGE_2 ); execute( "MATCH (n:Person {name: 'MAX'})\n" + "DETACH DELETE n" ); - - GraphResult res = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal)"); - assert res.getData().length == 0 ; + GraphResult res = matchAndReturnAllNodes(); + GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) Return rel" ); + assert res.getData().length == 0 && relations.getData().length == 0; } + + @Test - public void allNodesAndRelationshipsDeleteTest () - { + public void allNodesAndRelationshipsDeleteTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_EDGE_1 ); execute( "MATCH (n)\n" - + "DETACH DELETE n" ) ; - + + "DETACH DELETE n" ); - GraphResult res = matchAndReturnAllNodes() ; - GraphResult edges = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal)"); - assert res.getData().length == 0 && edges.getData().length == 0 ; + GraphResult res = matchAndReturnAllNodes(); + GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) Return rel" ); + assert res.getData().length == 0 && relations.getData().length == 0; } - - } From 1bcf85f479d70f5baed254463c12b52b6a85300c Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Fri, 5 Jul 2024 22:12:40 +0300 Subject: [PATCH 19/55] add testcases for filter test file --- .../db/cypher/clause/general/FilterTest.java | 75 ++++++++++++++++--- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 1512d91d16..3e2c8ca4be 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -19,35 +19,92 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; public class FilterTest extends CypherTestTemplate { @BeforeEach - public void reset() { + public void setUp() { tearDown(); createGraph(); } /////////////////////////////////////////////// - ///////// FILTER + /////////// FILTER /////////////////////////////////////////////// @Test - public void simplePropertyFilter() { + public void simpleConditionFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); - GraphResult res = execute( "MATCH (p) WHERE p.age > 3 RETURN p" ); + GraphResult result = execute( "MATCH (p) WHERE p.age > 3 RETURN p" ); - assertNode( res, 0 ); + assertNode( result, 0 ); - assert containsRows( res, true, false ); + assert containsRows( result, true, false ); - res = execute( "MATCH (p) WHERE p.age >= 3 RETURN p" ); - assertNode( res, 0 ); + result = execute( "MATCH (p) WHERE p.age >= 3 RETURN p" ); + assertNode( result, 0 ); - assert containsRows( res, true, false, Row.of( KIRA ) ); + assert containsRows( result, true, false, Row.of( KIRA ) ); } + + @Test + public void multipleConditionsFilterTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult result = execute( "MATCH (p) WHERE p.age >= 45 AND p.depno = 13 RETURN p.name" ); + + assert containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); + + result = execute( "MATCH (p) WHERE p.age <= 32 OR p.depno = 13 RETURN p.name " ); + + assert containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ), + Row.of( TestLiteral.from( "Bob" ) ), + Row.of( TestLiteral.from( "Alex" ) ) ); + } + + + @Test + public void existFilterTest() { + execute( SINGLE_NODE_PERSON_1 ); + GraphResult result = execute( "MATCH (p) WHERE exists(p.age) RETURN p" ); + + assertEmpty( result ); + + result = execute( "MATCH (p) WHERE exists(p.name) RETURN p" ); + assertNode( result, 0 ); + + assert containsRows( result, true, false, Row.of( MAX ) ); + } + + + @Test + public void startWithFilterTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult result = execute( "MATCH (p) WHERE p.name STARTS WITH 'M' RETURN p.name" ); + + assert containsRows( result, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + + + } + + + @Test + public void containsFilterTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult result = execute( "MATCH (p) WHERE p.name CONTAINS 'H' RETURN p.name" ); + + assert containsRows( result, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + } + + } From 7788b22811be33468fe185e775326ef3d3a24317 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Fri, 5 Jul 2024 22:54:49 +0300 Subject: [PATCH 20/55] add testcases for Other test file --- .../db/cypher/Functions/OtherFunTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java index 9867b4ef4d..eca5e3d731 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java @@ -16,6 +16,7 @@ package org.polypheny.db.cypher.Functions; +import org.checkerframework.checker.units.qual.K; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -67,4 +68,62 @@ public void ExistFunTest() { } + + @Test + public void testCoalesceFunction() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_PERSON_COMPLEX_1); + GraphResult result = execute("MATCH (p) RETURN p.name, coalesce(p.age, 0) AS age"); + + + assert containsRows(result, true, false, + Row.of(TestLiteral.from( "Max" ) ,TestLiteral.from( 0 )), + Row.of(TestLiteral.from( "Hans" ) , TestLiteral.from( 0 )), + Row.of(TestLiteral.from( "Ann" ),TestLiteral.from( 45 ))); + } + + @Test + public void testIsNullFunction() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_PERSON_COMPLEX_1); + GraphResult result = execute("MATCH (p) WHERE p.age IS NULL RETURN p"); + + assertNode(result, 0); + + assert containsRows(result, true, false, + Row.of(HANS), + Row.of(MAX)); + } + + @Test + public void testIsNotNullFunction() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_ANIMAL); + GraphResult result = execute("MATCH (p) WHERE p.type IS NOT NULL RETURN p"); + + assertNode(result, 0); + + assert containsRows(result, true, false, + Row.of( KIRA) ); + } + + @Test + public void testDefaultValuesWithCoalesce() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_PERSON_COMPLEX_1); + GraphResult result = execute("MATCH (p) RETURN p.name, coalesce(p.age, 'unknown') AS age"); + + assertNode(result, 0); + + assert containsRows(result, true, false, + Row.of(TestLiteral.from( "Max" ) ,TestLiteral.from( "unknown")), + Row.of(TestLiteral.from( "Hans" ) , TestLiteral.from("unknown" )), + Row.of(TestLiteral.from( "Ann" ),TestLiteral.from( "unknown" ))); + } + + } From 63c48f45e0d14f4f59bc56e52db1708168d6123a Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 23 Jul 2024 19:48:14 +0300 Subject: [PATCH 21/55] add testcases for call test --- .../db/cypher/clause/general/CallTest.java | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java new file mode 100644 index 0000000000..0403f7d783 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java @@ -0,0 +1,181 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.clause.general; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; + +public class CallTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void simpleCallProcedureTest() { + GraphResult res = execute( "CALL db.labels()" ); + assertEmpty (res); + + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + res = execute( "CALL db.labels()" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Person" ) ), + Row.of( TestLiteral.from( "Animal" ) ) ); + + + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + + res = execute( "CALL db.labels()" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Person" ) ), + Row.of( TestLiteral.from( "Person" ) ), + Row.of( TestLiteral.from( "Animal" ) ), + Row.of( TestLiteral.from( "Animal" ) )); + + } + + + + @Test + public void callLabelsYieldTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult res = execute( "CALL db.labels() YIELD label" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Person" ) ), + Row.of( TestLiteral.from( "Animal" ) ) ); + } + + @Test + public void renameCallLabelsYieldTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult res = execute( "CALL db.labels() YIELD label As Label" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Person" ) ), + Row.of( TestLiteral.from( "Animal" ) ) ); + } + + + @Test + public void callLabelsYieldCountTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult res = execute( "CALL db.labels() YIELD *" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 2 ) )); + } + + @Test + public void returnCallLabelsYieldTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult res = execute( "CALL db.labels() YIELD label\n" + + "RETURN label" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 2 ) ) ); + } + + @Test + public void returnFilterCallLabelsYieldTest() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_ANIMAL); + GraphResult res = execute("CALL db.labels() YIELD label WHERE label = 'Person' RETURN count(label) AS numLabels"); + + assert containsRows(res, true, false, + Row.of(TestLiteral.from(1))); + } + + @Test + public void callLabelsYieldWithOrderingTest() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_PERSON_2); + execute(SINGLE_NODE_ANIMAL); + GraphResult res = execute("CALL db.labels() YIELD label RETURN label ORDER BY label"); + + assert containsRows(res, true, false, + Row.of(TestLiteral.from("Animal")), + Row.of(TestLiteral.from("Person")), + Row.of(TestLiteral.from("Person"))); + } + + @Test + public void callLabelsYieldWithAggregationTest() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_ANIMAL); + execute(SINGLE_NODE_PERSON_2); + GraphResult res = execute("CALL db.labels() YIELD label RETURN label, count(*) AS labelCount"); + + assert containsRows(res, true, false, + Row.of(TestLiteral.from("Person"), TestLiteral.from(2)), + Row.of(TestLiteral.from("Animal"), TestLiteral.from(1))); + } + + @Test + public void simpleCallPropertyKeysYieldTest() { + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_ANIMAL); + execute(SINGLE_NODE_PERSON_2); + GraphResult res = execute("CALL db.propertyKeys() YIELD propertyKey "); + assert containsRows(res, true, false, + Row.of(TestLiteral.from("name")), + Row.of(TestLiteral.from("age")), + Row.of(TestLiteral.from("type"))); + + } + + @Test + public void renameCallPropertyKeysYieldTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult res = execute( "CALL db.propertyKeys() YIELD propertyKey AS prop" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Person" ) ), + Row.of( TestLiteral.from( "Animal" ) ) ); + } + @Test + public void callPropertyKeysYieldWithMatchTest() + { + + execute(SINGLE_NODE_PERSON_1); + execute(SINGLE_NODE_ANIMAL); + execute(SINGLE_NODE_PERSON_2); + GraphResult res = execute( "CALL db.propertyKeys() YIELD propertyKey AS prop\n" + + "MATCH (n)\n" + + "WHERE n[prop] IS NOT NULL\n" + + "RETURN prop, count(n) AS numNodes" ); + + + assert containsRows(res, true, false, + Row.of(TestLiteral.from("name") , TestLiteral.from( 3 )), + Row.of(TestLiteral.from("age") ,TestLiteral.from( 1)), + Row.of(TestLiteral.from("type") ,TestLiteral.from( 1 ))); + } + + + +} From 079e5f0ca60642af94b024ec1c5d909e8573095d Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 23 Jul 2024 19:52:14 +0300 Subject: [PATCH 22/55] move aggregation test file to func folder remove comment from merge test file add test cases for limit clause --- .../cypher/{ => Functions}/AggregateTest.java | 3 +- .../db/cypher/clause/general/LimitTest.java | 102 ++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) rename dbms/src/test/java/org/polypheny/db/cypher/{ => Functions}/AggregateTest.java (99%) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java similarity index 99% rename from dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java index ae9ab2c92d..b460d244b3 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java @@ -14,11 +14,12 @@ * limitations under the License. */ -package org.polypheny.db.cypher; +package org.polypheny.db.cypher.Functions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; import java.util.Arrays; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java new file mode 100644 index 0000000000..90513699ae --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java @@ -0,0 +1,102 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.clause.general; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.adapter.annotations.AdapterSettingList.List; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.util.Pair; +import org.polypheny.db.webui.models.results.GraphResult; + +public class LimitTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void simpleLimitTest() { + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (n) RETURN n.name, n.age LIMIT 3" ); + + assert res.getData().length == 3; + } + + + @Test + public void orderByLimitTest() { + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_1 ); + + GraphResult res = execute( "MATCH (n) RETURN n.name ORDER BY n.name DESC LIMIT 3" ); + + assert res.getData().length == 3; + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Kira" ) ) ); + + } + + + @Test + public void withLimitTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + + GraphResult res = execute( "MATCH (n) WITH n LIMIT 2 RETURN n.name, n.age;" ); + assert res.getData().length == 2; + } + + + @Test + public void withAndOrderByLimitTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + + GraphResult res = execute( "MATCH (n)\n" + + "WITH n ORDER BY n.name LIMIT 1\n" + + "RETURN n" ); + + assert res.getData().length == 1; + + assert containsNodes( res, true, + TestNode.from( Pair.of( "name" , "Ann" ) , + Pair.of( "age" , 45 ) , + Pair.of( "depno" , 13 )) ); + + + } + + +} From e162d87a61a7e176d07b0f60af24a092c0cf166b Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 23 Jul 2024 19:52:33 +0300 Subject: [PATCH 23/55] remove comment from merge test file --- .../polypheny/db/cypher/clause/write/MergeTest.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java index e9f3b71918..bfbcaeb6df 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java @@ -105,10 +105,7 @@ public void singleNodeWithSinglePropertyMergeTest() { execute( "MERGE (charlie {name: 'Charlie Sheen'})" ); GraphResult res = matchAndReturnAllNodes(); - System.out.print("hello: "); - // Printing the data using Arrays.deepToString - String[][] data = res.getData(); - System.out.println( Arrays.deepToString(data)); + assertNode( res, 0 ); assert containsNodes( res, true, TestNode.from( List.of(), Pair.of( "name", "Charlie Sheen" ) ) ); @@ -392,11 +389,5 @@ assert containsRows( res, true, true, - // do you want me to test this ?? - @Test - public void UniqueConstrainsMergeTest() { - - } - } From 990c862ac501d3632e928f99d4c04dd4abc838d9 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 28 Jul 2024 04:48:06 +0300 Subject: [PATCH 24/55] add tests for insert test file add tests for Match test file --- .../db/cypher/clause/read/MatchTest.java | 99 +++++++++++++++- .../db/cypher/clause/write/DmlInsertTest.java | 108 ++++++++++++++++-- 2 files changed, 196 insertions(+), 11 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java index e5f96757e3..2004858eda 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java @@ -16,15 +16,20 @@ package org.polypheny.db.cypher.clause.read; +import java.util.Arrays; import java.util.List; +import io.activej.codegen.expression.impl.Null; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.polypheny.db.adapter.annotations.AdapterSettingList; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.cypher.helper.TestObject; import org.polypheny.db.cypher.helper.TestPath; +import org.polypheny.db.interpreter.Row; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; @@ -115,6 +120,17 @@ public void simpleMatchMultiplePropertyTest() { /////////////////////////////////////////////// + @Test + public void NoLabelPropertyTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + GraphResult res = execute( "MATCH (n) RETURN n.age" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ), + Row.of( TestLiteral.from( null ) ) ); + + } + + @Test public void simplePropertyTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -157,6 +173,7 @@ public void simpleEdgeTest() { } + @Test public void emptyEdgeTest() { execute( SINGLE_EDGE_1 ); @@ -184,7 +201,8 @@ public void singleEdgeFilterMatchNodeTest() { execute( SINGLE_EDGE_1 ); execute( SINGLE_EDGE_2 ); GraphResult res = execute( "MATCH (n:Person)-[r:KNOWS {since: 1994}]->() RETURN n" ); - assert containsNodes( res, true, TestEdge.from( List.of( "Person" ), Pair.of( "name", "Max" ) ) ); + + assert containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ) ); } @@ -316,6 +334,12 @@ assert containsRows( res, true, false, Row.of( KIRA ), Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "age", 31 ) ) ) ); + res = execute( "MATCH (p:Person {name:'Max'})-->(t) RETURN t " ); + assert containsRows( res, true, false, + Row.of( KIRA ), + Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "age", 31 ) ) ) ); + + } @@ -349,6 +373,7 @@ public void matchPathTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH (m {name:'Max'}), (k {name:'Kira'}), p = (m)-[]-(k)\n" + "RETURN p" ); + assert containsRows( res, true, true, Row.of( TestPath.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), @@ -362,7 +387,79 @@ assert containsRows( res, true, true, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ) ); + + } + + + @Test + public void returnPathsByAsteriskMatchTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH Path = () -[]->() RETURN *" ); + + assert containsRows( res, true, false, + Row.of( TestPath.of( MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ) ); + + } + @Test + public void returnNodesByAsteriskMatchTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (p) RETURN *" ); + + assert containsRows( res, true, false, + Row.of( MAX ), + Row.of( KIRA ) ); + } + + + @Test + public void returnBothSideByAsteriskMatchTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (p) -[]->(m) RETURN *" ); + assert containsRows( res, true, false, + Row.of( MAX ), + Row.of( KIRA ) ); + } + + + @Test + public void returnAllElementsByAsteriskMatchTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH Path = (p) -[r] ->(m) RETURN *" ); + assert containsRows( res, true, false, + Row.of( TestPath.of( MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) + ,MAX , TestEdge.from(List.of("OWNER_OF") ) ,KIRA ) ); + } + + + @Test + public void returnEdgesByAsteriskMatchTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH ()-[r]-() RETURN *" ); + assert containsEdges( res, true,TestEdge.from( List.of( "OWNER_OF" ) ) ); + + } + + + @Test + public void shortestPathMatchTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (b:Person {name: 'Max'}), (a:Animal {name: 'Kira'})\n" + + "MATCH p = shortestPath((b)-[*]-(a))\n" + + "RETURN p\n" ); + + assert containsRows( res, true, true, + Row.of( TestPath.of( + TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), + TestEdge.from( List.of( "OWNER_OF" ) ), + KIRA ) ) ); + + + } + + + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java index cd6b7be69e..80d9a2e744 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java @@ -16,6 +16,7 @@ package org.polypheny.db.cypher.clause.write; +import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -51,12 +52,38 @@ public void reset() { @Test - public void insertEmptyNode() { + public void insertEmptyNodeWithNoVariableNoLabelTest() { + execute( "CREATE ()" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of() ) ); + } + + + @Test + public void insertEmptyNodeWithNoVariableTest() { + execute( "CREATE (:Person)" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); + } + + + @Test + public void insertEmptyNoLabelNodeTest() { execute( "CREATE (p)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); assert containsNodes( res, true, TestNode.from( List.of() ) ); } + @Test + public void insertEmptyNodeTest() + { + execute( "CREATE (p:Person)" ); + GraphResult res = matchAndReturnAllNodes(); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); + } @Test @@ -67,26 +94,30 @@ public void insertNodeTest() { assert containsNodes( res, true, TestNode.from( Pair.of( "name", "Max Muster" ) ) ); } + @Test public void insertNodeWithManyLabelsTest() { execute( "CREATE (p:Person :Employee )" ); GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, TestNode.from(List.of("Person" , "Employee") )); + assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ) ) ); } + + @Test - public void insertNodeWithManyLabelsAndPropertyTest () - { - execute( "CREATE (n:Person:Employee {name :'MAX'})" ); - GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, TestNode.from(List.of("Person" , "Employee") ,Pair.of( "name" , "Max" ))); + public void insertNodeWithManyLabelsAndPropertyTest() { + execute( "CREATE (n:Person:Employee {name :'Max'})" ); + + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ) ); } + + @Test - public void insertNodeWithPropertyContainsListTest() - { + public void insertNodeWithPropertyContainsListTest() { execute( "CREATE ({l: [1 ,2,3]})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1 ; + assert res.getData().length == 1; } @@ -133,9 +164,29 @@ public void insertReturnNodeTest() { GraphResult res = execute( "CREATE (p:Person {name: 'Max Muster'})\n" + "RETURN p" ); + assertNode( res, 0 ); + assert containsNodes( res, true, TestNode.from( List.of() ) ); } + @Test + public void insertSingleHopPathNoVariableTest() + { + execute( "CREATE (p:Person {name :'Max'}) -[ : OWNER_OF] ->(a: Animal {name :'Kira' , age: 3 , type :'dog'})" ); + GraphResult res = matchAndReturnAllNodes(); + // only select all nodes + assert containsNodes( res, true, + TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), + TestNode.from( + List.of( "Animal" ), + Pair.of( "name", "Kira" ), + Pair.of( "age", 3 ), + Pair.of( "type", "dog" ) ) ); + + // only select all edges + res = execute( "MATCH ()-[r]->() RETURN r" ); + assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); + } @Test public void insertSingleHopPathTest() { execute( "CREATE (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'})" ); @@ -147,6 +198,7 @@ assert containsNodes( res, true, Pair.of( "name", "Kira" ), Pair.of( "age", 3 ), Pair.of( "type", "dog" ) ) ); + } @@ -157,6 +209,42 @@ public void insertSingleHopPathEdgesTest() { assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); } + @Test + public void insertSingleHopPathWithMultiplePropertiesTest() + { + execute( "CREATE (p:Person {name: 'Max'})-[rel:KNOWS {since: 1994 , relation : 'friend'}]->(a:Person {name:'Hans', age:31})" ); + + // only select all nodes + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, + TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), + TestNode.from( + List.of( "Person" ), + Pair.of( "name", "Hans" ), + Pair.of( "age", 31))); + + // only select all edges + res = execute( "MATCH ()-[r]->() RETURN r" ); + assert containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ) , + Pair.of( "since" , 1994 ) , Pair.of( "relation" ,"friend" )) ); + + } + @Test + public void insertSingleHopPathWithListPropertyTest() { + execute( "Create (p:Person:Employee {name: 'Max'})-[role:ACTED_IN {roles:['Neo', 42, 'Thomas Anderson']}]->(matrix:Movie {title: 'The Matrix'})" ); + // only select all nodes + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, + TestNode.from( List.of( "Person" , "Employee"), Pair.of( "name", "Max" ) ), + TestNode.from( + List.of( "Movie" ), + Pair.of( "title", "The Matrix" ) ) ); + + // only select all edges + res = execute( "MATCH ()-[r]->() RETURN r" ); + assert containsEdges( res, true, TestEdge.from( List.of( "ACTED_IN" ), + Pair.of( "roles", List.of( "Neo", 42, "Thomas Anderson" ) ) ) ); + } @Test public void insertMultipleHopPathTest() { From 8242172d9613e76199da24c961c8ce6ccbdbe614 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 28 Jul 2024 22:45:49 +0300 Subject: [PATCH 25/55] add new tests to Union Test file --- .../db/cypher/clause/general/UnionTest.java | 175 ++++++++++++++---- 1 file changed, 138 insertions(+), 37 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java index 138ff1452b..690d4df530 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java @@ -26,84 +26,185 @@ public class UnionTest extends CypherTestTemplate { - @BeforeEach public void reset() { tearDown(); createGraph(); } + protected static final String SINGLE_NODE_MOVIE = "CREATE (wallStreet:Movie {title: 'Wall Street' , released : 2002})"; + @Test public void simpleUnionTest() { execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2); + execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_ANIMAL); - execute( SINGLE_NODE_ANIMAL); - - GraphResult res = execute( "MATCH (n:Actor)\n" - + "RETURN n.name AS name\n" + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN n.name \n" + "UNION \n" - + "MATCH (n:Movie)\n" - + "RETURN n.title AS name" ); + + "MATCH (n:Person)\n" + + "RETURN n.name " ); + containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Hans" ) ) ); + } - containsRows( res, true, false, + @Test + public void DifferentStructureUnionTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_MOVIE); + + GraphResult res = execute( "MATCH (p:Person)\n" + + "RETURN p.name AS name\n" + + "UNION\n" + + "MATCH (m :Movie)\n" + + "RETURN p.Title AS name\n" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Hans" ) ), - Row.of( TestLiteral.from( "Kira" ) )); + Row.of( TestLiteral.from( "Wall Street" )) ); + } + + @Test + public void NullPropertiesUnionTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1); + execute( SINGLE_NODE_PERSON_COMPLEX_1); + execute( SINGLE_NODE_MOVIE); + + GraphResult res = execute( "MATCH (p:Person)\n" + + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" + + "UNION\n" + + "MATCH (m:Movie)\n" + + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n"); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ) , TestLiteral.from( 45 ) , TestLiteral.from( null ),TestLiteral.from( null )), + Row.of( TestLiteral.from( null ),TestLiteral.from( null ),TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 )) ); } + + @Test public void allUnionTest() { execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_ANIMAL); - execute( SINGLE_NODE_ANIMAL); - - GraphResult res = execute( "MATCH (n:Actor)\n" - + "RETURN n.name AS name\n" - + "UNION ALL\n" - + "MATCH (n:Movie)\n" - + "RETURN n.title AS name" ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_PERSON_1); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN n.name \n" + + "UNION ALL \n" + + "MATCH (n:Person)\n" + + "RETURN n.name " ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Hans" ) ), - Row.of( TestLiteral.from( "Kira" ) ), - Row.of( TestLiteral.from( "Kira" ) ) ); + Row.of( TestLiteral.from( "Hans" ) ) , + Row.of(TestLiteral.from( "Max" )), + Row.of(TestLiteral.from( "Hans" ))); } + @Test + public void DifferentStructureAllUnionTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_MOVIE); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_MOVIE ); + GraphResult res = execute( "MATCH (p:Person)\n" + + "RETURN p.name AS name\n" + + "UNION ALL\n" + + "MATCH (m :Movie)\n" + + "RETURN p.Title AS name\n" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Wall Street" )), + Row.of( TestLiteral.from( "Max" )), + Row.of( TestLiteral.from( "Wall Street" ))); + } + + @Test + public void NullPropertiesAllUnionTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_MOVIE ); + execute( SINGLE_NODE_MOVIE); + + GraphResult res = execute( "MATCH (p:Person)\n" + + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" + + "UNION ALL\n" + + "MATCH (m:Movie)\n" + + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n"); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ) , TestLiteral.from( 45 ) , TestLiteral.from( null ),TestLiteral.from( null )), + Row.of( TestLiteral.from( "Ann" ) , TestLiteral.from( 45 ) , TestLiteral.from( null ),TestLiteral.from( null )), + Row.of( TestLiteral.from( null ),TestLiteral.from( null ),TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 )), + Row.of( TestLiteral.from( null ),TestLiteral.from( null ),TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 )) ); + } @Test public void distinctUnionTest() { execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_PERSON_1); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (n:Person)\n" + + "RETURN n.name \n" + + "UNION DISTINCT \n" + + "MATCH (n:Person)\n" + + "RETURN n.name " ); + + containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Hans" ) ) ); + } + + + @Test + public void DifferentStructureDistinctUnionTest() { execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_ANIMAL); - execute( SINGLE_NODE_ANIMAL); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_MOVIE); - GraphResult res = execute( "MATCH (n:Actor)\n" - + "RETURN n.name AS name\n" + GraphResult res = execute( "MATCH (p:Person)\n" + + "RETURN p.name AS name\n" + "UNION DISTINCT\n" - + "MATCH (n:Movie)\n" - + "RETURN n.title AS name" ); - + + "MATCH (m :Movie)\n" + + "RETURN p.Title AS name\n" ); - containsRows( res, true, false, + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Hans" ) ), - Row.of( TestLiteral.from( "Kira" ) )); + Row.of( TestLiteral.from( "Wall Street" )) ); + } + @Test + public void NullPropertiesDistinctUnionTest() + { + execute( SINGLE_NODE_PERSON_COMPLEX_1); + execute( SINGLE_NODE_PERSON_COMPLEX_1); + execute( SINGLE_NODE_MOVIE); + + GraphResult res = execute( "MATCH (p:Person)\n" + + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" + + "UNION DISTINCT \n" + + "MATCH (m:Movie)\n" + + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n"); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ) , TestLiteral.from( 45 ) , TestLiteral.from( null ),TestLiteral.from( null )), + Row.of( TestLiteral.from( null ),TestLiteral.from( null ),TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 )) ); } } From 33ab98691d714e29320490831b42c97df8b4d890 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 28 Jul 2024 23:34:56 +0300 Subject: [PATCH 26/55] Add test coverage for Call SubQueries --- .../cypher/Subqueries/CallSubqueriesTest.java | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java new file mode 100644 index 0000000000..b49ce5fd82 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java @@ -0,0 +1,184 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Subqueries; + +import com.google.common.util.concurrent.AbstractScheduledService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.util.Pair; +import org.polypheny.db.webui.models.results.GraphResult; +import java.util.List; +import java.util.Map; + +public class CallSubqueriesTest extends CypherTestTemplate { + + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void simpleCallTest() { + + GraphResult res = execute( " CALL { RETURN 'hello' AS innerReturn} \n" + + "RETURN innerReturn" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "hello" ) ) ); + } + + + @Test + public void repeatCallTest() { + GraphResult res = execute( "UNWIND [0, 1, 2] AS x\n" + + "CALL { RETURN 'hello' AS innerReturn }\n" + + "RETURN innerReturn" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "hello" ) ), + Row.of( TestLiteral.from( "hello" ) ), + Row.of( TestLiteral.from( "hello" ) ) ); + } + + + @Test + public void unwindVariablesAsInputsIntoCallTest() { + GraphResult res = execute( "UNWIND [0, 1, 2] AS x\n" + + "CALL { WITH x RETURN x * 10 AS y }\n" + + "RETURN x, y" ); + + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 0 ), TestLiteral.from( 0 ) ), + Row.of( TestLiteral.from( 1 ), TestLiteral.from( 10 ) ), + Row.of( TestLiteral.from( 2 ), TestLiteral.from( 20 ) ) ); + } + + + @Test + public void returnMatchNodesCallTest() { + execute( SINGLE_NODE_PERSON_1 ); + GraphResult res = execute( "CALL { MATCH (p:Person) RETURN p} RETURN p " ); + assert containsRows( res, true, true, Row.of( MAX ) ); + + } + + + @Test + public void countNodesCallTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "CALL {\n" + + " MATCH (p)\n" + + " RETURN count(p) AS totalPeople}\n" + + "RETURN totalPeople\n" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + + } + + + @Test + public void countRelationshipsCallTest() { + execute( SINGLE_EDGE_1 ); + execute( SINGLE_EDGE_2 ); + GraphResult res = execute( "CALL {\n" + + " MATCH ()-[r]->()\n" + + " RETURN count(r) AS totalRelationships }\n" + + "RETURN totalRelationships\n" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + + } + + + @Test + public void useMatchedNodesAsInputsIntoCallTest() { + execute( SINGLE_EDGE_2 ); + + GraphResult res = execute( "MATCH (p:Person)\n" + + "CALL {\n" + + " WITH p\n" + + " MATCH (p)-[:KNOWS]-(c:Person)\n" + + " RETURN c.name AS friend\n" + + "}\n" + + "RETURN p.name, friend" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Hans" ) ) ); + } + + + @Test + public void FilterMatchedNodesByOutputOfCallTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "CALL {\n" + + " MATCH (p:Person { name: 'Bob' })\n" + + " RETURN p.age AS age}\n" + + "MATCH (p:Person)\n" + + "WHERE p.age > age\n" + + "RETURN p\n" ); + + assert res.getData().length == 2; + assert containsNodes( res, true, + TestNode.from( List.of( "Person" ), Pair.of( "name", "Ann" ) ), + TestNode.from( List.of( "Person" ), Pair.of( "name", "Alex" ) ) ); + + } + + + @Test + public void UnionCallTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "CALL { MATCH (p:Person)\n" + + " RETURN p\n" + + "UNION\n" + + " MATCH (p:Person)\n" + + " RETURN p\n" + + "}\n" + + "RETURN p.name, p.age" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ) ) ); + } + + + @Test + public void unitSubQueryCallTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (p:Person) CALL { \n" + + "WITH p\n" + + " CREATE (:Person {name: p.name}) \n" + + "} RETURN count(*)" ); + //the number of rows present after the subquery is the same as was going into the subquery + assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + } + + +} From 4b3164f31ed6202e32a6d7c1a2b5eb1799303078 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 30 Jul 2024 02:52:53 +0300 Subject: [PATCH 27/55] Add test coverage for Collect SubQueries --- .../db/cypher/Functions/AggregateTest.java | 28 ++-- .../Subqueries/CollectSubQueriesTest.java | 157 ++++++++++++++++++ 2 files changed, 175 insertions(+), 10 deletions(-) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java index b460d244b3..bfb117ca11 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java @@ -23,6 +23,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; import java.util.Arrays; +import java.util.List; public class AggregateTest extends CypherTestTemplate { @@ -141,7 +142,7 @@ public void countDistinctFunctionTest() { execute(SINGLE_NODE_PERSON_1); - GraphResult res = execute("MATCH (n) RETURN count(DISTINCT n.name)"); + GraphResult res = execute("MATCH (n) RETURN COUNT(DISTINCT n.name)"); assert containsRows(res, true, false, Row.of(TestLiteral.from(1))); @@ -159,9 +160,8 @@ public void singleAvgAggregateTest() { execute( SINGLE_EDGE_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - GraphResult res = execute( "MATCH (n) RETURN avg(n.age)" ); + GraphResult res = execute( "MATCH (n) RETURN AVG(n.age)" ); // Printing the data using Arrays.deepToString - System.out.print( "Alyaa :" ); String[][] data = res.getData(); System.out.println( Arrays.deepToString(data)); assert containsRows( res, true, false, @@ -173,7 +173,7 @@ assert containsRows( res, true, false, public void avgNullAggregateTest() { execute(SINGLE_NODE_PERSON_1); execute(SINGLE_NODE_PERSON_2); - GraphResult res = execute("MATCH (p:Person) RETURN avg(p.age)"); + GraphResult res = execute("MATCH (p:Person) RETURN AVG(p.age)"); assert containsRows(res, true, false, Row.of(TestLiteral.from(null))); } @@ -184,7 +184,7 @@ public void avgRenameAggregationTest() { execute(SINGLE_NODE_PERSON_COMPLEX_1); execute(SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN avg(p.age) AS ages"); + GraphResult res = execute("MATCH (p:Person) RETURN AVG(p.age) AS ages"); assert containsRows(res, true, false, Row.of(TestLiteral.from(38))); } @Test @@ -196,7 +196,7 @@ public void avgRenameFieldAggregationTest() { execute(SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute("MATCH (p:Person) RETURN p.depno As depNumber , avg(p.age) As avgAge"); + GraphResult res = execute("MATCH (p:Person) RETURN p.depno As depNumber , AVG(p.age) As avgAge"); containsRows(res, true, false, Row.of(TestLiteral.from(13) , TestLiteral.from( 38 )), Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) )); @@ -207,14 +207,18 @@ public void singleCollectAggregationTest() { execute(SINGLE_NODE_PERSON_COMPLEX_1); execute(SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN collect(p.age) "); + GraphResult res = execute("MATCH (p:Person) RETURN COLLECT(p.age) "); + assert containsRows( res , true , false , Row.of( TestLiteral.from( List.of(45,31)) ) ); + } @Test public void collectRenameAggregationTest() { execute(SINGLE_NODE_PERSON_COMPLEX_1); execute(SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN collect(p.age) AS ages"); + GraphResult res = execute("MATCH (p:Person) RETURN COLLECT(p.age) AS ages"); + assert containsRows( res , true , false , Row.of( TestLiteral.from( List.of(45,31)) ) ); + } @Test @@ -223,13 +227,17 @@ public void collectRenameFieldAggregationTest() { execute(SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute("MATCH (p:Person) RETURN collect(p.age) AS ages , p.depno AS depNumber"); + GraphResult res = execute("MATCH (p:Person) RETURN COLLECT(p.age) AS ages , p.depno AS depNumber"); + assert containsRows( res , true , false , + Row.of( TestLiteral.from( List.of(45 ,31)),TestLiteral.from( 13 ) ), + Row.of( TestLiteral.from( List.of(32)),TestLiteral.from( 14 ) )); } @Test public void collectNullAggregationTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN collect(p.age)"); + GraphResult res = execute("MATCH (p:Person) RETURN COLLECT(p.age)"); + assert containsRows( res , true , false , Row.of( TestLiteral.from( List.of(null,null)) ) ); } @Test public void singleMinMaxAggregateTest() { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java new file mode 100644 index 0000000000..f84d6f113d --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java @@ -0,0 +1,157 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Subqueries; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.util.Pair; +import org.polypheny.db.webui.models.results.GraphResult; +import java.util.List; + +public class CollectSubQueriesTest extends CypherTestTemplate { + + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10})"; + + + @Test + public void simpleCollectSubQueryTest() { + execute( SINGLE_EDGE_1 ); + + GraphResult res = execute( "MATCH (person:Person)\n" + + "WHERE 'Kira' IN COLLECT { MATCH (person)-[:OWNER_OF]->(a:Animal) RETURN a.name }\n" + + "RETURN person.name AS name" ); + + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ) ); + + } + + + @Test + public void useCollectSubQueryInReturnTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN person.name,\n" + + " COLLECT {\n" + + " MATCH (person)-[:OWNER_OF]->(d:Dog)\n" + + " RETURN d.name\n" + + " } as DogNames" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); + + } + + + @Test + public void whereWithCollectSubQueryTest() { + execute( EDGE_3 ); + GraphResult res = execute( "\n" + + "MATCH (person:Person)\n" + + "RETURN person.name as name, COLLECT {\n" + + " MATCH (person)-[r:OWNER_OF]->(a:Dog)\n" + + " WHERE a.age <= 3\n" + + " RETURN a.name\n" + + "} as youngDog \n" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); + + } + + + @Test + public void unionWithCollectSubQueryTest() { + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN\n" + + " person.name AS name,\n" + + " COLLECT {\n" + + " MATCH (person)-[:HAS_DOG]->(dog:Dog)\n" + + " RETURN dog.name AS petName\n" + + " UNION\n" + + " MATCH (person)-[:HAS_CAT]->(cat:Cat)\n" + + " RETURN cat.name AS petName\n" + + " } AS petNames" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( List.of( "Andy", "Mittens" ) ) ) ); + + + } + + + @Test + public void withClauseWithCollectSubQueryTest() { + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN person.name AS name, COLLECT {\n" + + " WITH 1999 AS yearOfTheDog\n" + + " MATCH (person)-[r:OWNER_OF]->(d:Dog)\n" + + " WHERE r.since = yearOfTheDog\n" + + " RETURN d.name\n" + + "} as dogsOfTheYear" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); + } + + + @Test + public void caseWithCollectSubQueryTest() { + execute( EDGE_3 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN\n" + + " CASE\n" + + " WHEN COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name } = [] THEN \" No Dogs \" + person.name\n" + + " ELSE person.name\n" + + " END AS result" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "No Dogs" ) ), + Row.of( TestLiteral.from( "Max" ) ) ); + + } + + + @Test + public void updateWithCollectSubQueryTest() { + execute( SINGLE_NODE_PERSON_2 ); + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)" + + " WHERE person.name = \"Hans\"\n" + + "SET person.dogNames = COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name }\n" + + "RETURN person.dogNames as dogNames" ); + + assert containsRows( res , true , false , + Row.of( TestLiteral.from( List.of("Andy") ) ) ); + } + + + +} From 64a8c0e3e055966d7501fdd57a783c7c4b3ec773 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 30 Jul 2024 04:30:08 +0300 Subject: [PATCH 28/55] Add test coverage for Count SubQueries --- .../Subqueries/CountSubQueriesTest.java | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java new file mode 100644 index 0000000000..972ca9f1dc --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java @@ -0,0 +1,149 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Subqueries; + +import org.bouncycastle.crypto.modes.G3413CBCBlockCipher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class CountSubQueriesTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10})"; + + + @Test + public void simpleCountSubQueryTest() { + execute( SINGLE_NODE_PERSON_2 ); + execute( EDGE_3 ); + + GraphResult res = execute( "MATCH (person:Person)\n" + + "WHERE COUNT { (person)-[r:OWNER_OF]->(:Animal) } > 1\n" + + "RETURN person.name AS name" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ) ); + } + + + @Test + public void useCountSubQueryInReturnTest() { + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN person.name, COUNT { (person)-[:OWNER_OF]->(:Dog) } as howManyDogs" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 1 ) ) ); + + } + + + @Test + public void whereWithCountSubQueryTest() { + execute( SINGLE_NODE_PERSON_2 ); + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "WHERE COUNT {\n" + + " (person)-[r:OWNER_OF]->(dog:Dog)\n" + + " WHERE person.name = dog.name } = 1\n" + + "RETURN person.name AS name" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ) ); + } + + + @Test + public void UnionWithCountSubQueryTest() { + execute( EDGE_3 ); + + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN\n" + + " person.name AS name,\n" + + " COUNT {\n" + + " MATCH (person)-[:OWNER_OF]->(dog:Dog)\n" + + " RETURN dog.name AS petName\n" + + " UNION\n" + + " MATCH (person)-[:OWNER_OF]->(cat:Cat)\n" + + " RETURN cat.name AS petName\n" + + " } AS numPets" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 2 ) ) ); + } + + + @Test + public void WithClauseWithCountSubQueryTest() { + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "WHERE COUNT {\n" + + " WITH \"Andy\" AS dogName\n" + + " MATCH (person)-[:OWNER_OF]->(d:Dog)\n" + + " WHERE d.name = dogName\n" + + "} = 1\n" + + "RETURN person.name AS name" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ) ); + + } + + + @Test + public void UpdateWithCountSubQueryTest() { + execute( EDGE_3 ); + + GraphResult res = execute( "MATCH (person:Person) WHERE person.name =\"Max\"\n" + + "SET person.howManyDogs = COUNT { (person)-[:OWNER_OF]->(:Dog) }\n" + + "RETURN person.howManyDogs as howManyDogs" ); + + assert containsRows( res, true, false, Row.of( + TestLiteral.from( 1 ) ) ); + + + } + + + @Test + public void CaseWithCountSubQueryTest() { + execute( EDGE_3 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN\n" + + " CASE\n" + + " WHEN COUNT { (person)-[:OWNER_OF]->(:Dog) } >= 1 THEN \"DogLover \" + person.name\n" + + " ELSE person.name\n" + + " END AS result" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "DogLover" ) ), + Row.of( TestLiteral.from( "Hans" ) ) ); + + + } + + +} From c5f7670510d45957c24c428abb1b2f02088c6380 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 30 Jul 2024 04:32:33 +0300 Subject: [PATCH 29/55] Add changes for Count SubQueries --- .../db/cypher/Subqueries/CountSubQueriesTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java index 972ca9f1dc..d029062b4d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java @@ -77,7 +77,7 @@ assert containsRows( res, true, false, @Test - public void UnionWithCountSubQueryTest() { + public void unionWithCountSubQueryTest() { execute( EDGE_3 ); GraphResult res = execute( "MATCH (person:Person)\n" @@ -97,7 +97,7 @@ assert containsRows( res, true, false, @Test - public void WithClauseWithCountSubQueryTest() { + public void withClauseWithCountSubQueryTest() { execute( EDGE_3 ); GraphResult res = execute( "MATCH (person:Person)\n" + "WHERE COUNT {\n" @@ -114,7 +114,7 @@ assert containsRows( res, true, false, @Test - public void UpdateWithCountSubQueryTest() { + public void updateWithCountSubQueryTest() { execute( EDGE_3 ); GraphResult res = execute( "MATCH (person:Person) WHERE person.name =\"Max\"\n" @@ -129,7 +129,7 @@ assert containsRows( res, true, false, Row.of( @Test - public void CaseWithCountSubQueryTest() { + public void caseWithCountSubQueryTest() { execute( EDGE_3 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (person:Person)\n" From c3520a2fd7780e7bb86573712c2aba781fe07c8c Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 30 Jul 2024 20:02:58 +0300 Subject: [PATCH 30/55] Add changes for Exists SubQueries --- .../Subqueries/ExistsSubQueriesTest.java | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java new file mode 100644 index 0000000000..95f68493c8 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java @@ -0,0 +1,140 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Subqueries; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class ExistsSubQueriesTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10}),(d)-[:HAS_TOY]->(:Toy{name:'Banana'})"; + + + @Test + public void simpleExistsSubQueryTest() { + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "WHERE EXISTS {\n" + + " (person)-[:OWNER_OF]->(:Dog)\n" + + "}\n" + + "RETURN person.name AS name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); + execute( EDGE_3 ); + execute( "MATCH (person:Person)\n" + + "WHERE EXISTS {\n" + + " (person)-[:OWNER_OF]->(:Dog)\n" + + "}\n" + + "RETURN person.name AS name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + } + + + @Test + public void whereWithExistsSubQueryTest() { + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "WHERE EXISTS {\n" + + " MATCH (person)-[:OWNER_OF]->(dog:Dog)\n" + + " WHERE person.name = \"Max\" \n" + + "}\n" + + "RETURN dog.name AS name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Andy" ) ) ); + + } + + + @Test + public void nestedExistsSubQueryTest() { + + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "WHERE EXISTS {\n" + + " MATCH (person)-[:OWNER_OF]->(dog:Dog)\n" + + " WHERE EXISTS {\n" + + " MATCH (dog)-[:HAS_TOY]->(toy:Toy)\n" + + " WHERE toy.name = 'Banana'\n" + + " }\n" + + "}\n" + + "RETURN person.name AS name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + + + } + + + @Test + public void returnExistsSubQueryTest() { + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN person.name AS name, EXISTS {\n" + + " MATCH (person)-[:OWNER_OF]->(:Dog)\n" + + "} AS hasDog" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( true ) ) ); + } + + + @Test + public void unionWithExistsSubQueryTest() { + execute( EDGE_3 ); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (person:Person)\n" + + "RETURN\n" + + " person.name AS name,\n" + + " EXISTS {\n" + + " MATCH (person)-[:HAS_DOG]->(:Dog)\n" + + " UNION\n" + + " MATCH (person)-[:HAS_CAT]->(:Cat)\n" + + " } AS hasPet" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( true ) ), + Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( false ) ) ); + } + + + @Test + public void withClauseWithExistsSubQueryTest() { + execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person {name: name})\n" + + "WHERE EXISTS {\n" + + " WITH \"Andy\" AS name\n" + + " MATCH (person)-[:OWNER_OF]->(d:Dog)\n" + + " WHERE d.name = name\n" + + "}\n" + + "RETURN person.name AS name" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ) ); + } + + +} From c96c3581dfda7fd0ad103d957fc38f76181e7153 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Wed, 31 Jul 2024 02:19:20 +0300 Subject: [PATCH 31/55] Add test coverage for foreach clause --- .../db/cypher/clause/write/ForeachTest.java | 92 ++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java index 799f52c8eb..ce5ced63aa 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java @@ -19,8 +19,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.cypher.helper.TestNode; +import org.polypheny.db.util.Pair; +import org.polypheny.db.webui.models.results.GraphResult; +import java.util.List; + +public class ForeachTest extends CypherTestTemplate { -public class ForeachTest extends CypherTestTemplate { @BeforeEach public void reset() { tearDown(); @@ -28,5 +34,89 @@ public void reset() { } + @Test + public void createWithForeachTest() { + execute( "WITH ['Alice', 'Bob', 'Charlie'] AS names\n" + + "FOREACH (name IN names |\n" + + " CREATE (p:Person {name: name})\n" + + ")" ); + + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 3; + assert containsNodes( res, true, + TestNode.from( Pair.of( "name", "Alice" ) ), + TestNode.from( Pair.of( "name", "Bob" ) ), + TestNode.from( Pair.of( "name", "Charlie" ) ) ); + + + } + + + @Test + public void mergeWithForeachTest() { + execute( "WITH ['Alice', 'Bob', 'Charlie'] AS names\n" + + "FOREACH (name IN names |\n" + + " MERGE (p:Person {name: name})\n" + + ")" ); + + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 3; + assert containsNodes( res, true, + TestNode.from( Pair.of( "name", "Alice" ) ), + TestNode.from( Pair.of( "name", "Bob" ) ), + TestNode.from( Pair.of( "name", "Charlie" ) ) ); + + } + + + @Test + public void deleteWithForeachTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + execute( "MATCH (p:Person)\n" + + "WITH collect(p) AS people\n" + + "FOREACH (p IN people |\n" + + " DELETE p\n" + + ")" ); + GraphResult res = matchAndReturnAllNodes(); + assertEmpty( res ); + + } + + + @Test + public void removeWithForeachTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + execute( "MATCH (p:Person)\n" + + "WITH collect(p) AS people\n" + + "FOREACH (p IN people |\n" + + " REMOVE p.name \n" + + ")" ); + + GraphResult res = matchAndReturnAllNodes(); + assert containsRows( res, true, false, Row.of( TestLiteral.from( null ) ), + Row.of( TestLiteral.from( null ) ) ); + + } + + + @Test + public void updateWithForeachTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( "MATCH (p:Person)\n" + + "WITH collect(p) AS people\n" + + "FOREACH (p IN people |\n" + + " SET p.status = 'active'\n" + + ")" ); + + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, + TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ), Pair.of( "status", "active" ) ), + TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "status", "active" ) ) ); + } } From 2d073db7d6dc981944440b931c6b589c09f25c17 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Wed, 31 Jul 2024 02:32:22 +0300 Subject: [PATCH 32/55] Add test coverage for foreach clause --- .../db/cypher/clause/write/ForeachTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java index ce5ced63aa..9df533c82a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java @@ -119,4 +119,22 @@ assert containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "status", "active" ) ) ); } + + @Test + public void nestedForeachTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( "MATCH (p:Person)\n" + + "WITH collect(p) AS people\n" + + "FOREACH (p1 IN people |\n" + + " FOREACH (p2 IN people |\n" + + " CREATE (p1)-[:KNOWS]->(p2)\n" + + " )\n" + + ")" ); + GraphResult res = execute( "MATCH (p1)-[r:KNOWS]->(p2) RETURN r" ); + assert res.getData().length == 4; + res = execute( "MATCH (p1)-[r:KNOWS]-(p2) RETURN r" ); + assert res.getData().length == 6; + } + } From 8e051789c2a99282939f052d266daff0371c1a88 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 4 Aug 2024 03:37:33 +0300 Subject: [PATCH 33/55] Add test coverage for Operators ( boolean - comparison - string ) --- .../db/cypher/Operators/BooleanOperators.java | 76 ++++++++++++++++ .../Operators/ComparisonOperations.java | 86 +++++++++++++++++++ .../db/cypher/Operators/StringOperators.java | 42 +++++++++ 3 files changed, 204 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java new file mode 100644 index 0000000000..58f015c176 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java @@ -0,0 +1,76 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Operators; + +import net.bytebuddy.description.type.TypeList.Generic; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class BooleanOperators extends CypherTestTemplate { + @BeforeEach + public void setUp() { + tearDown(); + createGraph(); + } + + @Test + public void conjunctionOperatorTest() + { + GraphResult res = execute( "WITH true as a , false as b RETURN a AND b " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from( false ) ) ); + res = execute( "WITH true as a , true as b RETURN a AND b " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from(true ) ) ); + + } + + @Test + public void disjunctionOperatorTest() + { + GraphResult res = execute( "WITH true as a , false as b RETURN a OR b " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from( true ) ) ); + res = execute( "WITH false as a , false as b RETURN a OR b " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from(false ) ) ); + + } + + @Test + public void exclusiveDisjunctionOperatorTest() + { + GraphResult res = execute( "WITH true as a , false as b RETURN a XOR b " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from( true ) ) ); + res = execute( "WITH true as a , true as b RETURN a XOR b " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from(false ) ) ); + res = execute( "WITH false as a , false as b RETURN a XOR b " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from(true ) ) ); + + } + + @Test + public void negationOperatorTest() + { + GraphResult res = execute( "WITH true as a RETURN NOT a " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from(false ) ) ); + + res = execute( "WITH false as a RETURN NOT a " ); + assert containsRows( res , true , false , Row.of( TestLiteral.from(true ) ) ); + + } + +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java new file mode 100644 index 0000000000..2e9077dfcf --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java @@ -0,0 +1,86 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Operators; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class ComparisonOperations extends CypherTestTemplate { + @BeforeEach + public void setUp() { + tearDown(); + createGraph(); + } + + + @Test + public void IsNullOperatorTest() { + GraphResult res = execute( "Return null is not null as Result" ); + assert containsRows( res ,true , false ,Row.of( TestLiteral.from( false ) ) ); + } + + @Test + public void IsNotNullFunction() { + GraphResult res = execute( "Return null is null as Result" ); + assert containsRows( res ,true , false ,Row.of( TestLiteral.from( true ) ) ); + + } + + @Test + public void greaterThanOperatorTest() + { + GraphResult res = execute( "Return 1 > 2 as result " ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + } + + @Test + public void smallerThanOperatorTest() + { + GraphResult res = execute( "Return 1 < 2 as result " ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( true) ) ); + } + @Test + public void greaterThanOrEqualOperatorTest() + { + GraphResult res = execute( "Return 1 >= 2 as result " ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + } + @Test + public void smallerThanOrEqualOperatorTest() + { + GraphResult res = execute( "Return 1 <= 2 as result " ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( true ) ) ); + } + + @Test + public void equalityOperatorTest() + { + GraphResult res = execute( "Return 2 = 2 as result " ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( true ) ) ); + } + + @Test + public void inequalityOperatorTest() + { + GraphResult res = execute( "Return 1 <> 2 as result " ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + } + +} diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java new file mode 100644 index 0000000000..e14ae6ee47 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java @@ -0,0 +1,42 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Operators; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class StringOperators extends CypherTestTemplate { + + + @BeforeEach + public void setUp() { + tearDown(); + createGraph(); + } + + @Test + public void concatenateWithPlusOperatorTest() { + GraphResult res = execute("RETURN 'neo' + '4j' AS result"); + assert containsRows(res, true, true, Row.of( TestLiteral.from("neo4j"))); + } + + + +} From d3fabdc2df26ff77784fe78bfaf55ac2910a627d Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Mon, 5 Aug 2024 00:27:26 +0300 Subject: [PATCH 34/55] Add more test coverage for TemporalFun ( Date - time Date - time - Duration) --- .../db/cypher/Functions/TemporalFunTest.java | 173 +++++++++++++++++- 1 file changed, 166 insertions(+), 7 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java index fd14452f51..ae26c166d6 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; public class TemporalFunTest extends CypherTestTemplate { @@ -31,42 +32,200 @@ public void reset() { @Test - public void dateFunTest() { + public void stringIntoDateFunTest() { - GraphResult res = execute( "RETURN DATE('2023-05-18')\n" ); + GraphResult res = execute( "RETURN date('2015-07-21')\n" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); + res = execute( "RETURN date('2015-07')" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); + res = execute( "RETURN date('201507')" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); + + res = execute( "RETURN date('2015-W30-2')" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); + + res = execute( "RETURN date('2015')" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01" ) ) ); + } + + + @Test + public void yearMonthDayDateFunTest() { + GraphResult res = execute( "RETURN date({year: 1984, month: 10, day: 11})" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "1984-10-11" ) ) ); + + res = execute( "RETURN date({year: 1984, month: 10})" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "1984-10-01" ) ) ); + + res = execute( "RETURN date({year: 1984})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-01-01" ) ) ); + } + + + @Test + public void yearWeekDayDateFunTest() { + GraphResult res = execute( "RETURN date({year: 1984, week: 10, dayOfWeek: 3})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07" ) ) ); + } + + + @Test + public void yearQuarterDayDateFunTest() { + GraphResult res = execute( "RETURN date({year: 1984, quarter: 3, dayOfQuarter: 45})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14" ) ) ); + } + + + @Test + public void yearMonthDayZonedTimeDateFunTest() { + + GraphResult res = execute( "RETURN datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 123, microsecond: 456, nanosecond: 789}) AS theDate" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.123456789Z" ) ) ); + + res = execute( "datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 645, timezone: '+01:00'})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.645+01:00" ) ) ); + + res = execute( "RETURN datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14Z" ) ) ); + + + } + + + @Test + public void yearWeekDayTimeDateFunTest() { + GraphResult res = execute( "RETURN datetime({year: 1984, week: 10, dayOfWeek: 3, hour: 12, minute: 31, second: 14, millisecond: 645})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07T12:31:14.645Z" ) ) ); } + @Test + public void yearQuarterDayTimeDateFunTest() { + GraphResult res = execute( "RETURN datetime({year: 1984, quarter: 3, dayOfQuarter: 45, hour: 12, minute: 31, second: 14, microsecond: 645876})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14T12:31:14.645876Z" ) ) ); + } + + + @Test + public void stringIntoTimeDateFunTest() { + GraphResult res = execute( "RETURN datetime('2015-07-21T21:40:32.142+0100')" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142+01:00" ) ) ); + res = execute( "RETURN datetime('2015-W30-2T214032.142Z')" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142Z" ) ) ); + + res = execute( "RETURN datetime('2015T214032-0100')" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01T21:40:32-01:00" ) ) ); + + res = execute( "RETURN datetime('20150721T21:40-01:30')" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40-01:30" ) ) ); + + res = execute( "RETURN datetime('2015-07-21T21:40:32.142[Europe/London]')" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "datetime('2015-07-21T21:40:32.142[Europe/London]')" ) ) ); + + } @Test public void timeFunTest() { - GraphResult res = execute( "RETURN TIME('12:34:56')" ); + GraphResult res = execute( "RETURN time({hour: 12, minute: 31, second: 14, millisecond: 123, microsecond: 456, nanosecond: 789})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.123456789Z" ) ) ); + res = execute( "RETURN time({hour: 12, minute: 31, second: 14, nanosecond: 645876123})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876123Z" ) ) ); + + res = execute( "RETURN time({hour: 12, minute: 31, second: 14, microsecond: 645876, timezone: '+01:00'})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876000+01:00" ) ) ); + + res = execute( "time({hour: 12, minute: 31, timezone: '+01:00'})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:00+01:00" ) ) ); + + res = execute( "RETURN time({hour: 12, timezone: '+01:00'})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:00:00+01:00" ) ) ); } @Test - public void dateTimeFunTest() { + public void stringIntoTimeFunTest() { + GraphResult res = execute( "RETURN time('21:40:32.142+0100')" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000+01:00" ) ) ); + + res = execute( "RETURN time('214032.142Z')" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000Z" ) ) ); + + res = execute( "RETURN time('21:40:32+01:00')" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32+01:00" ) ) ); - GraphResult res = execute( "RETURN DATETIME('2023-05-18T12:34:56')" ); + res = execute( "RETURN time('214032-0100')" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32-01:00" ) ) ); } @Test - public void durationBetweenFunTest() { + public void durationFunTest() { + + GraphResult res = execute( "RETURN duration({days: 14, hours:16, minutes: 12})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); + + res = execute( "RETURN duration({months: 5, days: 1.5})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); + + res = execute( "RETURN duration({months: 0.75})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); - GraphResult res = execute( "RETURN duration.between(DATE('2023-05-18'), DATE('2023-06-18'))" ); + res = execute( "RETURN duration({weeks: 2.5})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P17DT12H" ) ) ); + + res = execute( "RETURN duration({minutes: 1.5, seconds: 1, milliseconds: 123, microseconds: 456, nanoseconds: 789})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); + + res = execute( "RETURN duration({minutes: 1.5, seconds: 1, nanoseconds: 123456789})" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); } + @Test + public void stringIntoDurationFunTest() { + GraphResult res = execute( "RETURN duration(\"P14DT16H12M\") " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); + res = execute( "RETURN duration(\"P5M1.5D\")" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); + + res = execute( "RETURN duration(\"P0.75M\") " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); + + res = execute( "RETURN duration(\"PT0.75M\")" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "PT45S" ) ) ); + + res = execute( "RETURN duration(\"P2012-02-02T14:37:21.545\")" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P2012Y2M2DT14H37M21.545S" ) ) ); + + + } + + + @Test + public void durationBetweenFunTest() { + GraphResult res = execute( "RETURN duration.between(date('1984-10-11'), date('2015-06-24')) AS theDuration" ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( "P30Y8M13D" ) ) ); + } + + + } From a23b57a1bfe9230293ac3b1a6640a3465603702f Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Mon, 5 Aug 2024 02:01:28 +0300 Subject: [PATCH 35/55] Add more test coverage for Mathematical Operators --- .../Operators/MathematicalOperators.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java new file mode 100644 index 0000000000..75d0cf6103 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java @@ -0,0 +1,88 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Operators; + +import javassist.bytecode.CodeIterator.Gap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; + +public class MathematicalOperators extends CypherTestTemplate { + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + @Test + public void additionOperator () + { + GraphResult res = execute( "RETURN 2 + 3" ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( 5 ) ) ); + } + + @Test + public void minisOperatorTest() + { + GraphResult res = execute( "RETURN 3 - 2" ); + + assert containsRows( res , true , false , Row.of( TestLiteral.from( 1) ) ); + + } + + + + + @Test + public void multiplicationOperatorTest() + { + GraphResult res = execute( "RETURN 2 * 3" ); + + assert containsRows( res , true , false ,Row.of( TestLiteral.from( 6 ) ) ); + } + + @Test + public void divisionOperatorTest() + { + GraphResult res = execute( "RETURN 6 / 3 " ); + + assert containsRows( res , true , false ,Row.of( TestLiteral.from( 2 ) ) ); + } + + + @Test + public void moduleOperatorTest() + { + GraphResult res = execute( "RETURN 3 % 2 " ); + assert containsRows( res , true ,false ,Row.of( TestLiteral.from( 1 ) ) ); + + } + + @Test + public void exponentiationOperator() + { + GraphResult res = execute( "RETURN 2 ^ 3" ); + + assert containsRows( res , true ,false , Row.of( TestLiteral.from( 8.0) ) ); + } + + + + +} From 612de00377055e5a5179cd80f6325f79ddbac263 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 6 Aug 2024 01:11:19 +0300 Subject: [PATCH 36/55] Add more test coverage for more functions (nodes , relationships , labels ) --- .../db/cypher/Functions/OtherFunTest.java | 109 ++++++++++-------- 1 file changed, 63 insertions(+), 46 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java index eca5e3d731..ce50b2b74f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java @@ -20,8 +20,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.List; public class OtherFunTest extends CypherTestTemplate { @@ -30,8 +32,9 @@ public void reset() { tearDown(); createGraph(); } - - + ////////////////////////// + /// Scalar Functions + /////////////////////////// @Test public void typeFunTest() { execute( SINGLE_EDGE_1 ); @@ -49,10 +52,40 @@ public void idFunTest() { GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" + "RETURN ID(p)\n" ); -// containsRows( res, true, true, Row.of( TestLiteral.from( ) ) ); } + @Test + public void testCoalesceFunTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + GraphResult result = execute( "MATCH (p) RETURN p.name, coalesce(p.age, 0) AS age" ); + + assert containsRows( result, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 0 ) ), + Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 0 ) ), + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); + } + + + @Test + public void testDefaultValuesWithCoalesceFunTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + GraphResult result = execute( "MATCH (p) RETURN p.name, coalesce(p.age, 'unknown') AS age" ); + + assertNode( result, 0 ); + + assert containsRows( result, true, false, + Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "unknown" ) ), + Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( "unknown" ) ), + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( "unknown" ) ) ); + } + /////////////////////////////// + // Predicate Functions + ///////////////////////////// @Test public void ExistFunTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -68,61 +101,45 @@ public void ExistFunTest() { } - + /////////////////////////// + //// List Functions + /////////////////////////// @Test - public void testCoalesceFunction() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_PERSON_COMPLEX_1); - GraphResult result = execute("MATCH (p) RETURN p.name, coalesce(p.age, 0) AS age"); - + public void returnLabelsFunTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (a)" + + "RETURN labels(a)" ); - assert containsRows(result, true, false, - Row.of(TestLiteral.from( "Max" ) ,TestLiteral.from( 0 )), - Row.of(TestLiteral.from( "Hans" ) , TestLiteral.from( 0 )), - Row.of(TestLiteral.from( "Ann" ),TestLiteral.from( 45 ))); + assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Person" ) ) ) ); } @Test - public void testIsNullFunction() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_PERSON_COMPLEX_1); - GraphResult result = execute("MATCH (p) WHERE p.age IS NULL RETURN p"); - - assertNode(result, 0); + public void returnNodesFunTest() + { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + + "RETURN nodes(p)" ); + assert res.getData().length == 1; + assert containsRows( res , true , false ,Row.of( TestLiteral.from( List.of(MAX ,KIRA ) ) ) ); - assert containsRows(result, true, false, - Row.of(HANS), - Row.of(MAX)); } @Test - public void testIsNotNullFunction() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_ANIMAL); - GraphResult result = execute("MATCH (p) WHERE p.type IS NOT NULL RETURN p"); - - assertNode(result, 0); - - assert containsRows(result, true, false, - Row.of( KIRA) ); + public void returnRelationsFunTest() + { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + + "RETURN relationships(p)" ); + assert res.getData().length == 1 ; } @Test - public void testDefaultValuesWithCoalesce() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_PERSON_COMPLEX_1); - GraphResult result = execute("MATCH (p) RETURN p.name, coalesce(p.age, 'unknown') AS age"); - - assertNode(result, 0); - - assert containsRows(result, true, false, - Row.of(TestLiteral.from( "Max" ) ,TestLiteral.from( "unknown")), - Row.of(TestLiteral.from( "Hans" ) , TestLiteral.from("unknown" )), - Row.of(TestLiteral.from( "Ann" ),TestLiteral.from( "unknown" ))); + public void returnRelationAndNodesFunTest() + { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + + "RETURN relationships(p) , nodes(p)" ); + assert res.getData().length == 1 ; } From 01b0c89aecfba23833e15116b06c3d2a8376362e Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 6 Aug 2024 01:11:42 +0300 Subject: [PATCH 37/55] Add more test coverage for limit clause --- .../db/cypher/clause/general/LimitTest.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java index 90513699ae..de8ce73628 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java @@ -48,6 +48,28 @@ public void simpleLimitTest() { } + @Test + public void InsertNodeLimitTest() { + GraphResult res = execute( "CREATE (n:person)\n" + + "RETURN n\n" + + "LIMIT 0" ); + + assert res.getData().length == 0; + res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + } + + + @Test + public void updateNodeLimitTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + GraphResult res = execute( "MATCH (n {name: 'MAX'})\n" + + "SET n.age = 60\n" + + "RETURN n\n" + + "LIMIT 0" ); + } + + @Test public void orderByLimitTest() { execute( SINGLE_NODE_ANIMAL ); @@ -91,11 +113,25 @@ public void withAndOrderByLimitTest() { assert res.getData().length == 1; assert containsNodes( res, true, - TestNode.from( Pair.of( "name" , "Ann" ) , - Pair.of( "age" , 45 ) , - Pair.of( "depno" , 13 )) ); + TestNode.from( Pair.of( "name", "Ann" ), + Pair.of( "age", 45 ), + Pair.of( "depno", 13 ) ) ); + + + } + + @Test + public void numberOfUpdatesLimitTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + + GraphResult res = execute( "MATCH (n)\n" + + "WITH n ORDER BY n.name LIMIT 1\n" + + "SET n.locked = true\n" + + "RETURN n.name" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } From b4f9a13063c3c95d1984335d5a1c024c31bdfd6b Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 6 Aug 2024 01:12:15 +0300 Subject: [PATCH 38/55] Add more test coverage for list Operators --- .../db/cypher/Operators/ListOperators.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java new file mode 100644 index 0000000000..fd0e42e097 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java @@ -0,0 +1,54 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Operators; + +import javassist.bytecode.CodeIterator.Gap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class ListOperators extends CypherTestTemplate { + @BeforeEach + public void setUp() { + tearDown(); + createGraph(); + } + + @Test + public void checkIfNumberInListOperatorTest() + { + GraphResult res = execute( "RETURN 1 IN [ 1 ,2 ]" ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( true ) ) ); + + res = execute( "RETURN 3 IN [ 1 ,2 ]" ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + } + @Test + public void checkIfListInListOperatorTest() + { + GraphResult res = execute( "RETURN [2, 1] IN [1, [2, 1], 3] " ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( true ) ) ); + + res = execute( "RETURN [1, 2] IN [1, 2] " ); + assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + } + + + +} From b26170917ae7b53c230c688b33b47aa5054844ca Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 6 Aug 2024 01:12:38 +0300 Subject: [PATCH 39/55] Add more test coverage for where clause --- .../db/cypher/clause/general/FilterTest.java | 230 +++++++++++++++++- 1 file changed, 226 insertions(+), 4 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 3e2c8ca4be..7a6906c54c 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -21,6 +21,8 @@ import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.Arrays; +import java.util.List; public class FilterTest extends CypherTestTemplate { @@ -36,7 +38,22 @@ public void setUp() { @Test - public void simpleConditionFilterTest() { + public void nodeLabelFilterTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult res = execute( "MATCH (n)\n" + + "WHERE n:Person\n" + + "RETURN n.name, n.age" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ) ) ); + } + + + @Test + public void nodePropertyFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); GraphResult result = execute( "MATCH (p) WHERE p.age > 3 RETURN p" ); @@ -53,7 +70,76 @@ public void simpleConditionFilterTest() { @Test - public void multipleConditionsFilterTest() { + public void relationPropertyFilterTest() { + execute( SINGLE_EDGE_2 ); + GraphResult res = execute( "MATCH (n:Person)-[k:KNOWS]->(f)\n" + + "WHERE k.since < 1995\n" + + "RETURN f.name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + + } + + + @Test + public void NodePatternFilterTest() { + execute( SINGLE_EDGE_2 ); + + GraphResult res = execute( "MATCH (a:Person WHERE a.name = 'Max')-[:KNOWS]->(b:Person WHERE b.name = 'Hans')\n" + + "RETURN b.name" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + + } + + @Test + public void relationshipPatternFilterTest() + { + execute( SINGLE_EDGE_2 ); + + GraphResult res = execute( "MATCH (a:Person)-[r:KNOWS WHERE r.since < 2000 ]->(b:Person)\n" + + "RETURN r.since" ); + assert containsRows( res , true , false , Row.of( TestLiteral.from(1994 ) ) ); + } + + + @Test + public void propertyExistenceCheckFilterTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "WHERE n.age IS NOT NULL\n" + + "RETURN n.name, n.age" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); + } + @Test + public void propertyNonExistenceCheckFilterTest() + { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "WHERE n.age IS NULL\n" + + "RETURN n.name" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" )) ); + } + + + + @Test + public void rangeFilterTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (n) WHERE 21 < n.age <= 32 RETURN n.name" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Bob" ) ) ); + } + + + @Test + public void booleanConditionFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); @@ -69,6 +155,35 @@ assert containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ), } + @Test + public void multiBooleanOperatorsFilterTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "WHERE (n.name = 'Alex' XOR (n.age < 30 AND n.name = 'Bob')) OR NOT (n.name = 'Bob' OR n.name = 'Alex')\n" + + "RETURN\n" + + " n.name AS name,\n" + + " n.age AS age\n" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( 32 ) ), + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); + } + + + @Test + public void withFilterTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "WITH n.name as name\n" + + "WHERE n.age = 45\n" + + "RETURN name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); + } + + @Test public void existFilterTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -83,15 +198,43 @@ public void existFilterTest() { } + /////////////////////////////////// + ///// STRING matching + ///////////////////////////////////// @Test public void startWithFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_ANIMAL ); - GraphResult result = execute( "MATCH (p) WHERE p.name STARTS WITH 'M' RETURN p.name" ); + GraphResult res = execute( "MATCH (p) WHERE p.name STARTS WITH 'M' RETURN p.name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + + + } + - assert containsRows( result, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + @Test + public void endWithFilterTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (n)\n" + + "WHERE n.name ENDS WITH 's'\n" + + "RETURN n.name" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + + } + + + @Test + public void notEndWithFilterTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "WHERE NOT n.name ENDS WITH 's'\n" + + "RETURN n.name, n.age" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -107,4 +250,83 @@ public void containsFilterTest() { } + @Test + public void patternFilterTest() { + execute( SINGLE_EDGE_2 ); + GraphResult res = execute( "MATCH\n" + + " (p:Person {name: 'Max'}),\n" + + " (other:Person)\n" + + "WHERE (p)-->(other)\n" + + "RETURN other.name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + + res = execute( "MATCH\n" + + " (p:Person {name: 'Max'}),\n" + + " (other:Person)\n" + + "WHERE (p)--(other)\n" + + "RETURN other.name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + + res = execute( "MATCH\n" + + " (p:Person {name: 'Max'}),\n" + + " (other:Person)\n" + + "WHERE (p)<--(other)\n" + + "RETURN other.name" ); + assertEmpty( res ); + } + + + @Test + public void patternWithPropertiesFilterTest() { + execute( SINGLE_EDGE_2 ); + GraphResult res = execute( "MATCH (other:Person)\n" + + "WHERE (other)-[:KNOWS]-({name: 'Hans'})\n" + + "RETURN other.name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + } + + + @Test + public void listComprehensionFilterTest() { + execute( SINGLE_EDGE_2 ); + GraphResult res = execute( "MATCH (a:Person {name: 'Max'})\n" + + "RETURN [(a)-->(b WHERE b:Person) | b.name] AS friends" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( List.of( "Hans" ) ) ) ); + + } + + + @Test + public void useInOperatorWithFilterTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (a:Person)\n" + + "WHERE a.name IN ['Peter', 'Max']\n" + + "RETURN a.name" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + } + + + @Test + public void missingPropertyFilterTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "WHERE n.age >= 40 \n" + + "RETURN n.name, n.age" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); + + } + + + + } From 6b0c0b82b8aa9fd8911f31c66c02e3f536e1b5be Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 6 Aug 2024 01:13:20 +0300 Subject: [PATCH 40/55] change function names to lower case --- .../db/cypher/Functions/StringFunTest.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java index 056b706042..c2424257ee 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java @@ -74,7 +74,7 @@ public void emptyLowerFunTest() { @Test - public void NullLowerFunTest() { + public void nullLowerFunTest() { GraphResult res = execute( "RETURN LOWER(null)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } @@ -114,14 +114,14 @@ public void trimFunTest() { @Test - public void EmptyTrimFunTest() { + public void emptyTrimFunTest() { GraphResult res = execute( "RETURN TRIM('')" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test - public void NormalReplaceFunTest() { + public void normalReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', 'Cypher') " ); assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); @@ -147,16 +147,14 @@ public void removeSubstringReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', '')" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, !" ) ) ); } -// @Test -// public void concatenateFunTest() { -// GraphResult res = execute("RETURN 'Hello' + ' ' + 'world!'"); -// assert containsRows(res, true, true, Row.of(TestLiteral.from("Hello world!"))); -// } -// @Test -// public void LengthFunTest() { -// GraphResult res = execute("RETURN LENGTH('Hello, world!')"); -// assert containsRows(res, true, true, Row.of(TestLiteral.from(13))); -// } + + + + @Test + public void stringLengthFunTest() { + GraphResult res = execute("RETURN LENGTH('Hello, world!')"); + assert containsRows(res, true, true, Row.of(TestLiteral.from(13))); + } } From 0cf738cb6c59edb688740b5403a072d2fff74ebf Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 6 Aug 2024 01:24:05 +0300 Subject: [PATCH 41/55] add coverage test for Point fun --- .../db/cypher/Functions/SpatialFunTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java new file mode 100644 index 0000000000..9222f121d7 --- /dev/null +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.cypher.Functions; + +import javassist.bytecode.CodeIterator.Gap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; +import org.polypheny.db.webui.models.results.GraphResult; + +public class SpatialFunTest extends CypherTestTemplate { + + @BeforeEach + public void reset() { + tearDown(); + createGraph(); + } + + + @Test + public void cartesian2DPointFunTest() { + + GraphResult res = execute( "WITH point({x: 3, y: 4}) AS p\n" + + "RETURN\n" + + " p.x AS x,\n" + + " p.y AS y,\n" + + " p.crs AS crs,\n" + + " p.srid AS srid" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 3.0 ), TestLiteral.from( 4.0 ), + TestLiteral.from( "cartesian" ), TestLiteral.from( 7203 ) ) ); + } + +} From a955b7bf9b8563900d90fe4ec7ff3b97f0bc060c Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Tue, 6 Aug 2024 01:29:22 +0300 Subject: [PATCH 42/55] add coverage test for Point fun --- .../db/cypher/Functions/SpatialFunTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java index 9222f121d7..8920923152 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java @@ -47,4 +47,29 @@ assert containsRows( res, true, false, TestLiteral.from( "cartesian" ), TestLiteral.from( 7203 ) ) ); } + + @Test + public void WGS_843DPointFunTest() { + GraphResult res = execute( "WITH point({latitude: 3, longitude: 4, height: 4321}) AS p\n" + + "RETURN\n" + + " p.latitude AS latitude,\n" + + " p.longitude AS longitude,\n" + + " p.height AS height,\n" + + " p.x AS x,\n" + + " p.y AS y,\n" + + " p.z AS z,\n" + + " p.crs AS crs,\n" + + " p.srid AS srid" ); + + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 3.0 ), + TestLiteral.from( 4.0 ), + TestLiteral.from( 4321.0 ), + TestLiteral.from( 4.0 ), + TestLiteral.from( 3.0 ), + TestLiteral.from( 4321.0 ), + TestLiteral.from( "wgs-84-3d" ), + TestLiteral.from( 4979 ) )); + } + } From b1080ef5d1c99b9e7ac0e4e1ceb242ee07c10ecb Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Thu, 8 Aug 2024 00:39:53 +0300 Subject: [PATCH 43/55] add coverage test for insert clause to ensure functionality of( max long , min long , max double ,min double , int bigger than 32 bit ) --- .../db/cypher/clause/write/DmlInsertTest.java | 84 ++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java index 80d9a2e744..68bf93e69a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java @@ -104,13 +104,94 @@ public void insertNodeWithManyLabelsTest() { @Test - public void insertNodeWithManyLabelsAndPropertyTest() { + public void insertNodeWithManyLabelsAndAsPropertyTest() { execute( "CREATE (n:Person:Employee {name :'Max'})" ); GraphResult res = matchAndReturnAllNodes(); assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ) ); } + @Test + public void insertBigIntegerExceeded32BitAsPropertyValeTest() + { + execute( "CREATE (n : node { id : 4294967296 })" ); + GraphResult res = matchAndReturnAllNodes() ; + assert res.getData().length == 1; + assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 4294967296L)) ); + } + + @Test + public void insertMaxLongAsPropertyValueTest() + { + execute( "CREATE (n : node { id : 9223372036854775807})" ); + GraphResult res = matchAndReturnAllNodes() ; + assert res.getData().length == 1; + assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 9223372036854775807L)) ); + + } + @Test + public void insertResultOfMathematicalOperationsTest() + { + execute( "CREATE (n : node { id : 1*2+6/3 })" ); + GraphResult res = matchAndReturnAllNodes() ; + assert res.getData().length == 1; + assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" ,9223372036854775807L )) ); + + } + + @Test + public void insertENotationAsPropertyValueTest() + { + execute( "CREATE (n : node { id : 1e2})" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 100)) ); + + + } + + @Test + public void insertMaxLongAsResultOfMathematicalOperationsTest() + { + + execute( "CREATE (n : node { id : 2^63-1})" ); + GraphResult res = matchAndReturnAllNodes() ; + assert res.getData().length == 1; + assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 4)) ); + + } + + @Test + public void insertMinLongAsPropertyValueTest() + { + + execute( "CREATE (n : node { id : -9223372036854775808L})" ); + GraphResult res = matchAndReturnAllNodes() ; + assert res.getData().length == 1; + assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , - 9223372036854775808L )) ); + } + + + @Test + public void insertMaxDoubleAsPropertyValueTest() + { + execute( "CREATE (n : node { id : 1.7976931348623157e+308})" ); + GraphResult res = matchAndReturnAllNodes() ; + assert res.getData().length == 1; + assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 1.7976931348623157e+308 )) ); + + } + + @Test + public void insertMinDoubleAsPropertyValueTest() + { + + execute( "CREATE (n : node { id : 4.9e-324 })" ); + GraphResult res = matchAndReturnAllNodes() ; + assert res.getData().length == 1; + assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 4.9e-324 )) ); + } + @Test @@ -122,6 +203,7 @@ public void insertNodeWithPropertyContainsListTest() { } + @Test public void insertTwoNodeTest() { execute( CREATE_PERSON_MAX ); From f0fb99a51203d806e12e85275a50256336b1926a Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Thu, 8 Aug 2024 04:07:22 +0300 Subject: [PATCH 44/55] add coverage test for insert clause to ensure functionality of (escape chars - hexadeciaml - octal ) --- .../db/cypher/clause/write/DmlInsertTest.java | 206 +++++++++++++----- 1 file changed, 150 insertions(+), 56 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java index 68bf93e69a..4a0523c1a3 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.List; +import org.apache.logging.log4j.core.pattern.NotANumber; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -76,9 +77,10 @@ public void insertEmptyNoLabelNodeTest() { assertNode( res, 0 ); assert containsNodes( res, true, TestNode.from( List.of() ) ); } + + @Test - public void insertEmptyNodeTest() - { + public void insertEmptyNodeTest() { execute( "CREATE (p:Person)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); @@ -107,92 +109,180 @@ public void insertNodeWithManyLabelsTest() { public void insertNodeWithManyLabelsAndAsPropertyTest() { execute( "CREATE (n:Person:Employee {name :'Max'})" ); - GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ) ); + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ) ); } + + @Test - public void insertBigIntegerExceeded32BitAsPropertyValeTest() - { + public void insertBigIntegerExceeded32BitAsPropertyValeTest() { execute( "CREATE (n : node { id : 4294967296 })" ); - GraphResult res = matchAndReturnAllNodes() ; - assert res.getData().length == 1; - assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 4294967296L)) ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4294967296L ) ) ); } + @Test - public void insertMaxLongAsPropertyValueTest() - { + public void insertMaxLongAsPropertyValueTest() { execute( "CREATE (n : node { id : 9223372036854775807})" ); - GraphResult res = matchAndReturnAllNodes() ; - assert res.getData().length == 1; - assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 9223372036854775807L)) ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 9223372036854775807L ) ) ); } + + @Test - public void insertResultOfMathematicalOperationsTest() - { + public void insertResultOfMathematicalOperationsTest() { execute( "CREATE (n : node { id : 1*2+6/3 })" ); - GraphResult res = matchAndReturnAllNodes() ; - assert res.getData().length == 1; - assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" ,9223372036854775807L )) ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 9223372036854775807L ) ) ); } + @Test - public void insertENotationAsPropertyValueTest() - { + public void insertENotationAsPropertyValueTest() { execute( "CREATE (n : node { id : 1e2})" ); - GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 100)) ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 100 ) ) ); } + @Test - public void insertMaxLongAsResultOfMathematicalOperationsTest() - { + public void insertMaxLongAsResultOfMathematicalOperationsTest() { execute( "CREATE (n : node { id : 2^63-1})" ); - GraphResult res = matchAndReturnAllNodes() ; - assert res.getData().length == 1; - assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 4)) ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4 ) ) ); } + @Test - public void insertMinLongAsPropertyValueTest() - { + public void insertMinLongAsPropertyValueTest() { execute( "CREATE (n : node { id : -9223372036854775808L})" ); - GraphResult res = matchAndReturnAllNodes() ; - assert res.getData().length == 1; - assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , - 9223372036854775808L )) ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", -9223372036854775808L ) ) ); } @Test - public void insertMaxDoubleAsPropertyValueTest() - { + public void insertMaxDoubleAsPropertyValueTest() { execute( "CREATE (n : node { id : 1.7976931348623157e+308})" ); - GraphResult res = matchAndReturnAllNodes() ; - assert res.getData().length == 1; - assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 1.7976931348623157e+308 )) ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 1.7976931348623157e+308 ) ) ); } + @Test - public void insertMinDoubleAsPropertyValueTest() - { + public void insertMinDoubleAsPropertyValueTest() { execute( "CREATE (n : node { id : 4.9e-324 })" ); - GraphResult res = matchAndReturnAllNodes() ; - assert res.getData().length == 1; - assert containsNodes( res , true , TestNode.from( List.of("node") ,Pair.of( "id" , 4.9e-324 )) ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4.9e-324 ) ) ); + } + + + @Test + public void insertHexadecimalIntegerAsPropertyValueTest() { + execute( "CREATE (n : node { id : 0x13af})" ); + execute( "CREATE (n : node { id : -0x66eff})" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, + TestNode.from( List.of( "node" ), Pair.of( "id", 5039 ) ), + TestNode.from( List.of( "node" ), Pair.of( "id", -421631 ) ) ); + + + } + + + @Test + public void insertOctalIntegerAsPropertyValueTest() { + + execute( "CREATE (n : node { id : 0o1372})" ); + execute( "CREATE (n : node { id :-0o5671 })" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, + TestNode.from( List.of( "node" ), Pair.of( "id", 762 ) ), + TestNode.from( List.of( "node" ), Pair.of( "id", -3001 ) ) ); + } + + + @Test + public void insertTabCharWithPropertyValueTest() { + execute( "CREATE (n : node { title : \"Hello\\tWorld\" })" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, + TestNode.from( List.of( "node" ), Pair.of( "title", "Hello\tWorld" ) ) ); + } + + + @Test + public void insertBackspaceCharWithPropertyValueTest() { + execute( "CREATE (n : node { title : \"Hello\\bWorld\" })" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, + TestNode.from( List.of( "node" ), Pair.of( "title", "Hello\bWorld" ) ) ); + } + + + @Test + public void insertNewlineWithPropertyValueTest() { + execute( "CREATE (n : node { title : \"Hello\\nWorld\" })" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, + TestNode.from( List.of( "node" ), Pair.of( "title", "Hello\nWorld" ) ) ); + } + + + @Test + public void insertSingleQuoteCharWithPropertyValueTest() { + execute( "CREATE (n : node { title : 'Hello\\'World' })" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, + TestNode.from( List.of( "node" ), Pair.of( "title", "Hello'World" ) ) ); + } + + + @Test + public void insertMultiplePropertiesWithSingleQuoteValuesTest() { + execute( " CREATE (n:node { name: \"Xi'an\", url: \"http://dbpedia.org/resource/Xi'an\"})" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, + TestNode.from( List.of( "node" ), Pair.of( "name", "Xi'an" ), + Pair.of( "url", "http://dbpedia.org/resource/Xi'an" ) ) ); } + @Test + public void insertDoubleQuoteCharWithPropertyValueTest() { + execute( "CREATE (n : node { title : \"Hello\\\"World\" })" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; + assert containsNodes( res, true, + TestNode.from( List.of( "node" ), Pair.of( "title", "Hello\"World" ) ) ); + } + @Test public void insertNodeWithPropertyContainsListTest() { @@ -203,7 +293,6 @@ public void insertNodeWithPropertyContainsListTest() { } - @Test public void insertTwoNodeTest() { execute( CREATE_PERSON_MAX ); @@ -250,10 +339,10 @@ public void insertReturnNodeTest() { assert containsNodes( res, true, TestNode.from( List.of() ) ); } + @Test - public void insertSingleHopPathNoVariableTest() - { - execute( "CREATE (p:Person {name :'Max'}) -[ : OWNER_OF] ->(a: Animal {name :'Kira' , age: 3 , type :'dog'})" ); + public void insertSingleHopPathNoVariableTest() { + execute( "CREATE (p:Person {name :'Max'}) -[ : OWNER_OF] ->(a: Animal {name :'Kira' , age: 3 , type :'dog'})" ); GraphResult res = matchAndReturnAllNodes(); // only select all nodes assert containsNodes( res, true, @@ -265,10 +354,12 @@ assert containsNodes( res, true, Pair.of( "type", "dog" ) ) ); // only select all edges - res = execute( "MATCH ()-[r]->() RETURN r" ); + res = execute( "MATCH ()-[r]->() RETURN r" ); assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); } + + @Test public void insertSingleHopPathTest() { execute( "CREATE (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'})" ); @@ -291,9 +382,9 @@ public void insertSingleHopPathEdgesTest() { assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); } + @Test - public void insertSingleHopPathWithMultiplePropertiesTest() - { + public void insertSingleHopPathWithMultiplePropertiesTest() { execute( "CREATE (p:Person {name: 'Max'})-[rel:KNOWS {since: 1994 , relation : 'friend'}]->(a:Person {name:'Hans', age:31})" ); // only select all nodes @@ -303,21 +394,23 @@ assert containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), - Pair.of( "age", 31))); + Pair.of( "age", 31 ) ) ); // only select all edges - res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ) , - Pair.of( "since" , 1994 ) , Pair.of( "relation" ,"friend" )) ); + res = execute( "MATCH ()-[r]->() RETURN r" ); + assert containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ), + Pair.of( "since", 1994 ), Pair.of( "relation", "friend" ) ) ); } + + @Test public void insertSingleHopPathWithListPropertyTest() { execute( "Create (p:Person:Employee {name: 'Max'})-[role:ACTED_IN {roles:['Neo', 42, 'Thomas Anderson']}]->(matrix:Movie {title: 'The Matrix'})" ); // only select all nodes GraphResult res = matchAndReturnAllNodes(); assert containsNodes( res, true, - TestNode.from( List.of( "Person" , "Employee"), Pair.of( "name", "Max" ) ), + TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ), TestNode.from( List.of( "Movie" ), Pair.of( "title", "The Matrix" ) ) ); @@ -328,6 +421,7 @@ assert containsEdges( res, true, TestEdge.from( List.of( "ACTED_IN" ), Pair.of( "roles", List.of( "Neo", 42, "Thomas Anderson" ) ) ) ); } + @Test public void insertMultipleHopPathTest() { execute( "CREATE (n:Person)-[f:FRIEND_OF]->(p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira'})" ); From a7a48e08999d5da0dcd526118fdf14a96f9ed5b7 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sat, 17 Aug 2024 04:22:19 +0300 Subject: [PATCH 45/55] Reformat line indents --- .../db/cypher/Functions/AggregateTest.java | 238 +++++++++--------- .../db/cypher/Functions/ListFunTest.java | 41 +++ .../db/cypher/Functions/NumericFunTest.java | 43 ++-- .../db/cypher/Functions/OtherFunTest.java | 58 +---- .../db/cypher/Functions/SpatialFunTest.java | 2 +- .../db/cypher/Functions/StringFunTest.java | 5 +- .../db/cypher/Functions/TemporalFunTest.java | 3 +- .../db/cypher/Operators/BooleanOperators.java | 41 +-- .../Operators/ComparisonOperations.java | 60 ++--- .../db/cypher/Operators/ListOperators.java | 29 +-- .../Operators/MathematicalOperators.java | 52 ++-- .../db/cypher/Operators/StringOperators.java | 8 +- .../cypher/Subqueries/CallSubqueriesTest.java | 2 +- .../Subqueries/CollectSubQueriesTest.java | 5 +- .../db/cypher/clause/general/CaseTest.java | 4 +- .../db/cypher/clause/general/FilterTest.java | 28 +-- .../db/cypher/clause/general/SkipTest.java | 22 +- .../db/cypher/clause/general/UnionTest.java | 80 +++--- .../db/cypher/clause/general/UnwindTest.java | 47 ++-- .../db/cypher/clause/general/WithTest.java | 170 +++++++------ .../db/cypher/clause/read/MatchTest.java | 12 +- .../db/cypher/clause/write/DmlDeleteTest.java | 6 +- .../db/cypher/clause/write/DmlUpdateTest.java | 11 + .../db/cypher/clause/write/MergeTest.java | 11 +- .../db/cypher/clause/write/RemoveTest.java | 14 +- 25 files changed, 502 insertions(+), 490 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java index bfb117ca11..a2b97e7266 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java @@ -53,15 +53,11 @@ public void singleCountAggregateTest() { assert containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); - execute( SINGLE_EDGE_2 ); res = execute( "MATCH (n:Person) RETURN count(*)" ); - assert containsRows( res, true, true, - Row.of( TestLiteral.from( 7) ) ); - - + Row.of( TestLiteral.from( 7 ) ) ); } @@ -82,13 +78,15 @@ assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 2 ) ) ); } + + @Test public void countNullAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN count(*)" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from( 0))); + Row.of( TestLiteral.from( 0 ) ) ); } @@ -132,25 +130,23 @@ assert containsRows( res, true, false, public void countPropertyAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute("MATCH (n) RETURN count(n.age)"); - assert containsRows(res, true, false, Row.of(TestLiteral.from(0))); + GraphResult res = execute( "MATCH (n) RETURN count(n.age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 0 ) ) ); } + @Test public void countDistinctFunctionTest() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_1); - - - GraphResult res = execute("MATCH (n) RETURN COUNT(DISTINCT n.name)"); - assert containsRows(res, true, false, Row.of(TestLiteral.from(1))); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_1 ); + GraphResult res = execute( "MATCH (n) RETURN COUNT(DISTINCT n.name)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } - @Test public void singleAvgAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -163,82 +159,93 @@ public void singleAvgAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN AVG(n.age)" ); // Printing the data using Arrays.deepToString String[][] data = res.getData(); - System.out.println( Arrays.deepToString(data)); + System.out.println( Arrays.deepToString( data ) ); assert containsRows( res, true, false, Row.of( TestLiteral.from( 26.33333333333333 ) ) ); } + @Test public void avgNullAggregateTest() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_2); - GraphResult res = execute("MATCH (p:Person) RETURN AVG(p.age)"); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (p:Person) RETURN AVG(p.age)" ); - assert containsRows(res, true, false, Row.of(TestLiteral.from(null))); + assert containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); } + @Test public void avgRenameAggregationTest() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN AVG(p.age) AS ages"); - assert containsRows(res, true, false, Row.of(TestLiteral.from(38))); + GraphResult res = execute( "MATCH (p:Person) RETURN AVG(p.age) AS ages" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); } + + @Test public void avgRenameFieldAggregationTest() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2 ); - execute(SINGLE_NODE_PERSON_COMPLEX_3 ); - + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute("MATCH (p:Person) RETURN p.depno As depNumber , AVG(p.age) As avgAge"); - containsRows(res, true, false, - Row.of(TestLiteral.from(13) , TestLiteral.from( 38 )), - Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) )); + GraphResult res = execute( "MATCH (p:Person) RETURN p.depno As depNumber , AVG(p.age) As avgAge" ); + containsRows( res, true, false, + Row.of( TestLiteral.from( 13 ), TestLiteral.from( 38 ) ), + Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); } + @Test public void singleCollectAggregationTest() { - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN COLLECT(p.age) "); - assert containsRows( res , true , false , Row.of( TestLiteral.from( List.of(45,31)) ) ); + GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age) " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); } + + @Test public void collectRenameAggregationTest() { - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN COLLECT(p.age) AS ages"); - assert containsRows( res , true , false , Row.of( TestLiteral.from( List.of(45,31)) ) ); + GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age) AS ages" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); } + @Test public void collectRenameFieldAggregationTest() { - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute("MATCH (p:Person) RETURN COLLECT(p.age) AS ages , p.depno AS depNumber"); - assert containsRows( res , true , false , - Row.of( TestLiteral.from( List.of(45 ,31)),TestLiteral.from( 13 ) ), - Row.of( TestLiteral.from( List.of(32)),TestLiteral.from( 14 ) )); + GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age) AS ages , p.depno AS depNumber" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( List.of( 45, 31 ) ), TestLiteral.from( 13 ) ), + Row.of( TestLiteral.from( List.of( 32 ) ), TestLiteral.from( 14 ) ) ); } + + @Test public void collectNullAggregationTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN COLLECT(p.age)"); - assert containsRows( res , true , false , Row.of( TestLiteral.from( List.of(null,null)) ) ); + GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age)" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( null, null ) ) ) ); } + + @Test public void singleMinMaxAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -251,20 +258,21 @@ public void singleMinMaxAggregateTest() { assert containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ) ); - - res = execute( "MATCH (n) RETURN max(n.age)" ); assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); } - @Test void minMaxNullAggregateTest() - { execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2 ); + + + @Test + void minMaxNullAggregateTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from(null ) ) ); + Row.of( TestLiteral.from( null ) ) ); res = execute( "MATCH (n) RETURN max(n.age) as ageMax" ); @@ -275,7 +283,6 @@ assert containsRows( res, true, false, } - @Test public void minMaxRenameAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); @@ -285,17 +292,17 @@ public void minMaxRenameAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from(31) )); - + Row.of( TestLiteral.from( 31 ) ) ); res = execute( "MATCH (n) RETURN max(n.age) as ageMax" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from(45) )); + Row.of( TestLiteral.from( 45 ) ) ); } + @Test public void minMaxRenameFieldAggregateTest() { @@ -306,15 +313,14 @@ public void minMaxRenameFieldAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN n.depno as depNumber , min(n.age) as ageMin" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from(13 ), TestLiteral.from(31) ), - Row.of( TestLiteral.from(14 ), TestLiteral.from(32) )); - + Row.of( TestLiteral.from( 13 ), TestLiteral.from( 31 ) ), + Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); res = execute( "MATCH (n) RETURN n.depno as depNumber , max(n.age) as ageMax" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from(13 ), TestLiteral.from(45) ), - Row.of( TestLiteral.from(14 ), TestLiteral.from(32) )); + Row.of( TestLiteral.from( 13 ), TestLiteral.from( 45 ) ), + Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); } @@ -331,94 +337,94 @@ assert containsRows( res, true, false, Row.of( TestLiteral.from( 34 ) ) ); } + @Test - public void sumNullAggregationTest () - { - execute(SINGLE_NODE_PERSON_1); + public void sumNullAggregationTest() { + execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n) RETURN sum(n.age)" ); + GraphResult res = execute( "MATCH (n) RETURN sum(n.age)" ); assert containsRows( res, true, false, Row.of( TestLiteral.from( 0 ) ) ); - /// Printing the data using Arrays.deepToString + /// Printing the data using Arrays.deepToString System.out.print( "Alyaa :" ); String[][] data = res.getData(); - System.out.println( Arrays.deepToString(data)); + System.out.println( Arrays.deepToString( data ) ); } + @Test public void sumRenameAggregationTest() { - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute("MATCH (p:Person) RETURN sum(p.age) As totalAge "); + GraphResult res = execute( "MATCH (p:Person) RETURN sum(p.age) As totalAge " ); assert containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); } + + @Test public void sumRenameFieldAggregationTest() { - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - execute( SINGLE_NODE_PERSON_COMPLEX_3); - - GraphResult res = execute("MATCH (p:Person) RETURN sum(p.age) AS totalAge, p.depno AS depNumber,"); - assert containsRows(res, true, false, - Row.of(TestLiteral.from(13) , TestLiteral.from( 76 )), - Row.of(TestLiteral.from(14) , TestLiteral.from( 32 ))); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person) RETURN sum(p.age) AS totalAge, p.depno AS depNumber," ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 13 ), TestLiteral.from( 76 ) ), + Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); } - @Test - public void singleStDevAggregateTest() - { execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - GraphResult res = execute("MATCH (p:Person) RETURN stdev(p.age) "); - assert containsRows(res, true, false, - Row.of( TestLiteral.from( 9.8994949))); - } @Test - public void stDevNullAggregateTest() - { execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_2); - GraphResult res = execute("MATCH (p:Person) RETURN stdev(p.age) "); - assert containsRows(res, true, false, - Row.of( TestLiteral.from( null))); - } - @Test - public void stDevRenameAggregateTest() - { - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - GraphResult res = execute("MATCH (p:Person) RETURN stdev(p.age) AS Stdev "); - assert containsRows(res, true, false, - Row.of( TestLiteral.from( 9.8994949))); + public void singleStDevAggregateTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) " ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 9.8994949 ) ) ); + - } - @Test - public void stDevRenameFieldAggregateTest() - { - execute(SINGLE_NODE_PERSON_COMPLEX_1); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - - GraphResult res = execute("MATCH (p:Person) RETURN stdev(p.age) AS Stdev , n.depno As department"); - assert containsRows(res, true, false, - Row.of( TestLiteral.from( 9.8994949) , TestLiteral.from( 13 ))); } + @Test + public void stDevNullAggregateTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) " ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( null ) ) ); + } + @Test + public void stDevRenameAggregateTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) AS Stdev " ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 9.8994949 ) ) ); + } + @Test + public void stDevRenameFieldAggregateTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) AS Stdev , n.depno As department" ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 9.8994949 ), TestLiteral.from( 13 ) ) ); + } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java index a0082e921f..c9aeda5831 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java @@ -21,6 +21,7 @@ import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.List; public class ListFunTest extends CypherTestTemplate { @@ -81,4 +82,44 @@ assert containsRows( res, true, true, Row.of( TestLiteral.from( 1 ), TestLiteral.from( 2 ), TestLiteral.from( 3 ) ) ); } + + @Test + public void returnLabelsFunTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (a)" + + "RETURN labels(a)" ); + + assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Person" ) ) ) ); + } + + + @Test + public void returnNodesFunTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + + "RETURN nodes(p)" ); + assert res.getData().length == 1; + assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( MAX, KIRA ) ) ) ); + + } + + + @Test + public void returnRelationsFunTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + + "RETURN relationships(p)" ); + assert res.getData().length == 1; + } + + + @Test + public void returnRelationAndNodesFunTest() { + execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + + "RETURN relationships(p) , nodes(p)" ); + assert res.getData().length == 1; + } + + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java index 9594627451..7762b0ae79 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java @@ -40,19 +40,18 @@ public void absFunTest() { res = execute( "RETURN ABS(5)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); - - res = execute("RETURN ABS(0)"); - assert containsRows(res, true, true, Row.of(TestLiteral.from(0))); + res = execute( "RETURN ABS(0)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); } @Test public void roundFunTest() { - GraphResult res = execute("RETURN ROUND(3)"); - assert containsRows(res, true, true, Row.of(TestLiteral.from(3))); + GraphResult res = execute( "RETURN ROUND(3)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); - res = execute("RETURN ROUND(-3)"); - assert containsRows(res, true, true, Row.of(TestLiteral.from(-3))); + res = execute( "RETURN ROUND(-3)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); res = execute( "RETURN ROUND(3.4)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); @@ -60,9 +59,8 @@ public void roundFunTest() { res = execute( "RETURN ROUND(3.5)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); - res = execute("RETURN ROUND(-3.5)"); - assert containsRows(res, true, true, Row.of(TestLiteral.from(-4))); - + res = execute( "RETURN ROUND(-3.5)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); } @@ -74,17 +72,17 @@ public void floorFunTest() { GraphResult res = execute( "RETURN FLOOR(3)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); - res = execute( "RETURN FLOOR(-3)" ); + res = execute( "RETURN FLOOR(-3)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); - res = execute( "RETURN FLOOR(3.16)" ); + res = execute( "RETURN FLOOR(3.16)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN FLOOR(3.9)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); - res = execute("RETURN FLOOR(-3.16)"); - assert containsRows(res, true, true, Row.of(TestLiteral.from(-4))); + res = execute( "RETURN FLOOR(-3.16)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); } @@ -93,7 +91,7 @@ public void ceilFunTest() { GraphResult res = execute( "RETURN CEIL(3)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); - res = execute( "RETURN CEIL(-3)" ); + res = execute( "RETURN CEIL(-3)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN CEIL(3.16)" ); @@ -110,21 +108,24 @@ public void sqrtFunTest() { GraphResult res = execute( "RETURN SQRT(9)" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); - res = execute("RETURN SQRT(0)"); - assert containsRows(res, true, true, Row.of(TestLiteral.from(0))); + res = execute( "RETURN SQRT(0)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); } + @Test public void nonPerfectSquareSqrtFunTest() { - GraphResult res = execute("RETURN SQRT(8)"); - assert containsRows(res, true, true, Row.of(TestLiteral.from(Math.sqrt(8)))); + GraphResult res = execute( "RETURN SQRT(8)" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( Math.sqrt( 8 ) ) ) ); } + @Test public void sqrtFunTestNegative() { - GraphResult res = execute("RETURN SQRT(-9)"); - // assert containsRows(res, true, true, Row.of(TestLiteral.from(null))); + GraphResult res = execute( "RETURN SQRT(-9)" ); + // assert containsRows(res, true, true, Row.of(TestLiteral.from(null))); } + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java index ce50b2b74f..fba3d90635 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java @@ -32,9 +32,11 @@ public void reset() { tearDown(); createGraph(); } - ////////////////////////// - /// Scalar Functions - /////////////////////////// + + + ////////////////////////// + /// Scalar Functions + /////////////////////////// @Test public void typeFunTest() { execute( SINGLE_EDGE_1 ); @@ -54,6 +56,7 @@ public void idFunTest() { } + @Test public void testCoalesceFunTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -83,9 +86,10 @@ assert containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( "unknown" ) ) ); } - /////////////////////////////// - // Predicate Functions - ///////////////////////////// + + /////////////////////////////// + // Predicate Functions + ///////////////////////////// @Test public void ExistFunTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -101,46 +105,4 @@ public void ExistFunTest() { } - /////////////////////////// - //// List Functions - /////////////////////////// - @Test - public void returnLabelsFunTest() { - execute( SINGLE_EDGE_1 ); - GraphResult res = execute( "MATCH (a)" - + "RETURN labels(a)" ); - - assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Person" ) ) ) ); - } - - @Test - public void returnNodesFunTest() - { - execute( SINGLE_EDGE_1 ); - GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" - + "RETURN nodes(p)" ); - assert res.getData().length == 1; - assert containsRows( res , true , false ,Row.of( TestLiteral.from( List.of(MAX ,KIRA ) ) ) ); - - } - - @Test - public void returnRelationsFunTest() - { - execute( SINGLE_EDGE_1 ); - GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" - + "RETURN relationships(p)" ); - assert res.getData().length == 1 ; - } - - @Test - public void returnRelationAndNodesFunTest() - { - execute( SINGLE_EDGE_1 ); - GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" - + "RETURN relationships(p) , nodes(p)" ); - assert res.getData().length == 1 ; - } - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java index 8920923152..67a00c79d1 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java @@ -69,7 +69,7 @@ assert containsRows( res, true, false, TestLiteral.from( 3.0 ), TestLiteral.from( 4321.0 ), TestLiteral.from( "wgs-84-3d" ), - TestLiteral.from( 4979 ) )); + TestLiteral.from( 4979 ) ) ); } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java index c2424257ee..b9a1183cf2 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java @@ -149,11 +149,10 @@ public void removeSubstringReplaceFunTest() { } - @Test public void stringLengthFunTest() { - GraphResult res = execute("RETURN LENGTH('Hello, world!')"); - assert containsRows(res, true, true, Row.of(TestLiteral.from(13))); + GraphResult res = execute( "RETURN LENGTH('Hello, world!')" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 13 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java index ae26c166d6..ea5eabd2a9 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java @@ -223,9 +223,8 @@ public void stringIntoDurationFunTest() { @Test public void durationBetweenFunTest() { GraphResult res = execute( "RETURN duration.between(date('1984-10-11'), date('2015-06-24')) AS theDuration" ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( "P30Y8M13D" ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "P30Y8M13D" ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java index 58f015c176..4b3735d85d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java @@ -24,52 +24,53 @@ import org.polypheny.db.webui.models.results.GraphResult; public class BooleanOperators extends CypherTestTemplate { + @BeforeEach public void setUp() { tearDown(); createGraph(); } + @Test - public void conjunctionOperatorTest() - { - GraphResult res = execute( "WITH true as a , false as b RETURN a AND b " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from( false ) ) ); + public void conjunctionOperatorTest() { + GraphResult res = execute( "WITH true as a , false as b RETURN a AND b " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH true as a , true as b RETURN a AND b " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from(true ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } + @Test - public void disjunctionOperatorTest() - { - GraphResult res = execute( "WITH true as a , false as b RETURN a OR b " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from( true ) ) ); + public void disjunctionOperatorTest() { + GraphResult res = execute( "WITH true as a , false as b RETURN a OR b " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "WITH false as a , false as b RETURN a OR b " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from(false ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } + @Test - public void exclusiveDisjunctionOperatorTest() - { - GraphResult res = execute( "WITH true as a , false as b RETURN a XOR b " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from( true ) ) ); + public void exclusiveDisjunctionOperatorTest() { + GraphResult res = execute( "WITH true as a , false as b RETURN a XOR b " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "WITH true as a , true as b RETURN a XOR b " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from(false ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH false as a , false as b RETURN a XOR b " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from(true ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } + @Test - public void negationOperatorTest() - { + public void negationOperatorTest() { GraphResult res = execute( "WITH true as a RETURN NOT a " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from(false ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH false as a RETURN NOT a " ); - assert containsRows( res , true , false , Row.of( TestLiteral.from(true ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java index 2e9077dfcf..85e8abe5d1 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java @@ -23,6 +23,7 @@ import org.polypheny.db.webui.models.results.GraphResult; public class ComparisonOperations extends CypherTestTemplate { + @BeforeEach public void setUp() { tearDown(); @@ -32,55 +33,58 @@ public void setUp() { @Test public void IsNullOperatorTest() { - GraphResult res = execute( "Return null is not null as Result" ); - assert containsRows( res ,true , false ,Row.of( TestLiteral.from( false ) ) ); + GraphResult res = execute( "Return null is not null as Result" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } + @Test public void IsNotNullFunction() { - GraphResult res = execute( "Return null is null as Result" ); - assert containsRows( res ,true , false ,Row.of( TestLiteral.from( true ) ) ); + GraphResult res = execute( "Return null is null as Result" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } + @Test - public void greaterThanOperatorTest() - { - GraphResult res = execute( "Return 1 > 2 as result " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + public void greaterThanOperatorTest() { + GraphResult res = execute( "Return 1 > 2 as result " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } + @Test - public void smallerThanOperatorTest() - { - GraphResult res = execute( "Return 1 < 2 as result " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( true) ) ); + public void smallerThanOperatorTest() { + GraphResult res = execute( "Return 1 < 2 as result " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } + + @Test - public void greaterThanOrEqualOperatorTest() - { - GraphResult res = execute( "Return 1 >= 2 as result " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + public void greaterThanOrEqualOperatorTest() { + GraphResult res = execute( "Return 1 >= 2 as result " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } + + @Test - public void smallerThanOrEqualOperatorTest() - { - GraphResult res = execute( "Return 1 <= 2 as result " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( true ) ) ); + public void smallerThanOrEqualOperatorTest() { + GraphResult res = execute( "Return 1 <= 2 as result " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } + @Test - public void equalityOperatorTest() - { - GraphResult res = execute( "Return 2 = 2 as result " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( true ) ) ); + public void equalityOperatorTest() { + GraphResult res = execute( "Return 2 = 2 as result " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } + @Test - public void inequalityOperatorTest() - { - GraphResult res = execute( "Return 1 <> 2 as result " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + public void inequalityOperatorTest() { + GraphResult res = execute( "Return 1 <> 2 as result " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java index fd0e42e097..81c3043d37 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java @@ -23,32 +23,33 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -public class ListOperators extends CypherTestTemplate { +public class ListOperators extends CypherTestTemplate { + @BeforeEach public void setUp() { tearDown(); createGraph(); } + @Test - public void checkIfNumberInListOperatorTest() - { - GraphResult res = execute( "RETURN 1 IN [ 1 ,2 ]" ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( true ) ) ); + public void checkIfNumberInListOperatorTest() { + GraphResult res = execute( "RETURN 1 IN [ 1 ,2 ]" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); - res = execute( "RETURN 3 IN [ 1 ,2 ]" ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + res = execute( "RETURN 3 IN [ 1 ,2 ]" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } + + @Test - public void checkIfListInListOperatorTest() - { - GraphResult res = execute( "RETURN [2, 1] IN [1, [2, 1], 3] " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( true ) ) ); + public void checkIfListInListOperatorTest() { + GraphResult res = execute( "RETURN [2, 1] IN [1, [2, 1], 3] " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); - res = execute( "RETURN [1, 2] IN [1, 2] " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( false ) ) ); + res = execute( "RETURN [1, 2] IN [1, 2] " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java index 75d0cf6103..0f821ba4d0 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java @@ -24,65 +24,61 @@ import org.polypheny.db.webui.models.results.GraphResult; import java.util.Arrays; -public class MathematicalOperators extends CypherTestTemplate { +public class MathematicalOperators extends CypherTestTemplate { + @BeforeEach public void reset() { tearDown(); createGraph(); } + + @Test - public void additionOperator () - { - GraphResult res = execute( "RETURN 2 + 3" ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( 5 ) ) ); + public void additionOperator() { + GraphResult res = execute( "RETURN 2 + 3" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 5 ) ) ); } + @Test - public void minisOperatorTest() - { + public void minisOperatorTest() { GraphResult res = execute( "RETURN 3 - 2" ); - assert containsRows( res , true , false , Row.of( TestLiteral.from( 1) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } - - @Test - public void multiplicationOperatorTest() - { - GraphResult res = execute( "RETURN 2 * 3" ); + public void multiplicationOperatorTest() { + GraphResult res = execute( "RETURN 2 * 3" ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( 6 ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 6 ) ) ); } + @Test - public void divisionOperatorTest() - { - GraphResult res = execute( "RETURN 6 / 3 " ); + public void divisionOperatorTest() { + GraphResult res = execute( "RETURN 6 / 3 " ); - assert containsRows( res , true , false ,Row.of( TestLiteral.from( 2 ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @Test - public void moduleOperatorTest() - { - GraphResult res = execute( "RETURN 3 % 2 " ); - assert containsRows( res , true ,false ,Row.of( TestLiteral.from( 1 ) ) ); + public void moduleOperatorTest() { + GraphResult res = execute( "RETURN 3 % 2 " ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } + @Test - public void exponentiationOperator() - { - GraphResult res = execute( "RETURN 2 ^ 3" ); + public void exponentiationOperator() { + GraphResult res = execute( "RETURN 2 ^ 3" ); - assert containsRows( res , true ,false , Row.of( TestLiteral.from( 8.0) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 8.0 ) ) ); } - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java index e14ae6ee47..048b17d68a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java @@ -22,7 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -public class StringOperators extends CypherTestTemplate { +public class StringOperators extends CypherTestTemplate { @BeforeEach @@ -31,12 +31,12 @@ public void setUp() { createGraph(); } + @Test public void concatenateWithPlusOperatorTest() { - GraphResult res = execute("RETURN 'neo' + '4j' AS result"); - assert containsRows(res, true, true, Row.of( TestLiteral.from("neo4j"))); + GraphResult res = execute( "RETURN 'neo' + '4j' AS result" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "neo4j" ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java index b49ce5fd82..a41e7d2887 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java @@ -176,7 +176,7 @@ public void unitSubQueryCallTest() { + "WITH p\n" + " CREATE (:Person {name: p.name}) \n" + "} RETURN count(*)" ); - //the number of rows present after the subquery is the same as was going into the subquery + //the number of rows present after the subquery is the same as was going into the subquery assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java index f84d6f113d..f14ea5a250 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java @@ -148,10 +148,9 @@ public void updateWithCollectSubQueryTest() { + "SET person.dogNames = COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name }\n" + "RETURN person.dogNames as dogNames" ); - assert containsRows( res , true , false , - Row.of( TestLiteral.from( List.of("Andy") ) ) ); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( List.of( "Andy" ) ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java index bb34a49955..9be0cbac74 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java @@ -112,7 +112,7 @@ public void expressionsAndSucceedingClauses() { execute( PERSON_NODE_BOB ); execute( PERSON_NODE_CHARLIE ); - GraphResult res = execute( "MATCH (n:Person)\n" + GraphResult res = execute( "MATCH (n:Person)\n" + "WITH n,\n" + "CASE n.eyes\n" + " WHEN 'blue' THEN 1\n" @@ -125,7 +125,7 @@ public void expressionsAndSucceedingClauses() { assert containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) )); + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 7a6906c54c..3452caf360 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -91,14 +91,14 @@ public void NodePatternFilterTest() { } + @Test - public void relationshipPatternFilterTest() - { + public void relationshipPatternFilterTest() { execute( SINGLE_EDGE_2 ); - GraphResult res = execute( "MATCH (a:Person)-[r:KNOWS WHERE r.since < 2000 ]->(b:Person)\n" + GraphResult res = execute( "MATCH (a:Person)-[r:KNOWS WHERE r.since < 2000 ]->(b:Person)\n" + "RETURN r.since" ); - assert containsRows( res , true , false , Row.of( TestLiteral.from(1994 ) ) ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 1994 ) ) ); } @@ -114,21 +114,21 @@ public void propertyExistenceCheckFilterTest() { assert containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } + + @Test - public void propertyNonExistenceCheckFilterTest() - { - execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "WHERE n.age IS NULL\n" - + "RETURN n.name" ); + public void propertyNonExistenceCheckFilterTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + GraphResult res = execute( "MATCH (n:Person)\n" + + "WHERE n.age IS NULL\n" + + "RETURN n.name" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Max" )) ); + Row.of( TestLiteral.from( "Max" ) ) ); } - @Test public void rangeFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); @@ -327,6 +327,4 @@ assert containsRows( res, true, false, } - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java index bc07b910bb..a7a348364f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java @@ -25,7 +25,7 @@ import org.polypheny.db.webui.models.results.GraphResult; import java.util.Arrays; -public class SkipTest extends CypherTestTemplate { +public class SkipTest extends CypherTestTemplate { @BeforeEach public void reset() { @@ -33,6 +33,7 @@ public void reset() { createGraph(); } + @Test public void simpleSkipTest() { execute( SINGLE_NODE_ANIMAL ); @@ -46,6 +47,7 @@ public void simpleSkipTest() { assert res.getData().length == 2; } + @Test public void orderBySkipTest() { execute( SINGLE_NODE_ANIMAL ); @@ -61,10 +63,10 @@ assert containsRows( res, true, true, Row.of( TestLiteral.from( "Kira" ) ) ); } + @Test - public void withAndSkipTest() - { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + public void withAndSkipTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); @@ -74,9 +76,9 @@ public void withAndSkipTest() } + @Test - public void returnSubsetSkipTest() - { + public void returnSubsetSkipTest() { execute( SINGLE_NODE_ANIMAL ); execute( SINGLE_NODE_ANIMAL ); execute( SINGLE_NODE_ANIMAL ); @@ -88,9 +90,9 @@ public void returnSubsetSkipTest() assert res.getData().length == 1; - } + @Test public void withAndOrderBySkipTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); @@ -103,9 +105,9 @@ public void withAndOrderBySkipTest() { assert res.getData().length == 1; assert containsNodes( res, true, - TestNode.from( Pair.of( "name" , "Bob" ) , - Pair.of( "age" , 31 ) , - Pair.of( "depno" , 13 )) ); + TestNode.from( Pair.of( "name", "Bob" ), + Pair.of( "age", 31 ), + Pair.of( "depno", 13 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java index 690d4df530..4483fa4dcd 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java @@ -31,6 +31,8 @@ public void reset() { tearDown(); createGraph(); } + + protected static final String SINGLE_NODE_MOVIE = "CREATE (wallStreet:Movie {title: 'Wall Street' , released : 2002})"; @@ -56,7 +58,7 @@ public void simpleUnionTest() { public void DifferentStructureUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_MOVIE); + execute( SINGLE_NODE_MOVIE ); GraphResult res = execute( "MATCH (p:Person)\n" + "RETURN p.name AS name\n" @@ -66,25 +68,25 @@ public void DifferentStructureUnionTest() { assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Wall Street" )) ); + Row.of( TestLiteral.from( "Wall Street" ) ) ); } + @Test - public void NullPropertiesUnionTest() - { - execute( SINGLE_NODE_PERSON_COMPLEX_1); - execute( SINGLE_NODE_PERSON_COMPLEX_1); - execute( SINGLE_NODE_MOVIE); + public void NullPropertiesUnionTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_MOVIE ); GraphResult res = execute( "MATCH (p:Person)\n" + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" + "UNION\n" + "MATCH (m:Movie)\n" - + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n"); + + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Ann" ) , TestLiteral.from( 45 ) , TestLiteral.from( null ),TestLiteral.from( null )), - Row.of( TestLiteral.from( null ),TestLiteral.from( null ),TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 )) ); + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), + Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ) ); } @@ -92,7 +94,7 @@ assert containsRows( res, true, false, public void allUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - execute( SINGLE_NODE_PERSON_1); + execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person)\n" @@ -103,17 +105,18 @@ public void allUnionTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Hans" ) ) , - Row.of(TestLiteral.from( "Max" )), - Row.of(TestLiteral.from( "Hans" ))); + Row.of( TestLiteral.from( "Hans" ) ), + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Hans" ) ) ); } + @Test public void DifferentStructureAllUnionTest() { execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_MOVIE); + execute( SINGLE_NODE_MOVIE ); execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_MOVIE ); @@ -125,39 +128,38 @@ public void DifferentStructureAllUnionTest() { assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Wall Street" )), - Row.of( TestLiteral.from( "Max" )), - Row.of( TestLiteral.from( "Wall Street" ))); + Row.of( TestLiteral.from( "Wall Street" ) ), + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Wall Street" ) ) ); } + @Test - public void NullPropertiesAllUnionTest() - { - execute( SINGLE_NODE_PERSON_COMPLEX_1); + public void NullPropertiesAllUnionTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_MOVIE ); - execute( SINGLE_NODE_MOVIE); + execute( SINGLE_NODE_MOVIE ); GraphResult res = execute( "MATCH (p:Person)\n" + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" + "UNION ALL\n" + "MATCH (m:Movie)\n" - + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n"); + + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Ann" ) , TestLiteral.from( 45 ) , TestLiteral.from( null ),TestLiteral.from( null )), - Row.of( TestLiteral.from( "Ann" ) , TestLiteral.from( 45 ) , TestLiteral.from( null ),TestLiteral.from( null )), - Row.of( TestLiteral.from( null ),TestLiteral.from( null ),TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 )), - Row.of( TestLiteral.from( null ),TestLiteral.from( null ),TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 )) ); + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), + Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ), + Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ) ); } - @Test public void distinctUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - execute( SINGLE_NODE_PERSON_1); + execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person)\n" @@ -176,7 +178,7 @@ public void distinctUnionTest() { public void DifferentStructureDistinctUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_MOVIE); + execute( SINGLE_NODE_MOVIE ); GraphResult res = execute( "MATCH (p:Person)\n" + "RETURN p.name AS name\n" @@ -186,25 +188,25 @@ public void DifferentStructureDistinctUnionTest() { assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), - Row.of( TestLiteral.from( "Wall Street" )) ); + Row.of( TestLiteral.from( "Wall Street" ) ) ); } + @Test - public void NullPropertiesDistinctUnionTest() - { - execute( SINGLE_NODE_PERSON_COMPLEX_1); - execute( SINGLE_NODE_PERSON_COMPLEX_1); - execute( SINGLE_NODE_MOVIE); + public void NullPropertiesDistinctUnionTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_MOVIE ); GraphResult res = execute( "MATCH (p:Person)\n" + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" + "UNION DISTINCT \n" + "MATCH (m:Movie)\n" - + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n"); + + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Ann" ) , TestLiteral.from( 45 ) , TestLiteral.from( null ),TestLiteral.from( null )), - Row.of( TestLiteral.from( null ),TestLiteral.from( null ),TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 )) ); + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), + Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ) ); } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java index 25205af05d..1f36f719f7 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java @@ -77,7 +77,6 @@ public void minMaxAggregateSimpleUnWind() { } - @Test public void minMaxAggregateListOfListUnwind() { GraphResult res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN min(val)" ); @@ -125,65 +124,53 @@ public void AvgAggregateNodePropertyUnWind() { @Test - public void CollectAggregateUnWind () - { + public void CollectAggregateUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); } - - - @Test public void countUnWind() { GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); - assert containsRows( res, true, false, - Row.of( TestLiteral.from( 3))); + Row.of( TestLiteral.from( 3 ) ) ); } + @Test public void distinctUnWind() { GraphResult res = execute( "UNWIND [3, 3 ,2 ,1 ] AS i RETURN DISTINCT i" ); assert res.getData().length == 3; - assert containsRows( res , true , false , - Row.of(TestLiteral.from(3)) , - Row.of( TestLiteral.from( 2 )) ,Row.of( TestLiteral.from( 1) )); + assert containsRows( res, true, false, + Row.of( TestLiteral.from( 3 ) ), + Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 1 ) ) ); } - - @Test - public void ConditionalLogicUnWind() - { - GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); - assert containsRows( res , true , true , - Row.of( TestLiteral.from( 1 ) ,TestLiteral.from("odd" ) ), - Row.of( TestLiteral.from( 2 ) ,TestLiteral.from( "even" )), - Row.of( TestLiteral.from( 3 ) ,TestLiteral.from( "odd"))); + public void ConditionalLogicUnWind() { + GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( 1 ), TestLiteral.from( "odd" ) ), + Row.of( TestLiteral.from( 2 ), TestLiteral.from( "even" ) ), + Row.of( TestLiteral.from( 3 ), TestLiteral.from( "odd" ) ) ); } - - @Test - public void mapStructureUnWind() - { - GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); - assert containsRows( res , true , false , Row.of( TestLiteral.from( "Alice" ) ),Row.of( TestLiteral.from( 30 ) ) ); + public void mapStructureUnWind() { + GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ) ), Row.of( TestLiteral.from( 30 ) ) ); } - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java index 4a9664dc79..de560abb1b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java @@ -35,6 +35,7 @@ public void reset() { createGraph(); } + @Test public void singleVariableWithTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -45,15 +46,16 @@ public void singleVariableWithTest() { } + @Test - public void multipleRenameVariablesWithTest() - { + public void multipleRenameVariablesWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH p.name AS person_name , p.age AS person_age , p RETURN person_name, person_age , p.depno;" ); } + @Test public void renameWithTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -62,10 +64,11 @@ public void renameWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name AS name, n RETURN name, n" ); assert containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ), - Row.of( TestLiteral.from( "Hans" ),HANS )); + Row.of( TestLiteral.from( "Hans" ), HANS ) ); } + @Test public void startWithTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -73,12 +76,12 @@ public void startWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name, n WHERE n.name STARTS WITH 'H' RETURN n" ); - assert containsRows( res, true, true, Row.of( HANS ) ); } + @Test public void startRenameWithTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -92,6 +95,7 @@ assert containsRows( res, true, true, } + @Test public void endWithTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -104,6 +108,7 @@ public void endWithTest() { } + @Test public void endRenameWithTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -131,108 +136,117 @@ public void containsWithTest() { } + // aggregate @Test - public void avgAggregationRenameWithTest() - { + public void avgAggregationRenameWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH avg(p.age) as ageAvg RETURN ageAvg " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from(38 )) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 38 ) ) ); } + @Test - public void maxMinAggregationRenameWithTest() - { + public void maxMinAggregationRenameWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH MAX(p.age) as ageMax RETURN ageMax " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from(45 )) ); - res = execute( "MATCH (p:Person) WITH MIN(p.age) as ageMin RETURN ageMin " ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 45 ) ) ); + res = execute( "MATCH (p:Person) WITH MIN(p.age) as ageMin RETURN ageMin " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from(31 )) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 31 ) ) ); } + + @Test - public void countAggregationWithTest() - { + public void countAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH COUNT(*) as count RETURN count " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from(2 )) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 2 ) ) ); } + + @Test - public void stDevAggregationWithTest() - { + public void stDevAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH STDEV(p.age) as ageStdev RETURN ageStdev " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from(9.8994949)) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 9.8994949 ) ) ); } + @Test - public void collectAggregationWithTest() - { + public void collectAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH COLLECT(p.age) as ageList RETURN ageList " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from(45) ,TestLiteral.from( 31 ) ) ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( 45 ), TestLiteral.from( 31 ) ) ); } + @Test - public void mapStructureRenameWithTest() - { + public void mapStructureRenameWithTest() { GraphResult res = execute( "WITH {person: {name: 'Anne', age: 25}} AS p RETURN p" ); } + @Test - public void filterWithTest() - { execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + public void filterWithTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p WHERE p.age > 31 RETURN p.name, p.age" ); + GraphResult res = execute( "MATCH (p:Person) WITH p WHERE p.age > 31 RETURN p.name, p.age" ); } + + @Test - public void calculationWithTest() - { execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + public void calculationWithTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p, p.age * 2 AS double_age RETURN p.name, double_age;" ); + GraphResult res = execute( "MATCH (p:Person) WITH p, p.age * 2 AS double_age RETURN p.name, double_age;" ); } + @Test - public void listWithTest() - { - GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers RETURN numbers" ); + public void listWithTest() { + GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers RETURN numbers" ); } + + @Test - public void unWindListWithTest() - { - GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number RETURN number;" ); + public void unWindListWithTest() { + GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number RETURN number;" ); } + + @Test - public void unWindAndFilterListWithTest() - { - GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number WITH number WHERE number > 3 RETURN number" ); + public void unWindAndFilterListWithTest() { + GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number WITH number WHERE number > 3 RETURN number" ); } + + @Test - public void unWindAndStartListWithTest() - { - GraphResult res = execute( "WITH ['John', 'Mark', 'Jonathan', 'Bill'] AS somenames UNWIND somenames AS names WITH names AS candidate WHERE candidate STARTS WITH 'Jo' RETURN candidate" ); - assert containsRows( res , true , false , Row.of( TestLiteral.from( "John" ) ),Row.of( TestLiteral.from( "Jonathan" ) ) ); + public void unWindAndStartListWithTest() { + GraphResult res = execute( "WITH ['John', 'Mark', 'Jonathan', 'Bill'] AS somenames UNWIND somenames AS names WITH names AS candidate WHERE candidate STARTS WITH 'Jo' RETURN candidate" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( "John" ) ), Row.of( TestLiteral.from( "Jonathan" ) ) ); } + @Test public void unWindAndLogicalOperatorsListWithTest() { GraphResult res = execute( "WITH [2, 4, 7, 9, 12] AS numberlist UNWIND numberlist AS number WITH number WHERE number = 4 OR (number > 6 AND number < 10) RETURN number" ); @@ -242,74 +256,72 @@ assert containsRows( res, false, false, Row.of( TestLiteral.from( 9 ) ) ); } + @Test - public void unWindAndWhereInListWithTest() - { - GraphResult res = execute( "WITH [2, 3, 4, 5] AS numberlist UNWIND numberlist AS number WITH number WHERE number IN [2, 3, 8] RETURN number" ) ; - assert containsRows( res , true , false , Row.of( TestLiteral.from( 2 ) ) , Row.of( TestLiteral.from( 3 ) )); + public void unWindAndWhereInListWithTest() { + GraphResult res = execute( "WITH [2, 3, 4, 5] AS numberlist UNWIND numberlist AS number WITH number WHERE number IN [2, 3, 8] RETURN number" ); + assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 3 ) ) ); } + @Test - public void createNodeWithTest() - { - execute( "WITH [1, 1.0] AS list CREATE ({l: list})" ); - GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1 ; + public void createNodeWithTest() { + execute( "WITH [1, 1.0] AS list CREATE ({l: list})" ); + GraphResult res = matchAndReturnAllNodes(); + assert res.getData().length == 1; } + @Test - public void distinctWithTest() - { - execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2 ); - execute( SINGLE_NODE_PERSON_1); + public void distinctWithTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (p:Person) WITH Distinct(p) Return p " ); - assert res.getData().length == 2 ; + GraphResult res = execute( "MATCH (p:Person) WITH Distinct(p) Return p " ); + assert res.getData().length == 2; } + + @Test - public void existsWithTest() - { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + public void existsWithTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age;" ); - assert containsRows( res , true , true , Row.of( TestLiteral.from( "Ann" ),TestLiteral.from( 45 ) )); + GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age;" ); + assert containsRows( res, true, true, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } - - @Test - public void conditionalLogicWithTest() - { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ) ; + public void conditionalLogicWithTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p, CASE WHEN p.age < 30 THEN 'Young' THEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' ELSE 'Elderly END AS ageGroup RETURN p.name, ageGroup;" ) ; - assert containsRows( res , true , true , - Row.of( TestLiteral.from( "Ana" ) , TestLiteral.from( "Middle-aged" ) ) , - Row.of( TestLiteral.from( "Bob" ) , TestLiteral.from( "Middle-aged" ) ), - Row.of( TestLiteral.from( "Alex" ) , TestLiteral.from( "Middle-aged" ) )); + GraphResult res = execute( "MATCH (p:Person) WITH p, CASE WHEN p.age < 30 THEN 'Young' THEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' ELSE 'Elderly END AS ageGroup RETURN p.name, ageGroup;" ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( "Ana" ), TestLiteral.from( "Middle-aged" ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( "Middle-aged" ) ), + Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( "Middle-aged" ) ) ); } + @Test - public void orderByWithTest() - { + public void orderByWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p.name" ); + GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p.name" ); - assert containsRows( res , true ,true , - Row.of( TestLiteral.from( "Hans" )) , - Row.of( TestLiteral.from( "Max" )) ); + assert containsRows( res, true, true, + Row.of( TestLiteral.from( "Hans" ) ), + Row.of( TestLiteral.from( "Max" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java index 2004858eda..032e9a09a4 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java @@ -87,7 +87,7 @@ public void simpleMatchSinglePropertyTest() { GraphResult res = execute( "MATCH (n {name: 'Max'}) RETURN n" ); assertNode( res, 0 ); - containsNodes( res, true, MAX ); + assert containsNodes( res, true, HANS ); res = execute( "MATCH (n {name: 'Hans'}) RETURN n" ); assertNode( res, 0 ); @@ -173,7 +173,6 @@ public void simpleEdgeTest() { } - @Test public void emptyEdgeTest() { execute( SINGLE_EDGE_1 ); @@ -201,8 +200,7 @@ public void singleEdgeFilterMatchNodeTest() { execute( SINGLE_EDGE_1 ); execute( SINGLE_EDGE_2 ); GraphResult res = execute( "MATCH (n:Person)-[r:KNOWS {since: 1994}]->() RETURN n" ); - - assert containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ) ); } @@ -430,7 +428,7 @@ public void returnAllElementsByAsteriskMatchTest() { GraphResult res = execute( "MATCH Path = (p) -[r] ->(m) RETURN *" ); assert containsRows( res, true, false, Row.of( TestPath.of( MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) - ,MAX , TestEdge.from(List.of("OWNER_OF") ) ,KIRA ) ); + , MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ); } @@ -438,7 +436,7 @@ assert containsRows( res, true, false, public void returnEdgesByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH ()-[r]-() RETURN *" ); - assert containsEdges( res, true,TestEdge.from( List.of( "OWNER_OF" ) ) ); + assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); } @@ -460,6 +458,4 @@ assert containsRows( res, true, true, } - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java index 63a10b2bd6..cbc4709ceb 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java @@ -70,7 +70,7 @@ assert containsRows( res, true, false, public void twoNodeDeleteTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (p:Person {name: 'Max'}), (h:Person {name: 'Hans'})\n" + GraphResult res = execute( "MATCH (p:Person {name: 'Max'}), (h:Person {name: 'Hans'})\n" + "DELETE p, h" ); assertEmpty( res ); } @@ -112,9 +112,7 @@ assert containsRows( res, true, false, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), - Pair.of( "age", 31 )))); - - + Pair.of( "age", 31 ) ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java index a303e5b871..cb55a02e80 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java @@ -121,4 +121,15 @@ public void updateRelationshipNewPropertyTest() { + "SET rel.status = 'fresh'" ); } + + @Test + public void updateCaseWhenTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( "MATCH (n {name: 'Ann'})\n" + + "SET (CASE WHEN n.age = 45 THEN n END).worksIn = 'Malmo'\n" + + "RETURN n.name, n.worksIn" ); + + + } + } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java index bfbcaeb6df..d2ea48ebf4 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java @@ -378,16 +378,13 @@ assert containsRows( res, true, true, res = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); assert res.getData().length == 3; assert containsEdges( res, true, TestEdge.from( List.of( "HAS_CHAUFFEUR" ) ) ); - execute( "MATCH (person:Person)\n" + execute( "MATCH (person:Person)\n" + "MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName})\n" ); - GraphResult edges = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); - GraphResult nodes = execute( "MATCH (n:Chauffeur) RETURN Chauffeur" ); - assert edges.getData().length == 3 && nodes.getData().length == 3 ; + GraphResult edges = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); + GraphResult nodes = execute( "MATCH (n:Chauffeur) RETURN Chauffeur" ); + assert edges.getData().length == 3 && nodes.getData().length == 3; } - - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java index e2f86c8801..913a01692e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java @@ -70,12 +70,12 @@ public void returnWithRemoveTest() { public void multipleLabelsRemoveTest() { execute( SINGLE_NODE_PERSON_EMPLOYEE ); - GraphResult res = matchAndReturnAllNodes() ; - assert containsNodes( res, true, TestNode.from(List.of("Person" , "Employee") )); + GraphResult res = matchAndReturnAllNodes(); + assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ) ) ); - execute( "MATCH (n) REMOVE n:Person:Employee " ); - res = execute( "MATCH (n :Person:Employee) RETURN n" ); - assert res.getData().length == 0 ; + execute( "MATCH (n) REMOVE n:Person:Employee " ); + res = execute( "MATCH (n :Person:Employee) RETURN n" ); + assert res.getData().length == 0; } @@ -95,8 +95,8 @@ public void singlePropertyNodeRemoveTest() { @Test public void multiplePropertiesRemoveTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( "MATCH (n:Person {name: 'Ann'})\n" - + "REMOVE n.age, n.depno\n" ); + execute( "MATCH (n:Person {name: 'Ann'})\n" + + "REMOVE n.age, n.depno\n" ); GraphResult res = execute( "MATCH (n : Person) RETURN n.age , n.depno , n.name " ); assert containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); From c7ed8c2c24231ea1ac6a125b919262ad23b2a49d Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sat, 17 Aug 2024 06:27:26 +0300 Subject: [PATCH 46/55] add more coverage test for update clause --- .../db/cypher/clause/write/DmlUpdateTest.java | 80 ++++++++++++++++++- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java index cb55a02e80..7ef05310c2 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; +import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; @@ -86,17 +87,50 @@ assert containsRows( res, true, true, public void updateVariablesIncrementTest() { execute( SINGLE_NODE_PERSON_1 ); execute( "MATCH (a:Person {name: 'Max'})\n" - + "SET a = { age: 13, job: 'Developer'} " ); + + "SET a = { name : 'Max' , age: 13, job: 'Developer'} " ); GraphResult res = matchAndReturnAllNodes(); assert containsRows( res, true, true, Row.of( TestNode.from( List.of( "Person" ), + Pair.of( "name", "Max" ), Pair.of( "age", 13 ), Pair.of( "job", "Developer" ) ) ) ); } + @Test + public void updateVariablesDecrementTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( "MATCH (p {name: 'Ann'})\n" + + "SET p = {name: 'Ann Smith'}" ); + + GraphResult res = matchAndReturnAllNodes(); + containsNodes( res, true, + TestNode.from( List.of( "Person" ), + Pair.of( "name", "'Ann Smith" ) ) ); + + } + + + @Test + public void updateVariablesIncrementAndDecrementTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( "MATCH (p {name: 'Ann'})\n" + + "SET p = {name: 'Peter Smith', position: 'Entrepreneur'}\n" + + "RETURN p.name, p.age, p.position" ); + + GraphResult res = matchAndReturnAllNodes(); + assert containsRows( res, true, true, + Row.of( TestNode.from( + List.of( "Person" ), + Pair.of( "name", "Peter Smith" ), + Pair.of( "position", "Entrepreneur" ) ) ) ); + + + } + + @Test @Disabled // Extension of Cypher implementation required public void updatePropertyReturnTest() { @@ -126,10 +160,50 @@ public void updateRelationshipNewPropertyTest() { public void updateCaseWhenTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( "MATCH (n {name: 'Ann'})\n" - + "SET (CASE WHEN n.age = 45 THEN n END).worksIn = 'Malmo'\n" - + "RETURN n.name, n.worksIn" ); + + "SET (CASE WHEN n.age = 45 THEN n END).worksIn = 'Malmo" ); + GraphResult res = matchAndReturnAllNodes(); + containsNodes( res, true, + TestNode.from( List.of( "Person" ), + Pair.of( "name", "Ann" ), + Pair.of( "worksIn", "Malmo" ) ) ); + execute( "MATCH (n {name: 'Ann'})\n" + + "SET (CASE WHEN n.age = 45 THEN n END).name = 'Max" + + "RETURN n.name, n.age" ); + + containsNodes( res, true, + TestNode.from( List.of( "Person" ), + Pair.of( "name", "Max" ), + Pair.of( "age", 45 ) ) ); } + + @Test + public void updatePropertyWithNullTest() { + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( "MATCH (n {name: 'Ann'})\n" + + "SET n.name = null\n" ); + + GraphResult res = matchAndReturnAllNodes(); + containsNodes( res, true, + TestNode.from( List.of( "Person" ), + Pair.of( "age", 54 ) ) ); + } + + + @Test + public void updateMultiplePropertiesWithOneSetTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( "MATCH (n {name: 'Max'})\n" + + "SET n.position = 'Developer', n.surname = 'Taylor'" ); + GraphResult res = matchAndReturnAllNodes(); + containsNodes( res, true, + TestNode.from( List.of( "Person" ), + Pair.of( "name", "Max" ), + Pair.of( "position", "Developer" ), + Pair.of( "surname", "Taylor " ) ) ); + } + + } From f71f5d093b979580b729798e479b8ca12fd688b7 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 18 Aug 2024 15:13:06 +0300 Subject: [PATCH 47/55] "Refactor: Replace Java assert statements with JUnit5 assertions for improved testing consistency and readability." --- .../db/cypher/CypherTestTemplate.java | 70 +++++----- .../db/cypher/Functions/AggregateTest.java | 64 ++++----- .../db/cypher/Functions/ListFunTest.java | 22 +-- .../db/cypher/Functions/NumericFunTest.java | 42 +++--- .../db/cypher/Functions/OtherFunTest.java | 10 +- .../db/cypher/Functions/SpatialFunTest.java | 4 +- .../db/cypher/Functions/StringFunTest.java | 42 +++--- .../db/cypher/Functions/TemporalFunTest.java | 82 +++++------ .../db/cypher/Operators/BooleanOperators.java | 18 +-- .../Operators/ComparisonOperations.java | 16 +-- .../db/cypher/Operators/ListOperators.java | 8 +- .../Operators/MathematicalOperators.java | 12 +- .../db/cypher/Operators/StringOperators.java | 2 +- .../cypher/Subqueries/CallSubqueriesTest.java | 24 ++-- .../Subqueries/CollectSubQueriesTest.java | 14 +- .../Subqueries/CountSubQueriesTest.java | 14 +- .../Subqueries/ExistsSubQueriesTest.java | 14 +- .../db/cypher/clause/general/CallTest.java | 25 ++-- .../db/cypher/clause/general/CaseTest.java | 63 +++------ .../db/cypher/clause/general/FilterTest.java | 48 +++---- .../db/cypher/clause/general/LimitTest.java | 28 ++-- .../db/cypher/clause/general/OrderByTest.java | 129 ++++++++---------- .../db/cypher/clause/general/SkipTest.java | 14 +- .../db/cypher/clause/general/UnionTest.java | 13 +- .../db/cypher/clause/general/UnwindTest.java | 22 +-- .../db/cypher/clause/general/WithTest.java | 59 ++++---- .../db/cypher/clause/read/MatchTest.java | 64 ++++----- .../db/cypher/clause/write/DmlDeleteTest.java | 15 +- .../db/cypher/clause/write/DmlInsertTest.java | 129 +++++++++--------- .../db/cypher/clause/write/DmlUpdateTest.java | 12 +- .../db/cypher/clause/write/ForeachTest.java | 18 +-- .../db/cypher/clause/write/MergeTest.java | 63 +++++---- .../db/cypher/clause/write/RemoveTest.java | 22 +-- 33 files changed, 581 insertions(+), 601 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java index 876cb2d629..1f66ec83eb 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java @@ -17,6 +17,8 @@ package org.polypheny.db.cypher; import static java.lang.String.format; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; @@ -190,13 +192,13 @@ public static boolean containsRows( GraphResult actual, boolean exclusive, boole i++; } - assert !exclusive || actual.getData().length >= rows.length; + // Use assert to validate exclusive condition + assertTrue(!exclusive || actual.getData().length >= rows.length, "Exclusive condition failed: actual data has fewer rows than expected."); + + + // Use the appropriate matching method based on the 'ordered' flag + return ordered ? matchesExactRows(parsed, rows) : matchesUnorderedRows(parsed, rows); - if ( ordered ) { - return matchesExactRows( parsed, rows ); - } else { - return matchesUnorderedRows( parsed, rows ); - } } catch ( Throwable t ) { fail( "Error while evaluating result: " + t.getMessage() ); throw new RuntimeException(); @@ -204,60 +206,54 @@ public static boolean containsRows( GraphResult actual, boolean exclusive, boole } - private static boolean matchesUnorderedRows( List> parsed, Row[] rows ) { - + private static boolean matchesUnorderedRows(List> parsed, Row[] rows) { List used = new ArrayList<>(); - for ( Row row : rows ) { - int i = 0; + for (Row row : rows) { boolean matches = false; - for ( List objects : parsed ) { - if ( !matches && !used.contains( i ) ) { - if ( row.matches( objects ) ) { - used.add( i ); - matches = true; - } + for (int i = 0; i < parsed.size(); i++) { + if (!matches && !used.contains(i) && row.matches(parsed.get(i))) { + used.add(i); + matches = true; + break; } - - i++; - } - if ( !matches ) { - return false; } + + // Use assert to validate that each row finds a match + assertTrue(matches, "Row " + row + " could not be matched in the parsed data."); } return true; - } - private static boolean matchesExactRows( List> parsed, Row[] rows ) { - boolean matches = true; - int j = 0; - for ( Row row : rows ) { - matches &= row.matches( parsed.get( j ) ); - j++; + + private static boolean matchesExactRows(List> parsed, Row[] rows) { + for (int j = 0; j < rows.length; j++) { + // Use assert to ensure each row matches + assertTrue(rows[j].matches(parsed.get(j)), "Row " + j + " does not match the expected value."); } - return matches; + return true; } @SneakyThrows - private boolean contains( String[][] actual, boolean exclusive, int index, Class clazz, TestObject[] expected ) { + private boolean contains(String[][] actual, boolean exclusive, int index, Class clazz, TestObject[] expected) { List parsed = new ArrayList<>(); - for ( String[] entry : actual ) { - parsed.add( PolyValue.JSON_WRAPPER.readValue( entry[index], clazz ) ); + for (String[] entry : actual) { + parsed.add(PolyValue.JSON_WRAPPER.readValue(entry[index], clazz)); } - assert !exclusive || parsed.size() == expected.length; + // Assert that if exclusive is true, the number of parsed items equals the number of expected items + assertEquals(exclusive ? expected.length : parsed.size(), parsed.size(), "Exclusive condition failed: parsed size does not match expected length."); - boolean contains = true; - for ( TestObject node : expected ) { - contains &= parsed.stream().anyMatch( n -> node.matches( n, exclusive ) ); + for (TestObject node : expected) { + // Assert that each expected node matches at least one parsed element + assertTrue(parsed.stream().anyMatch(n -> node.matches(n, exclusive)), "Expected node does not match any parsed element."); } - return contains; + return true; } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java index a2b97e7266..3475891c56 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java @@ -50,13 +50,13 @@ public void singleCountAggregateTest() { GraphResult res = execute( "MATCH (n:Person) RETURN count(*)" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); execute( SINGLE_EDGE_2 ); res = execute( "MATCH (n:Person) RETURN count(*)" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 7 ) ) ); @@ -72,7 +72,7 @@ public void countFieldAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN n.name, count(*)" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 2 ) ) ); @@ -85,7 +85,7 @@ public void countNullAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN count(*)" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 0 ) ) ); } @@ -98,9 +98,9 @@ public void countRenameFieldAggregateTest() { execute( SINGLE_EDGE_2 ); GraphResult res = execute( "MATCH (n) RETURN n.name, count(*) AS c" ); - assert res.getHeader()[1].name.equals( "c" ); + res.getHeader()[1].name.equals( "c" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 2 ) ) ); @@ -117,7 +117,7 @@ public void doubleCountRenameAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN n.name, n.age, count(*) AS c" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( null ), TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 3 ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( null ), TestLiteral.from( 1 ) ), @@ -131,7 +131,7 @@ public void countPropertyAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n) RETURN count(n.age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 0 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 0 ) ) ); } @@ -141,7 +141,7 @@ public void countDistinctFunctionTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( "MATCH (n) RETURN COUNT(DISTINCT n.name)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } @@ -160,7 +160,7 @@ public void singleAvgAggregateTest() { // Printing the data using Arrays.deepToString String[][] data = res.getData(); System.out.println( Arrays.deepToString( data ) ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 26.33333333333333 ) ) ); } @@ -172,7 +172,7 @@ public void avgNullAggregateTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN AVG(p.age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); } @@ -183,7 +183,7 @@ public void avgRenameAggregationTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN AVG(p.age) AS ages" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); } @@ -208,7 +208,7 @@ public void singleCollectAggregationTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age) " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); } @@ -219,7 +219,7 @@ public void collectRenameAggregationTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age) AS ages" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); } @@ -231,7 +231,7 @@ public void collectRenameFieldAggregationTest() { execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age) AS ages , p.depno AS depNumber" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ), TestLiteral.from( 13 ) ), Row.of( TestLiteral.from( List.of( 32 ) ), TestLiteral.from( 14 ) ) ); } @@ -242,7 +242,7 @@ public void collectNullAggregationTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( null, null ) ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( null, null ) ) ) ); } @@ -255,11 +255,11 @@ public void singleMinMaxAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); GraphResult res = execute( "MATCH (n) RETURN min(n.age)" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "MATCH (n) RETURN max(n.age)" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); } @@ -271,12 +271,12 @@ void minMaxNullAggregateTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); res = execute( "MATCH (n) RETURN max(n.age) as ageMax" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); @@ -291,12 +291,12 @@ public void minMaxRenameAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); res = execute( "MATCH (n) RETURN max(n.age) as ageMax" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); @@ -312,13 +312,13 @@ public void minMaxRenameFieldAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN n.depno as depNumber , min(n.age) as ageMin" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 13 ), TestLiteral.from( 31 ) ), Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); res = execute( "MATCH (n) RETURN n.depno as depNumber , max(n.age) as ageMax" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 13 ), TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); @@ -333,7 +333,7 @@ public void singleSumAggregateTest() { execute( SINGLE_EDGE_2 ); GraphResult res = execute( "MATCH (n) RETURN sum(n.age)" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 34 ) ) ); } @@ -344,7 +344,7 @@ public void sumNullAggregationTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n) RETURN sum(n.age)" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 0 ) ) ); /// Printing the data using Arrays.deepToString @@ -361,7 +361,7 @@ public void sumRenameAggregationTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN sum(p.age) As totalAge " ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); @@ -375,7 +375,7 @@ public void sumRenameFieldAggregationTest() { execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (p:Person) RETURN sum(p.age) AS totalAge, p.depno AS depNumber," ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 13 ), TestLiteral.from( 76 ) ), Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); @@ -388,7 +388,7 @@ public void singleStDevAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) " ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 9.8994949 ) ) ); @@ -400,7 +400,7 @@ public void stDevNullAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) " ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); } @@ -410,7 +410,7 @@ public void stDevRenameAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) AS Stdev " ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 9.8994949 ) ) ); } @@ -422,7 +422,7 @@ public void stDevRenameFieldAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) AS Stdev , n.depno As department" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 9.8994949 ), TestLiteral.from( 13 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java index c9aeda5831..1980524844 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java @@ -23,6 +23,8 @@ import org.polypheny.db.webui.models.results.GraphResult; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ListFunTest extends CypherTestTemplate { @BeforeEach @@ -35,7 +37,7 @@ public void reset() { @Test public void simpleSizeFunTest() { GraphResult res = execute( "RETURN size([1, 2, 3])" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); } @@ -43,7 +45,7 @@ assert containsRows( res, true, true, @Test public void nullSizeFunTest() { GraphResult res = execute( "RETURN size(null)" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } @@ -56,7 +58,7 @@ public void patternExpressionSizeFunTest() { + "WHERE a.name = 'Max'\n" + "RETURN size((a)-[]->())) AS fof" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 2 ) ) ); } @@ -68,7 +70,7 @@ public void stringSizeFunTest() { GraphResult res = execute( "MATCH (a) RETURN size(a.name)" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); } @@ -78,7 +80,7 @@ public void simpleRangeFunTest() { GraphResult res = execute( "RETURN RANGE(1, 3)" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 1 ), TestLiteral.from( 2 ), TestLiteral.from( 3 ) ) ); } @@ -89,7 +91,7 @@ public void returnLabelsFunTest() { GraphResult res = execute( "MATCH (a)" + "RETURN labels(a)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Person" ) ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Person" ) ) ) ); } @@ -98,8 +100,8 @@ public void returnNodesFunTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + "RETURN nodes(p)" ); - assert res.getData().length == 1; - assert containsRows( res, true, false, Row.of( TestLiteral.from( List.of( MAX, KIRA ) ) ) ); + assertEquals( 1, res.getData().length ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( MAX, KIRA ) ) ) ); } @@ -109,7 +111,7 @@ public void returnRelationsFunTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + "RETURN relationships(p)" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -118,7 +120,7 @@ public void returnRelationAndNodesFunTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH p = (a)-->(b)-->(c)\n" + "RETURN relationships(p) , nodes(p)" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java index 7762b0ae79..7e2f153239 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java @@ -35,32 +35,32 @@ public void reset() { public void absFunTest() { GraphResult res = execute( "RETURN ABS(-5) " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); res = execute( "RETURN ABS(5)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); res = execute( "RETURN ABS(0)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); } @Test public void roundFunTest() { GraphResult res = execute( "RETURN ROUND(3)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN ROUND(-3)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); res = execute( "RETURN ROUND(3.4)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN ROUND(3.5)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN ROUND(-3.5)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); } @@ -70,35 +70,35 @@ public void roundFunTest() { public void floorFunTest() { GraphResult res = execute( "RETURN FLOOR(3)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN FLOOR(-3)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); res = execute( "RETURN FLOOR(3.16)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN FLOOR(3.9)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN FLOOR(-3.16)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); } @Test public void ceilFunTest() { GraphResult res = execute( "RETURN CEIL(3)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN CEIL(-3)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN CEIL(3.16)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN CEIL(3.5)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); } @@ -106,24 +106,24 @@ public void ceilFunTest() { @Test public void sqrtFunTest() { GraphResult res = execute( "RETURN SQRT(9)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN SQRT(0)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); } @Test public void nonPerfectSquareSqrtFunTest() { GraphResult res = execute( "RETURN SQRT(8)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( Math.sqrt( 8 ) ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( Math.sqrt( 8 ) ) ) ); } @Test public void sqrtFunTestNegative() { GraphResult res = execute( "RETURN SQRT(-9)" ); - // assert containsRows(res, true, true, Row.of(TestLiteral.from(null))); + // containsRows(res, true, true, Row.of(TestLiteral.from(null))); } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java index fba3d90635..45de224f50 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java @@ -43,7 +43,7 @@ public void typeFunTest() { GraphResult res = execute( "MATCH (a)-[r]->(b)\n" + "RETURN TYPE(r)\n" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "OWNER_OF" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "OWNER_OF" ) ) ); } @@ -64,7 +64,7 @@ public void testCoalesceFunTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); GraphResult result = execute( "MATCH (p) RETURN p.name, coalesce(p.age, 0) AS age" ); - assert containsRows( result, true, false, + containsRows( result, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 0 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 0 ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); @@ -80,7 +80,7 @@ public void testDefaultValuesWithCoalesceFunTest() { assertNode( result, 0 ); - assert containsRows( result, true, false, + containsRows( result, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "unknown" ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( "unknown" ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( "unknown" ) ) ); @@ -96,12 +96,12 @@ public void ExistFunTest() { GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" + "RETURN EXISTS(p.age)\n" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( false ) ) ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( "MATCH (p:Person { name: 'Ann' })\n" + "RETURN EXISTS(p.age)\n" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( true ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java index 67a00c79d1..6900dab39f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java @@ -42,7 +42,7 @@ public void cartesian2DPointFunTest() { + " p.crs AS crs,\n" + " p.srid AS srid" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 3.0 ), TestLiteral.from( 4.0 ), TestLiteral.from( "cartesian" ), TestLiteral.from( 7203 ) ) ); } @@ -61,7 +61,7 @@ public void WGS_843DPointFunTest() { + " p.crs AS crs,\n" + " p.srid AS srid" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 3.0 ), TestLiteral.from( 4.0 ), TestLiteral.from( 4321.0 ), diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java index b9a1183cf2..527496e428 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java @@ -34,9 +34,9 @@ public void reset() { @Test public void upperFunTest() { GraphResult res = execute( "RETURN UPPER('hello')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); res = execute( "RETURN UPPER('hElLo')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); } @@ -45,85 +45,85 @@ public void upperFunTest() { @Test public void EmptyUpperFunTest() { GraphResult res = execute( "RETURN UPPER('')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void nullUpperFunTest() { GraphResult res = execute( "RETURN UPPER(null)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } @Test public void LowerFunTest() { GraphResult res = execute( "RETURN LOWER('WORLD')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); res = execute( "RETURN LOWER('WOrLd')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); } @Test public void emptyLowerFunTest() { GraphResult res = execute( "RETURN LOWER('')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void nullLowerFunTest() { GraphResult res = execute( "RETURN LOWER(null)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } @Test public void normalSubstringFunTest() { GraphResult res = execute( "RETURN SUBSTRING('Hello, world!', 0, 5)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); res = execute( "RETURN SUBSTRING('Hello, world!', 7, 5)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); res = execute( "RETURN SUBSTRING('Hello, world!', 7, 0)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void exceedLengthSubstringFunTest() { GraphResult res = execute( "RETURN SUBSTRING('Hello', 0, 10)" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); } @Test public void trimFunTest() { GraphResult res = execute( "RETURN TRIM(' hello ')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); res = execute( "RETURN TRIM('hello')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); res = execute( "RETURN TRIM(' ')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void emptyTrimFunTest() { GraphResult res = execute( "RETURN TRIM('')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void normalReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', 'Cypher') " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); } @@ -131,28 +131,28 @@ public void normalReplaceFunTest() { @Test public void caseSensitiveReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'WORLD', 'Cypher')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, world!" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, world!" ) ) ); } @Test public void removeSpacesReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', ' ', '')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello,world!" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello,world!" ) ) ); } @Test public void removeSubstringReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', '')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, !" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, !" ) ) ); } @Test public void stringLengthFunTest() { GraphResult res = execute( "RETURN LENGTH('Hello, world!')" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 13 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 13 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java index ea5eabd2a9..adb973d2b9 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java @@ -35,19 +35,19 @@ public void reset() { public void stringIntoDateFunTest() { GraphResult res = execute( "RETURN date('2015-07-21')\n" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); res = execute( "RETURN date('2015-07')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); res = execute( "RETURN date('201507')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); res = execute( "RETURN date('2015-W30-2')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); res = execute( "RETURN date('2015')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01" ) ) ); } @@ -55,29 +55,29 @@ public void stringIntoDateFunTest() { public void yearMonthDayDateFunTest() { GraphResult res = execute( "RETURN date({year: 1984, month: 10, day: 11})" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11" ) ) ); res = execute( "RETURN date({year: 1984, month: 10})" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-01" ) ) ); res = execute( "RETURN date({year: 1984})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-01-01" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-01-01" ) ) ); } @Test public void yearWeekDayDateFunTest() { GraphResult res = execute( "RETURN date({year: 1984, week: 10, dayOfWeek: 3})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07" ) ) ); } @Test public void yearQuarterDayDateFunTest() { GraphResult res = execute( "RETURN date({year: 1984, quarter: 3, dayOfQuarter: 45})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14" ) ) ); } @@ -85,13 +85,13 @@ public void yearQuarterDayDateFunTest() { public void yearMonthDayZonedTimeDateFunTest() { GraphResult res = execute( "RETURN datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 123, microsecond: 456, nanosecond: 789}) AS theDate" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.123456789Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.123456789Z" ) ) ); res = execute( "datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 645, timezone: '+01:00'})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.645+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.645+01:00" ) ) ); res = execute( "RETURN datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14Z" ) ) ); } @@ -100,14 +100,14 @@ public void yearMonthDayZonedTimeDateFunTest() { @Test public void yearWeekDayTimeDateFunTest() { GraphResult res = execute( "RETURN datetime({year: 1984, week: 10, dayOfWeek: 3, hour: 12, minute: 31, second: 14, millisecond: 645})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07T12:31:14.645Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07T12:31:14.645Z" ) ) ); } @Test public void yearQuarterDayTimeDateFunTest() { GraphResult res = execute( "RETURN datetime({year: 1984, quarter: 3, dayOfQuarter: 45, hour: 12, minute: 31, second: 14, microsecond: 645876})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14T12:31:14.645876Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14T12:31:14.645876Z" ) ) ); } @@ -116,22 +116,22 @@ public void yearQuarterDayTimeDateFunTest() { public void stringIntoTimeDateFunTest() { GraphResult res = execute( "RETURN datetime('2015-07-21T21:40:32.142+0100')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142+01:00" ) ) ); res = execute( "RETURN datetime('2015-W30-2T214032.142Z')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142Z" ) ) ); res = execute( "RETURN datetime('2015T214032-0100')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01T21:40:32-01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01T21:40:32-01:00" ) ) ); res = execute( "RETURN datetime('20150721T21:40-01:30')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40-01:30" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40-01:30" ) ) ); res = execute( "RETURN datetime('2015-07-21T21:40:32.142[Europe/London]')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "datetime('2015-07-21T21:40:32.142[Europe/London]')" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "datetime('2015-07-21T21:40:32.142[Europe/London]')" ) ) ); } @@ -140,19 +140,19 @@ public void stringIntoTimeDateFunTest() { public void timeFunTest() { GraphResult res = execute( "RETURN time({hour: 12, minute: 31, second: 14, millisecond: 123, microsecond: 456, nanosecond: 789})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.123456789Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.123456789Z" ) ) ); res = execute( "RETURN time({hour: 12, minute: 31, second: 14, nanosecond: 645876123})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876123Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876123Z" ) ) ); res = execute( "RETURN time({hour: 12, minute: 31, second: 14, microsecond: 645876, timezone: '+01:00'})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876000+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876000+01:00" ) ) ); res = execute( "time({hour: 12, minute: 31, timezone: '+01:00'})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:00+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:00+01:00" ) ) ); res = execute( "RETURN time({hour: 12, timezone: '+01:00'})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "12:00:00+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:00:00+01:00" ) ) ); } @@ -160,16 +160,16 @@ public void timeFunTest() { @Test public void stringIntoTimeFunTest() { GraphResult res = execute( "RETURN time('21:40:32.142+0100')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000+01:00" ) ) ); res = execute( "RETURN time('214032.142Z')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000Z" ) ) ); res = execute( "RETURN time('21:40:32+01:00')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32+01:00" ) ) ); res = execute( "RETURN time('214032-0100')" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32-01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32-01:00" ) ) ); } @@ -179,22 +179,22 @@ public void stringIntoTimeFunTest() { public void durationFunTest() { GraphResult res = execute( "RETURN duration({days: 14, hours:16, minutes: 12})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); res = execute( "RETURN duration({months: 5, days: 1.5})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); res = execute( "RETURN duration({months: 0.75})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); res = execute( "RETURN duration({weeks: 2.5})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P17DT12H" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P17DT12H" ) ) ); res = execute( "RETURN duration({minutes: 1.5, seconds: 1, milliseconds: 123, microseconds: 456, nanoseconds: 789})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); res = execute( "RETURN duration({minutes: 1.5, seconds: 1, nanoseconds: 123456789})" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); } @@ -203,18 +203,18 @@ public void durationFunTest() { @Test public void stringIntoDurationFunTest() { GraphResult res = execute( "RETURN duration(\"P14DT16H12M\") " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); res = execute( "RETURN duration(\"P5M1.5D\")" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); res = execute( "RETURN duration(\"P0.75M\") " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); res = execute( "RETURN duration(\"PT0.75M\")" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "PT45S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "PT45S" ) ) ); res = execute( "RETURN duration(\"P2012-02-02T14:37:21.545\")" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P2012Y2M2DT14H37M21.545S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P2012Y2M2DT14H37M21.545S" ) ) ); } @@ -223,7 +223,7 @@ public void stringIntoDurationFunTest() { @Test public void durationBetweenFunTest() { GraphResult res = execute( "RETURN duration.between(date('1984-10-11'), date('2015-06-24')) AS theDuration" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "P30Y8M13D" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P30Y8M13D" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java index 4b3735d85d..a547accbe5 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java @@ -35,9 +35,9 @@ public void setUp() { @Test public void conjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a AND b " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH true as a , true as b RETURN a AND b " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @@ -45,9 +45,9 @@ public void conjunctionOperatorTest() { @Test public void disjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a OR b " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "WITH false as a , false as b RETURN a OR b " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @@ -55,11 +55,11 @@ public void disjunctionOperatorTest() { @Test public void exclusiveDisjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a XOR b " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "WITH true as a , true as b RETURN a XOR b " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH false as a , false as b RETURN a XOR b " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @@ -67,10 +67,10 @@ public void exclusiveDisjunctionOperatorTest() { @Test public void negationOperatorTest() { GraphResult res = execute( "WITH true as a RETURN NOT a " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH false as a RETURN NOT a " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java index 85e8abe5d1..87afb96ddf 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java @@ -34,14 +34,14 @@ public void setUp() { @Test public void IsNullOperatorTest() { GraphResult res = execute( "Return null is not null as Result" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @Test public void IsNotNullFunction() { GraphResult res = execute( "Return null is null as Result" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @@ -49,42 +49,42 @@ public void IsNotNullFunction() { @Test public void greaterThanOperatorTest() { GraphResult res = execute( "Return 1 > 2 as result " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @Test public void smallerThanOperatorTest() { GraphResult res = execute( "Return 1 < 2 as result " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @Test public void greaterThanOrEqualOperatorTest() { GraphResult res = execute( "Return 1 >= 2 as result " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @Test public void smallerThanOrEqualOperatorTest() { GraphResult res = execute( "Return 1 <= 2 as result " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @Test public void equalityOperatorTest() { GraphResult res = execute( "Return 2 = 2 as result " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @Test public void inequalityOperatorTest() { GraphResult res = execute( "Return 1 <> 2 as result " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java index 81c3043d37..10a68b5c19 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java @@ -35,20 +35,20 @@ public void setUp() { @Test public void checkIfNumberInListOperatorTest() { GraphResult res = execute( "RETURN 1 IN [ 1 ,2 ]" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "RETURN 3 IN [ 1 ,2 ]" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @Test public void checkIfListInListOperatorTest() { GraphResult res = execute( "RETURN [2, 1] IN [1, [2, 1], 3] " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "RETURN [1, 2] IN [1, 2] " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java index 0f821ba4d0..06cccbb6a9 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java @@ -36,7 +36,7 @@ public void reset() { @Test public void additionOperator() { GraphResult res = execute( "RETURN 2 + 3" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 5 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 5 ) ) ); } @@ -44,7 +44,7 @@ public void additionOperator() { public void minisOperatorTest() { GraphResult res = execute( "RETURN 3 - 2" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } @@ -53,7 +53,7 @@ public void minisOperatorTest() { public void multiplicationOperatorTest() { GraphResult res = execute( "RETURN 2 * 3" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 6 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 6 ) ) ); } @@ -61,14 +61,14 @@ public void multiplicationOperatorTest() { public void divisionOperatorTest() { GraphResult res = execute( "RETURN 6 / 3 " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @Test public void moduleOperatorTest() { GraphResult res = execute( "RETURN 3 % 2 " ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } @@ -77,7 +77,7 @@ public void moduleOperatorTest() { public void exponentiationOperator() { GraphResult res = execute( "RETURN 2 ^ 3" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 8.0 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 8.0 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java index 048b17d68a..861d71a58e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java @@ -35,7 +35,7 @@ public void setUp() { @Test public void concatenateWithPlusOperatorTest() { GraphResult res = execute( "RETURN 'neo' + '4j' AS result" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "neo4j" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "neo4j" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java index a41e7d2887..501d0da942 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java @@ -27,6 +27,8 @@ import java.util.List; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class CallSubqueriesTest extends CypherTestTemplate { @@ -43,7 +45,7 @@ public void simpleCallTest() { GraphResult res = execute( " CALL { RETURN 'hello' AS innerReturn} \n" + "RETURN innerReturn" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "hello" ) ) ); } @@ -54,7 +56,7 @@ public void repeatCallTest() { + "CALL { RETURN 'hello' AS innerReturn }\n" + "RETURN innerReturn" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "hello" ) ), Row.of( TestLiteral.from( "hello" ) ), Row.of( TestLiteral.from( "hello" ) ) ); @@ -67,7 +69,7 @@ public void unwindVariablesAsInputsIntoCallTest() { + "CALL { WITH x RETURN x * 10 AS y }\n" + "RETURN x, y" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 0 ), TestLiteral.from( 0 ) ), Row.of( TestLiteral.from( 1 ), TestLiteral.from( 10 ) ), Row.of( TestLiteral.from( 2 ), TestLiteral.from( 20 ) ) ); @@ -78,7 +80,7 @@ assert containsRows( res, true, true, public void returnMatchNodesCallTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( "CALL { MATCH (p:Person) RETURN p} RETURN p " ); - assert containsRows( res, true, true, Row.of( MAX ) ); + containsRows( res, true, true, Row.of( MAX ) ); } @@ -93,7 +95,7 @@ public void countNodesCallTest() { + " RETURN count(p) AS totalPeople}\n" + "RETURN totalPeople\n" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @@ -106,7 +108,7 @@ public void countRelationshipsCallTest() { + " MATCH ()-[r]->()\n" + " RETURN count(r) AS totalRelationships }\n" + "RETURN totalRelationships\n" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @@ -123,7 +125,7 @@ public void useMatchedNodesAsInputsIntoCallTest() { + "}\n" + "RETURN p.name, friend" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Hans" ) ) ); } @@ -140,8 +142,8 @@ public void FilterMatchedNodesByOutputOfCallTest() { + "WHERE p.age > age\n" + "RETURN p\n" ); - assert res.getData().length == 2; - assert containsNodes( res, true, + assertEquals( 2, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Ann" ) ), TestNode.from( List.of( "Person" ), Pair.of( "name", "Alex" ) ) ); @@ -161,7 +163,7 @@ public void UnionCallTest() { + "}\n" + "RETURN p.name, p.age" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ) ) ); } @@ -177,7 +179,7 @@ public void unitSubQueryCallTest() { + " CREATE (:Person {name: p.name}) \n" + "} RETURN count(*)" ); //the number of rows present after the subquery is the same as was going into the subquery - assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java index f14ea5a250..bfd8f129d5 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java @@ -45,7 +45,7 @@ public void simpleCollectSubQueryTest() { + "WHERE 'Kira' IN COLLECT { MATCH (person)-[:OWNER_OF]->(a:Animal) RETURN a.name }\n" + "RETURN person.name AS name" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -61,7 +61,7 @@ public void useCollectSubQueryInReturnTest() { + " RETURN d.name\n" + " } as DogNames" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); } @@ -78,7 +78,7 @@ public void whereWithCollectSubQueryTest() { + " RETURN a.name\n" + "} as youngDog \n" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); } @@ -98,7 +98,7 @@ public void unionWithCollectSubQueryTest() { + " RETURN cat.name AS petName\n" + " } AS petNames" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( List.of( "Andy", "Mittens" ) ) ) ); @@ -116,7 +116,7 @@ public void withClauseWithCollectSubQueryTest() { + " RETURN d.name\n" + "} as dogsOfTheYear" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); } @@ -132,7 +132,7 @@ public void caseWithCollectSubQueryTest() { + " ELSE person.name\n" + " END AS result" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "No Dogs" ) ), Row.of( TestLiteral.from( "Max" ) ) ); @@ -148,7 +148,7 @@ public void updateWithCollectSubQueryTest() { + "SET person.dogNames = COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name }\n" + "RETURN person.dogNames as dogNames" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Andy" ) ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java index d029062b4d..9e048a8127 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java @@ -44,7 +44,7 @@ public void simpleCountSubQueryTest() { + "WHERE COUNT { (person)-[r:OWNER_OF]->(:Animal) } > 1\n" + "RETURN person.name AS name" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -55,7 +55,7 @@ public void useCountSubQueryInReturnTest() { GraphResult res = execute( "MATCH (person:Person)\n" + "RETURN person.name, COUNT { (person)-[:OWNER_OF]->(:Dog) } as howManyDogs" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 1 ) ) ); } @@ -71,7 +71,7 @@ public void whereWithCountSubQueryTest() { + " WHERE person.name = dog.name } = 1\n" + "RETURN person.name AS name" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -91,7 +91,7 @@ public void unionWithCountSubQueryTest() { + " RETURN cat.name AS petName\n" + " } AS numPets" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 2 ) ) ); } @@ -107,7 +107,7 @@ public void withClauseWithCountSubQueryTest() { + "} = 1\n" + "RETURN person.name AS name" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -121,7 +121,7 @@ public void updateWithCountSubQueryTest() { + "SET person.howManyDogs = COUNT { (person)-[:OWNER_OF]->(:Dog) }\n" + "RETURN person.howManyDogs as howManyDogs" ); - assert containsRows( res, true, false, Row.of( + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); @@ -138,7 +138,7 @@ public void caseWithCountSubQueryTest() { + " WHEN COUNT { (person)-[:OWNER_OF]->(:Dog) } >= 1 THEN \"DogLover \" + person.name\n" + " ELSE person.name\n" + " END AS result" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "DogLover" ) ), Row.of( TestLiteral.from( "Hans" ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java index 95f68493c8..86a4ad47f1 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java @@ -43,7 +43,7 @@ public void simpleExistsSubQueryTest() { + "}\n" + "RETURN person.name AS name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); execute( EDGE_3 ); execute( "MATCH (person:Person)\n" + "WHERE EXISTS {\n" @@ -51,7 +51,7 @@ public void simpleExistsSubQueryTest() { + "}\n" + "RETURN person.name AS name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -65,7 +65,7 @@ public void whereWithExistsSubQueryTest() { + "}\n" + "RETURN dog.name AS name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Andy" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Andy" ) ) ); } @@ -84,7 +84,7 @@ public void nestedExistsSubQueryTest() { + "}\n" + "RETURN person.name AS name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -98,7 +98,7 @@ public void returnExistsSubQueryTest() { + " MATCH (person)-[:OWNER_OF]->(:Dog)\n" + "} AS hasDog" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( true ) ) ); } @@ -116,7 +116,7 @@ public void unionWithExistsSubQueryTest() { + " UNION\n" + " MATCH (person)-[:HAS_CAT]->(:Cat)\n" + " } AS hasPet" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( true ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( false ) ) ); } @@ -132,7 +132,7 @@ public void withClauseWithExistsSubQueryTest() { + " WHERE d.name = name\n" + "}\n" + "RETURN person.name AS name" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java index 0403f7d783..51b3252eb8 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java @@ -21,7 +21,6 @@ import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; public class CallTest extends CypherTestTemplate { @@ -41,7 +40,7 @@ public void simpleCallProcedureTest() { execute( SINGLE_NODE_ANIMAL ); res = execute( "CALL db.labels()" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); @@ -50,7 +49,7 @@ assert containsRows( res, true, false, execute( SINGLE_NODE_ANIMAL ); res = execute( "CALL db.labels()" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ), @@ -65,7 +64,7 @@ public void callLabelsYieldTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "CALL db.labels() YIELD label" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); } @@ -75,7 +74,7 @@ public void renameCallLabelsYieldTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "CALL db.labels() YIELD label As Label" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); } @@ -86,7 +85,7 @@ public void callLabelsYieldCountTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "CALL db.labels() YIELD *" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) )); } @@ -96,7 +95,7 @@ public void returnCallLabelsYieldTest() { execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "CALL db.labels() YIELD label\n" + "RETURN label" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @@ -106,7 +105,7 @@ public void returnFilterCallLabelsYieldTest() { execute(SINGLE_NODE_ANIMAL); GraphResult res = execute("CALL db.labels() YIELD label WHERE label = 'Person' RETURN count(label) AS numLabels"); - assert containsRows(res, true, false, + containsRows(res, true, false, Row.of(TestLiteral.from(1))); } @@ -117,7 +116,7 @@ public void callLabelsYieldWithOrderingTest() { execute(SINGLE_NODE_ANIMAL); GraphResult res = execute("CALL db.labels() YIELD label RETURN label ORDER BY label"); - assert containsRows(res, true, false, + containsRows(res, true, false, Row.of(TestLiteral.from("Animal")), Row.of(TestLiteral.from("Person")), Row.of(TestLiteral.from("Person"))); @@ -130,7 +129,7 @@ public void callLabelsYieldWithAggregationTest() { execute(SINGLE_NODE_PERSON_2); GraphResult res = execute("CALL db.labels() YIELD label RETURN label, count(*) AS labelCount"); - assert containsRows(res, true, false, + containsRows(res, true, false, Row.of(TestLiteral.from("Person"), TestLiteral.from(2)), Row.of(TestLiteral.from("Animal"), TestLiteral.from(1))); } @@ -141,7 +140,7 @@ public void simpleCallPropertyKeysYieldTest() { execute(SINGLE_NODE_ANIMAL); execute(SINGLE_NODE_PERSON_2); GraphResult res = execute("CALL db.propertyKeys() YIELD propertyKey "); - assert containsRows(res, true, false, + containsRows(res, true, false, Row.of(TestLiteral.from("name")), Row.of(TestLiteral.from("age")), Row.of(TestLiteral.from("type"))); @@ -153,7 +152,7 @@ public void renameCallPropertyKeysYieldTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "CALL db.propertyKeys() YIELD propertyKey AS prop" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); } @@ -170,7 +169,7 @@ public void callPropertyKeysYieldWithMatchTest() + "RETURN prop, count(n) AS numNodes" ); - assert containsRows(res, true, false, + containsRows(res, true, false, Row.of(TestLiteral.from("name") , TestLiteral.from( 3 )), Row.of(TestLiteral.from("age") ,TestLiteral.from( 1)), Row.of(TestLiteral.from("type") ,TestLiteral.from( 1 ))); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java index 9be0cbac74..2f4a59fdd7 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java @@ -42,18 +42,16 @@ public void simpleCaseTest() { execute( PERSON_NODE_ALICE ); execute( PERSON_NODE_BOB ); execute( PERSON_NODE_CHARLIE ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN\n" - + "CASE n.eyes\n" - + " WHEN 'blue' THEN 1\n" - + " WHEN 'brown' THEN 2\n" - + " ELSE 3\n" - + "END AS result, n.eyes" ); + GraphResult res = execute(""" + MATCH (n:Person) + RETURN + CASE n.eyes + WHEN 'blue' THEN 1 + WHEN 'brown' THEN 2 + ELSE 3 + END AS result, n.eyes"""); - assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); } @@ -65,18 +63,9 @@ public void GenericCaseTest() { execute( PERSON_NODE_BOB ); execute( PERSON_NODE_CHARLIE ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN\n" - + "CASE\n" - + " WHEN n.eyes = 'blue' THEN 1\n" - + " WHEN n.age < 40 THEN 2\n" - + " ELSE 3\n" - + "END AS result, n.eyes, n.age" ); + GraphResult res = execute( "MATCH (n:Person)\n" + "RETURN\n" + "CASE\n" + " WHEN n.eyes = 'blue' THEN 1\n" + " WHEN n.age < 40 THEN 2\n" + " ELSE 3\n" + "END AS result, n.eyes, n.age" ); - assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); } @@ -89,18 +78,9 @@ public void nullWithCaseTest() { execute( PERSON_NODE_CHARLIE ); execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN n.name,\n" - + "CASE n.age\n" - + " WHEN null THEN -1\n" - + " ELSE n.age - 10\n" - + "END AS age_10_years_ago" ); + GraphResult res = execute( "MATCH (n:Person)\n" + "RETURN n.name,\n" + "CASE n.age\n" + " WHEN null THEN -1\n" + " ELSE n.age - 10\n" + "END AS age_10_years_ago" ); - assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 28 ) ), - Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 15 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 43 ) ), - Row.of( TestLiteral.from( "MAX" ), TestLiteral.from( null ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 28 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 15 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 43 ) ), Row.of( TestLiteral.from( "MAX" ), TestLiteral.from( null ) ) ); } @@ -112,20 +92,9 @@ public void expressionsAndSucceedingClauses() { execute( PERSON_NODE_BOB ); execute( PERSON_NODE_CHARLIE ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "WITH n,\n" - + "CASE n.eyes\n" - + " WHEN 'blue' THEN 1\n" - + " WHEN 'brown' THEN 2\n" - + " ELSE 3\n" - + "END AS colorCode\n" - + "SET n.colorCode = colorCode\n" - + "RETURN n.name, n.colorCode" ); - - assert containsRows( res, true, false, - Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); + GraphResult res = execute( "MATCH (n:Person)\n" + "WITH n,\n" + "CASE n.eyes\n" + " WHEN 'blue' THEN 1\n" + " WHEN 'brown' THEN 2\n" + " ELSE 3\n" + "END AS colorCode\n" + "SET n.colorCode = colorCode\n" + "RETURN n.name, n.colorCode" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 3452caf360..70a9107b6a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -46,7 +46,7 @@ public void nodeLabelFilterTest() { + "WHERE n:Person\n" + "RETURN n.name, n.age" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ) ) ); } @@ -60,12 +60,12 @@ public void nodePropertyFilterTest() { assertNode( result, 0 ); - assert containsRows( result, true, false ); + containsRows( result, true, false ); result = execute( "MATCH (p) WHERE p.age >= 3 RETURN p" ); assertNode( result, 0 ); - assert containsRows( result, true, false, Row.of( KIRA ) ); + containsRows( result, true, false, Row.of( KIRA ) ); } @@ -76,7 +76,7 @@ public void relationPropertyFilterTest() { + "WHERE k.since < 1995\n" + "RETURN f.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -87,7 +87,7 @@ public void NodePatternFilterTest() { GraphResult res = execute( "MATCH (a:Person WHERE a.name = 'Max')-[:KNOWS]->(b:Person WHERE b.name = 'Hans')\n" + "RETURN b.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -98,7 +98,7 @@ public void relationshipPatternFilterTest() { GraphResult res = execute( "MATCH (a:Person)-[r:KNOWS WHERE r.since < 2000 ]->(b:Person)\n" + "RETURN r.since" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 1994 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1994 ) ) ); } @@ -111,7 +111,7 @@ public void propertyExistenceCheckFilterTest() { + "WHERE n.age IS NOT NULL\n" + "RETURN n.name, n.age" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } @@ -124,7 +124,7 @@ public void propertyNonExistenceCheckFilterTest() { + "WHERE n.age IS NULL\n" + "RETURN n.name" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -134,7 +134,7 @@ public void rangeFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) WHERE 21 < n.age <= 32 RETURN n.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Bob" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Bob" ) ) ); } @@ -145,11 +145,11 @@ public void booleanConditionFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult result = execute( "MATCH (p) WHERE p.age >= 45 AND p.depno = 13 RETURN p.name" ); - assert containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); + containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); result = execute( "MATCH (p) WHERE p.age <= 32 OR p.depno = 13 RETURN p.name " ); - assert containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ), + containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ), Row.of( TestLiteral.from( "Bob" ) ), Row.of( TestLiteral.from( "Alex" ) ) ); } @@ -166,7 +166,7 @@ public void multiBooleanOperatorsFilterTest() { + " n.name AS name,\n" + " n.age AS age\n" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( 32 ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } @@ -180,7 +180,7 @@ public void withFilterTest() { + "WHERE n.age = 45\n" + "RETURN name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); } @@ -194,7 +194,7 @@ public void existFilterTest() { result = execute( "MATCH (p) WHERE exists(p.name) RETURN p" ); assertNode( result, 0 ); - assert containsRows( result, true, false, Row.of( MAX ) ); + containsRows( result, true, false, Row.of( MAX ) ); } @@ -208,7 +208,7 @@ public void startWithFilterTest() { execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "MATCH (p) WHERE p.name STARTS WITH 'M' RETURN p.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -222,7 +222,7 @@ public void endWithFilterTest() { + "WHERE n.name ENDS WITH 's'\n" + "RETURN n.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -234,7 +234,7 @@ public void notEndWithFilterTest() { GraphResult res = execute( "MATCH (n:Person)\n" + "WHERE NOT n.name ENDS WITH 's'\n" + "RETURN n.name, n.age" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -246,7 +246,7 @@ public void containsFilterTest() { execute( SINGLE_NODE_ANIMAL ); GraphResult result = execute( "MATCH (p) WHERE p.name CONTAINS 'H' RETURN p.name" ); - assert containsRows( result, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( result, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -259,7 +259,7 @@ public void patternFilterTest() { + "WHERE (p)-->(other)\n" + "RETURN other.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); res = execute( "MATCH\n" + " (p:Person {name: 'Max'}),\n" @@ -267,7 +267,7 @@ public void patternFilterTest() { + "WHERE (p)--(other)\n" + "RETURN other.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); res = execute( "MATCH\n" + " (p:Person {name: 'Max'}),\n" @@ -285,7 +285,7 @@ public void patternWithPropertiesFilterTest() { + "WHERE (other)-[:KNOWS]-({name: 'Hans'})\n" + "RETURN other.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -295,7 +295,7 @@ public void listComprehensionFilterTest() { GraphResult res = execute( "MATCH (a:Person {name: 'Max'})\n" + "RETURN [(a)-->(b WHERE b:Person) | b.name] AS friends" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Hans" ) ) ) ); } @@ -309,7 +309,7 @@ public void useInOperatorWithFilterTest() { + "WHERE a.name IN ['Peter', 'Max']\n" + "RETURN a.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -321,7 +321,7 @@ public void missingPropertyFilterTest() { GraphResult res = execute( "MATCH (n:Person)\n" + "WHERE n.age >= 40 \n" + "RETURN n.name, n.age" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java index de8ce73628..db4afc8f8c 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java @@ -18,13 +18,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.polypheny.db.adapter.annotations.AdapterSettingList.List; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class LimitTest extends CypherTestTemplate { @BeforeEach @@ -44,7 +45,7 @@ public void simpleLimitTest() { GraphResult res = execute( "MATCH (n) RETURN n.name, n.age LIMIT 3" ); - assert res.getData().length == 3; + assertEquals( 3, res.getData().length ); } @@ -54,9 +55,9 @@ public void InsertNodeLimitTest() { + "RETURN n\n" + "LIMIT 0" ); - assert res.getData().length == 0; + assertEquals( 0, res.getData().length ); res = matchAndReturnAllNodes(); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -67,6 +68,8 @@ public void updateNodeLimitTest() { + "SET n.age = 60\n" + "RETURN n\n" + "LIMIT 0" ); + + } @@ -80,9 +83,9 @@ public void orderByLimitTest() { GraphResult res = execute( "MATCH (n) RETURN n.name ORDER BY n.name DESC LIMIT 3" ); - assert res.getData().length == 3; + assertEquals( 3, res.getData().length ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Kira" ) ) ); @@ -97,7 +100,7 @@ public void withLimitTest() { execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (n) WITH n LIMIT 2 RETURN n.name, n.age;" ); - assert res.getData().length == 2; + assertEquals( 2, res.getData().length ); } @@ -110,12 +113,11 @@ public void withAndOrderByLimitTest() { + "WITH n ORDER BY n.name LIMIT 1\n" + "RETURN n" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); - assert containsNodes( res, true, - TestNode.from( Pair.of( "name", "Ann" ), - Pair.of( "age", 45 ), - Pair.of( "depno", 13 ) ) ); + containsNodes( res, true, TestNode.from( Pair.of( "name", "Ann" ), + Pair.of( "age", 45 ), + Pair.of( "depno", 13 ) ) ); } @@ -131,7 +133,7 @@ public void numberOfUpdatesLimitTest() { + "SET n.locked = true\n" + "RETURN n.name" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java index c744c3949b..1f000e1a5d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java @@ -20,11 +20,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.polypheny.db.adapter.java.Array; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; public class OrderByTest extends CypherTestTemplate { @@ -43,14 +41,14 @@ public void singleOrderByTest() { GraphResult res = execute( "MATCH (n) RETURN n.name ORDER BY n.name ASC" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Hans" ) ), Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Max" ) ) ); res = execute( "MATCH (n) RETURN n.name ORDER BY n.name DESC" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Hans" ) ) ); @@ -65,13 +63,13 @@ public void doubleOrderByTest() { GraphResult res = execute( "MATCH (n) RETURN n.name, n.age ORDER BY n.age ASC, n.name ASC" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); res = execute( "MATCH (n) RETURN n.depno, n.name ORDER BY n.depno ASC, n.name DESC" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ), Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Ann" ) ) ); @@ -97,6 +95,7 @@ public void nullOrderByTest() { } + @Test public void skipAndLimitWithSortTest() { execute( SINGLE_NODE_ANIMAL ); @@ -107,7 +106,7 @@ public void skipAndLimitWithSortTest() { GraphResult res = execute( "MATCH (n) RETURN n.name ORDER BY n.name DESC SKIP 1 LIMIT 2" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Kira" ) ) ); } @@ -123,145 +122,137 @@ public void orderByNotReturnedPropertyTest() { GraphResult res = execute( "MATCH (n) RETURN n ORDER BY n.name DESC" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( MAX ), Row.of( MAX ), Row.of( KIRA ), Row.of( KIRA ), Row.of( KIRA ) ); } + + @Test - public void renameWithClauseSortTest() - { + public void renameWithClauseSortTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); - GraphResult res = execute( "MATCH (p:Person) WITH p.age AS personAge RETURN personAge ORDER BY personAge" ); - assert containsRows( res , true ,true , + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) WITH p.age AS personAge RETURN personAge ORDER BY personAge" ); + containsRows( res, true, true, Row.of( TestLiteral.from( 31 ) ), - Row.of(TestLiteral.from( 45 )) ); + Row.of( TestLiteral.from( 45 ) ) ); } + + @Test - public void renameWithClauseOrderByWithLimitTest() - { + public void renameWithClauseOrderByWithLimitTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC LIMIT 2 RETURN age" ); - - assert containsRows( res , true ,true , - Row.of( TestLiteral.from( 45 ) ), - Row.of(TestLiteral.from( 32 )) ); + GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC LIMIT 2 RETURN age" ); + containsRows( res, true, true, + Row.of( TestLiteral.from( 45 ) ), + Row.of( TestLiteral.from( 32 ) ) ); } - @Test - public void renameWithClauseDoubleOrderByTest() - { + public void renameWithClauseDoubleOrderByTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC RETURN department , name" ); + GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC RETURN department , name" ); - - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Ann" ) ), - Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ) , - Row.of( TestLiteral.from( 14 ),TestLiteral.from( "Alex" ))); + Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ), + Row.of( TestLiteral.from( 14 ), TestLiteral.from( "Alex" ) ) ); + } - } @Test - public void renameWithClauseDoubleOrderByWithLimitTest() - { + public void renameWithClauseDoubleOrderByWithLimitTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC LIMIT 3 RETURN department , name " ); + GraphResult res = execute( "MATCH (p:Person) WITH p.depno AS department , p.name AS name ORDER BY department ASC, name ASC LIMIT 3 RETURN department , name " ); - - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Ann" ) ), - Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ) , - Row.of( TestLiteral.from( 14 ),TestLiteral.from( "Alex" ))); + Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ), + Row.of( TestLiteral.from( 14 ), TestLiteral.from( "Alex" ) ) ); + } - } @Test public void UnwindSortTest() { GraphResult res = execute( "UNWIND [1, true,3.14] AS i RETURN i ORDER BY i" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( true ) ), Row.of( TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( 3.14 ) ) ); } + + @Test - public void renameWithClauseWithUnwindSortTest () - { + public void renameWithClauseWithUnwindSortTest() { - GraphResult res = execute( "WITH [1 ,2 ,3] AS number UNWIND number AS n RETURN n ORDER BY n" ); + GraphResult res = execute( "WITH [1 ,2 ,3] AS number UNWIND number AS n RETURN n ORDER BY n" ); - assert containsRows( res , true , true , - Row.of( TestLiteral.from( 1 ) ), - Row.of( TestLiteral.from( 2 ) ), - Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, + Row.of( TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( 3 ) ) ); } - @Test - public void renameWithMixedTypesWithUnwindSortTest () - { + @Test + public void renameWithMixedTypesWithUnwindSortTest() { GraphResult res = execute( "WITH [1 ,2 ,'4'] AS number UNWIND number AS n RETURN n ORDER BY n" ); - assert containsRows( res , true , true , - Row.of( TestLiteral.from( '4') ), - Row.of( TestLiteral.from( 1) ), + containsRows( res, true, true, + Row.of( TestLiteral.from( '4' ) ), + Row.of( TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( 2 ) ) ); } + @Test - public void AvgAggregateFieldSortTest() - { + public void AvgAggregateFieldSortTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (p:Person)RETURN p.depno As Department ,avg(p.age) AS averageAge ORDER BY averageAge" ); - assert containsRows( res , true , true , - Row.of( TestLiteral.from( 14) , TestLiteral.from( 32 )), - Row.of( TestLiteral.from( 13 ) ,TestLiteral.from( 38 ))); + containsRows( res, true, true, + Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ), + Row.of( TestLiteral.from( 13 ), TestLiteral.from( 38 ) ) ); } - @Test - public void renameWithClauseOrderByWithSkipLimitTest() - { + public void renameWithClauseOrderByWithSkipLimitTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute(SINGLE_NODE_PERSON_COMPLEX_2); + execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC SKIP 1 Limit 1 RETURN age" ); + GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC SKIP 1 Limit 1 RETURN age" ); - assert containsRows( res , true ,true , - Row.of( TestLiteral.from( 32 ) )); + containsRows( res, true, true, + Row.of( TestLiteral.from( 32 ) ) ); } - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java index a7a348364f..ef16283a1d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java @@ -25,6 +25,8 @@ import org.polypheny.db.webui.models.results.GraphResult; import java.util.Arrays; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class SkipTest extends CypherTestTemplate { @BeforeEach @@ -44,7 +46,7 @@ public void simpleSkipTest() { GraphResult res = execute( "MATCH (n) RETURN n.name, n.age SKIP 3" ); - assert res.getData().length == 2; + assertEquals( 2, res.getData().length ); } @@ -58,7 +60,7 @@ public void orderBySkipTest() { GraphResult res = execute( "MATCH (n) RETURN n.name ORDER BY n.name DESC SKIP 3" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Kira" ) ), Row.of( TestLiteral.from( "Kira" ) ) ); } @@ -72,7 +74,7 @@ public void withAndSkipTest() { GraphResult res = execute( "MATCH (n) WITH n SKIP 2 RETURN n.name, n.age" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -87,7 +89,7 @@ public void returnSubsetSkipTest() { GraphResult res = execute( "MATCH (n) RETURN n.name SKIP 3 LIMIT 1" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -102,9 +104,9 @@ public void withAndOrderBySkipTest() { + "WITH n ORDER BY n.name SKIP 1\n" + "RETURN n" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( Pair.of( "name", "Bob" ), Pair.of( "age", 31 ), Pair.of( "depno", 13 ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java index 4483fa4dcd..f6661c0db1 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java @@ -21,7 +21,6 @@ import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; public class UnionTest extends CypherTestTemplate { @@ -66,7 +65,7 @@ public void DifferentStructureUnionTest() { + "MATCH (m :Movie)\n" + "RETURN p.Title AS name\n" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Wall Street" ) ) ); } @@ -84,7 +83,7 @@ public void NullPropertiesUnionTest() { + "MATCH (m:Movie)\n" + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ) ); } @@ -126,7 +125,7 @@ public void DifferentStructureAllUnionTest() { + "MATCH (m :Movie)\n" + "RETURN p.Title AS name\n" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Wall Street" ) ), Row.of( TestLiteral.from( "Max" ) ), @@ -147,7 +146,7 @@ public void NullPropertiesAllUnionTest() { + "MATCH (m:Movie)\n" + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ), @@ -186,7 +185,7 @@ public void DifferentStructureDistinctUnionTest() { + "MATCH (m :Movie)\n" + "RETURN p.Title AS name\n" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Wall Street" ) ) ); } @@ -204,7 +203,7 @@ public void NullPropertiesDistinctUnionTest() { + "MATCH (m:Movie)\n" + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java index 1f36f719f7..d43d855442 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java @@ -6,6 +6,8 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class UnwindTest extends CypherTestTemplate { @BeforeEach @@ -19,7 +21,7 @@ public void reset() { public void simpleUnwindTest() { GraphResult res = execute( "UNWIND [1, 3, null] AS x RETURN x, 'val' AS y" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 1 ), TestLiteral.from( "val" ) ), Row.of( TestLiteral.from( 3 ), TestLiteral.from( "val" ) ), Row.of( TestLiteral.from( null ), TestLiteral.from( "val" ) ) ); @@ -93,10 +95,10 @@ public void maxMinAggregateNodePropertyUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); res = execute( "MATCH (n) UNWIND n.age AS age RETURN min(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); } @@ -107,7 +109,7 @@ public void sumAggregateNodePropertyUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN sum(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); } @@ -118,7 +120,7 @@ public void AvgAggregateNodePropertyUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); } @@ -136,7 +138,7 @@ public void CollectAggregateUnWind() { public void countUnWind() { GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ) ); } @@ -145,8 +147,8 @@ assert containsRows( res, true, false, @Test public void distinctUnWind() { GraphResult res = execute( "UNWIND [3, 3 ,2 ,1 ] AS i RETURN DISTINCT i" ); - assert res.getData().length == 3; - assert containsRows( res, true, false, + assertEquals( 3, res.getData().length ); + containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 1 ) ) ); @@ -157,7 +159,7 @@ assert containsRows( res, true, false, @Test public void ConditionalLogicUnWind() { GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( 1 ), TestLiteral.from( "odd" ) ), Row.of( TestLiteral.from( 2 ), TestLiteral.from( "even" ) ), Row.of( TestLiteral.from( 3 ), TestLiteral.from( "odd" ) ) ); @@ -168,7 +170,7 @@ assert containsRows( res, true, true, @Test public void mapStructureUnWind() { GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ) ), Row.of( TestLiteral.from( 30 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ) ), Row.of( TestLiteral.from( 30 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java index de560abb1b..068d03c76d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java @@ -20,11 +20,11 @@ import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; -import org.polypheny.db.cypher.helper.TestNode; -import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.AbstractSequentialList; -import java.util.Arrays; + + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class WithTest extends CypherTestTemplate { @@ -42,7 +42,9 @@ public void singleVariableWithTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person) WITH n RETURN n.name" ); - + containsRows( res, true, false, + Row.of( TestLiteral.from( "Max" ) ), + Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -53,6 +55,10 @@ public void multipleRenameVariablesWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH p.name AS person_name , p.age AS person_age , p RETURN person_name, person_age , p.depno;" ); + containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( 13 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ), TestLiteral.from( 13 ) ) ); + } @@ -62,7 +68,7 @@ public void renameWithTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person) WITH n.name AS name, n RETURN name, n" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ), Row.of( TestLiteral.from( "Hans" ), HANS ) ); @@ -76,7 +82,7 @@ public void startWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name, n WHERE n.name STARTS WITH 'H' RETURN n" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( HANS ) ); } @@ -90,7 +96,7 @@ public void startRenameWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name as name , n WHERE name STARTS WITH 'H' RETURN n" ); assertNode( res, 0 ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( HANS ) ); } @@ -104,7 +110,7 @@ public void endWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name , n WHERE n.name ENDS WITH 'x' RETURN name, n" ); assertNode( res, 1 ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); } @@ -117,7 +123,7 @@ public void endRenameWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name AS name, n WHERE name ENDS WITH 'x' RETURN name, n" ); assertNode( res, 1 ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); } @@ -132,7 +138,7 @@ public void containsWithTest() { GraphResult res = execute( "MATCH (n:Person)-[]->(p:Animal) WITH *, n.name AS username WHERE username CONTAINS 'a' RETURN username, p" ); assertNode( res, 1 ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), KIRA ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), KIRA ) ); } @@ -144,7 +150,7 @@ public void avgAggregationRenameWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH avg(p.age) as ageAvg RETURN ageAvg " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 38 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 38 ) ) ); } @@ -155,10 +161,10 @@ public void maxMinAggregationRenameWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH MAX(p.age) as ageMax RETURN ageMax " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 45 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 45 ) ) ); res = execute( "MATCH (p:Person) WITH MIN(p.age) as ageMin RETURN ageMin " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 31 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 31 ) ) ); } @@ -168,7 +174,7 @@ public void countAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH COUNT(*) as count RETURN count " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 2 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 2 ) ) ); } @@ -179,7 +185,7 @@ public void stDevAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH STDEV(p.age) as ageStdev RETURN ageStdev " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 9.8994949 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 9.8994949 ) ) ); } @@ -190,7 +196,7 @@ public void collectAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (p:Person) WITH COLLECT(p.age) as ageList RETURN ageList " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( 45 ), TestLiteral.from( 31 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 45 ), TestLiteral.from( 31 ) ) ); } @@ -208,6 +214,7 @@ public void filterWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (p:Person) WITH p WHERE p.age > 31 RETURN p.name, p.age" ); + } @@ -243,24 +250,24 @@ public void unWindAndFilterListWithTest() { @Test public void unWindAndStartListWithTest() { GraphResult res = execute( "WITH ['John', 'Mark', 'Jonathan', 'Bill'] AS somenames UNWIND somenames AS names WITH names AS candidate WHERE candidate STARTS WITH 'Jo' RETURN candidate" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( "John" ) ), Row.of( TestLiteral.from( "Jonathan" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "John" ) ), Row.of( TestLiteral.from( "Jonathan" ) ) ); } @Test public void unWindAndLogicalOperatorsListWithTest() { GraphResult res = execute( "WITH [2, 4, 7, 9, 12] AS numberlist UNWIND numberlist AS number WITH number WHERE number = 4 OR (number > 6 AND number < 10) RETURN number" ); - assert containsRows( res, false, false, + assertTrue( containsRows( res, false, false, Row.of( TestLiteral.from( 4 ) ), Row.of( TestLiteral.from( 7 ) ), - Row.of( TestLiteral.from( 9 ) ) ); + Row.of( TestLiteral.from( 9 ) ) ) ); } @Test public void unWindAndWhereInListWithTest() { GraphResult res = execute( "WITH [2, 3, 4, 5] AS numberlist UNWIND numberlist AS number WITH number WHERE number IN [2, 3, 8] RETURN number" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 3 ) ) ); } @@ -269,7 +276,7 @@ public void unWindAndWhereInListWithTest() { public void createNodeWithTest() { execute( "WITH [1, 1.0] AS list CREATE ({l: list})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -281,7 +288,7 @@ public void distinctWithTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( "MATCH (p:Person) WITH Distinct(p) Return p " ); - assert res.getData().length == 2; + assertEquals( 2, res.getData().length ); } @@ -293,7 +300,7 @@ public void existsWithTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age;" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } @@ -305,7 +312,7 @@ public void conditionalLogicWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (p:Person) WITH p, CASE WHEN p.age < 30 THEN 'Young' THEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' ELSE 'Elderly END AS ageGroup RETURN p.name, ageGroup;" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Ana" ), TestLiteral.from( "Middle-aged" ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( "Middle-aged" ) ), Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( "Middle-aged" ) ) ); @@ -319,7 +326,7 @@ public void orderByWithTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p.name" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "Hans" ) ), Row.of( TestLiteral.from( "Max" ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java index 032e9a09a4..86114691f1 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java @@ -74,7 +74,7 @@ public void simpleMatchLabelTest() { GraphResult res = execute( "MATCH (n:Person) RETURN n" ); assertNode( res, 0 ); - assert containsNodes( res, true, MAX ); + containsNodes( res, true, MAX ); } @@ -87,7 +87,7 @@ public void simpleMatchSinglePropertyTest() { GraphResult res = execute( "MATCH (n {name: 'Max'}) RETURN n" ); assertNode( res, 0 ); - assert containsNodes( res, true, HANS ); + containsNodes( res, true, HANS ); res = execute( "MATCH (n {name: 'Hans'}) RETURN n" ); assertNode( res, 0 ); @@ -111,7 +111,7 @@ public void simpleMatchMultiplePropertyTest() { res = execute( "MATCH (n {name: 'Kira', age: 3}) RETURN n" ); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of( "Animal" ), Pair.of( "name", "Kira" ), Pair.of( "age", 3 ), Pair.of( "type", "dog" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Animal" ), Pair.of( "name", "Kira" ), Pair.of( "age", 3 ), Pair.of( "type", "dog" ) ) ); } @@ -125,7 +125,7 @@ public void NoLabelPropertyTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); GraphResult res = execute( "MATCH (n) RETURN n.age" ); - assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ), + containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( null ) ) ); } @@ -135,8 +135,8 @@ assert containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ), public void simplePropertyTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( "MATCH (n:Person) RETURN n.name" ); - assert is( res, Type.ANY, 0 ); - assert containsIn( res, true, 0, "n.name", TestLiteral.from( "Max" ) ); + is( res, Type.ANY, 0 ); + containsIn( res, true, 0, "n.name", TestLiteral.from( "Max" ) ); } @@ -144,10 +144,10 @@ public void simplePropertyTest() { public void simpleMultiplePropertyTest() { execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "MATCH (n:Animal) RETURN n.name, n.age" ); - assert is( res, Type.ANY, 0 ); // we never have guaranties for the types - assert is( res, Type.ANY, 1 ); - assert containsIn( res, true, 0, "n.name", TestLiteral.from( "Kira" ) ); - assert containsIn( res, true, 1, "n.age", TestLiteral.from( "3" ) ); + is( res, Type.ANY, 0 ); // we never have guaranties for the types + is( res, Type.ANY, 1 ); + containsIn( res, true, 0, "n.name", TestLiteral.from( "Kira" ) ); + containsIn( res, true, 1, "n.age", TestLiteral.from( "3" ) ); } @@ -156,7 +156,7 @@ public void mixedNodeAndPropertyProjectTest() { execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "MATCH (n:Person) RETURN n, n.age" ); assertNode( res, 0 ); - assert is( res, Type.ANY, 1 ); + is( res, Type.ANY, 1 ); } /////////////////////////////////////////////// @@ -169,7 +169,7 @@ public void simpleEdgeTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH ()-[r]->() RETURN r" ); assertEdge( res, 0 ); - assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); + containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); } @@ -191,7 +191,7 @@ public void singleEdgeFilterTest() { assertEmpty( res ); res = execute( "MATCH ()-[r:KNOWS {since: 1994}]->() RETURN r" ); - assert containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ), Pair.of( "since", 1994 ) ) ); + containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ), Pair.of( "since", 1994 ) ) ); } @@ -219,7 +219,7 @@ public void multipleHopTest() { res = execute( "MATCH ()-[r:FRIEND_OF {since:1995}]->()-[]-() RETURN r" ); assertEdge( res, 0 ); - assert containsEdges( res, true, TestEdge.from( List.of( "FRIEND_OF" ), Pair.of( "since", 1995 ) ) ); + containsEdges( res, true, TestEdge.from( List.of( "FRIEND_OF" ), Pair.of( "since", 1995 ) ) ); } @@ -231,7 +231,7 @@ public void repeatingHopTest() { GraphResult res = execute( "MATCH ()-[*2]->(n) RETURN n" ); assertNode( res, 0 ); - assert containsRows( res, true, true, Row.of( TestNode.from( List.of( "Animal" ), Pair.of( "name", "Kira" ) ) ) ); + containsRows( res, true, true, Row.of( TestNode.from( List.of( "Animal" ), Pair.of( "name", "Kira" ) ) ) ); } @@ -243,7 +243,7 @@ public void variableHopTest() { GraphResult res = execute( "MATCH ()-[*1..2]->(n) RETURN n" ); assertNode( res, 0 ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( KIRA ), Row.of( HANS_AGE ), Row.of( MAX ), @@ -265,8 +265,8 @@ public void simpleMixedRelationshipTest() { GraphResult res = execute( "MATCH (h:Person)-[r:OWNER_OF]-(p:Animal) RETURN h,p" ); assertNode( res, 0 ); assertNode( res, 1 ); - assert containsIn( res, true, 0, MAX ); - assert containsIn( res, true, 1, TestNode.from( + containsIn( res, true, 0, MAX ); + containsIn( res, true, 1, TestNode.from( List.of( "Animal" ), Pair.of( "name", "Kira" ), Pair.of( "age", 3 ), @@ -286,7 +286,7 @@ public void simpleCrossProductMatchTest() { assertNode( res, 0 ); assertNode( res, 1 ); - assert containsRows( res, true, true, Row.of( MAX, MAX ) ); + containsRows( res, true, true, Row.of( MAX, MAX ) ); } @@ -298,7 +298,7 @@ public void simpleCrossProductBiMatchTest() { assertNode( res, 0 ); assertNode( res, 1 ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( MAX, MAX ), Row.of( HANS, MAX ), Row.of( MAX, HANS ), @@ -314,7 +314,7 @@ public void simpleTriCrossProductMatchTest() { assertNode( res, 1 ); assertNode( res, 2 ); - assert containsRows( res, true, true, Row.of( MAX, MAX, MAX ) ); + containsRows( res, true, true, Row.of( MAX, MAX, MAX ) ); } @@ -328,12 +328,12 @@ public void simpleNeighborMatchTest() { GraphResult res = execute( "MATCH (p:Person {name:'Max'})-[]-(t) RETURN t" ); assertNode( res, 0 ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( KIRA ), Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "age", 31 ) ) ) ); res = execute( "MATCH (p:Person {name:'Max'})-->(t) RETURN t " ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( KIRA ), Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "age", 31 ) ) ) ); @@ -350,7 +350,7 @@ public void triCrossProductMatchTest() { assertNode( res, 1 ); assertNode( res, 2 ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( MAX, MAX, MAX ), Row.of( HANS, MAX, MAX ), Row.of( MAX, HANS, MAX ), @@ -372,14 +372,14 @@ public void matchPathTest() { GraphResult res = execute( "MATCH (m {name:'Max'}), (k {name:'Kira'}), p = (m)-[]-(k)\n" + "RETURN p" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestPath.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ) ); res = execute( "MATCH Path = (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'}) RETURN Path " ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestPath.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestEdge.from( List.of( "OWNER_OF" ) ), @@ -394,7 +394,7 @@ public void returnPathsByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH Path = () -[]->() RETURN *" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestPath.of( MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ) ); @@ -406,7 +406,7 @@ public void returnNodesByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH (p) RETURN *" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( MAX ), Row.of( KIRA ) ); } @@ -416,7 +416,7 @@ assert containsRows( res, true, false, public void returnBothSideByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH (p) -[]->(m) RETURN *" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( MAX ), Row.of( KIRA ) ); } @@ -426,7 +426,7 @@ assert containsRows( res, true, false, public void returnAllElementsByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH Path = (p) -[r] ->(m) RETURN *" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestPath.of( MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) , MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ); } @@ -436,7 +436,7 @@ assert containsRows( res, true, false, public void returnEdgesByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH ()-[r]-() RETURN *" ); - assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); + containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); } @@ -448,7 +448,7 @@ public void shortestPathMatchTest() { + "MATCH p = shortestPath((b)-[*]-(a))\n" + "RETURN p\n" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestPath.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestEdge.from( List.of( "OWNER_OF" ) ), diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java index cbc4709ceb..9b88f133d8 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java @@ -16,7 +16,6 @@ package org.polypheny.db.cypher.clause.write; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,6 +24,8 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class DmlDeleteTest extends CypherTestTemplate { @BeforeEach @@ -61,7 +62,7 @@ public void simpleFilteredNodeDeleteTest() { execute( "MATCH (p:Person {name: 'Max'})\n" + "DELETE p" ); GraphResult res = matchAndReturnAllNodes(); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ) ) ) ); } @@ -86,7 +87,7 @@ public void simpleRelationshipDeleteTest() { assertEmpty( res ); res = matchAndReturnAllNodes(); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ) ), Row.of( TestNode.from( List.of( "Animal" ), @@ -107,7 +108,7 @@ public void relationshipWithPropertiesDeleteTest() { assertEmpty( res ); res = matchAndReturnAllNodes(); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ) ), Row.of( TestNode.from( List.of( "Person" ), @@ -128,7 +129,7 @@ public void pathDeleteTest() { GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) RETURN rel " ); - assert res.getData().length == 0 && relations.getData().length == 0; + assertTrue( res.getData().length == 0 && relations.getData().length == 0 ); } @@ -142,7 +143,7 @@ public void NodeWithAllRelationshipsDeleteTest() { GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) Return rel" ); - assert res.getData().length == 0 && relations.getData().length == 0; + assertTrue( res.getData().length == 0 && relations.getData().length == 0 ); } @@ -157,7 +158,7 @@ public void allNodesAndRelationshipsDeleteTest() { GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) Return rel" ); - assert res.getData().length == 0 && relations.getData().length == 0; + assertTrue( res.getData().length == 0 && relations.getData().length == 0 ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java index 4a0523c1a3..718ed8d104 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java @@ -16,9 +16,7 @@ package org.polypheny.db.cypher.clause.write; -import java.util.Arrays; import java.util.List; -import org.apache.logging.log4j.core.pattern.NotANumber; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -28,6 +26,9 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import static org.junit.jupiter.api.Assertions.assertEquals; + + public class DmlInsertTest extends CypherTestTemplate { @@ -57,7 +58,7 @@ public void insertEmptyNodeWithNoVariableNoLabelTest() { execute( "CREATE ()" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of() ) ); + containsNodes( res, true, TestNode.from( List.of() ) ); } @@ -66,7 +67,7 @@ public void insertEmptyNodeWithNoVariableTest() { execute( "CREATE (:Person)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); } @@ -75,7 +76,7 @@ public void insertEmptyNoLabelNodeTest() { execute( "CREATE (p)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of() ) ); + containsNodes( res, true, TestNode.from( List.of() ) ); } @@ -84,7 +85,7 @@ public void insertEmptyNodeTest() { execute( "CREATE (p:Person)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); } @@ -93,7 +94,7 @@ public void insertNodeTest() { execute( "CREATE (p:Person {name: 'Max Muster'})" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( Pair.of( "name", "Max Muster" ) ) ); + containsNodes( res, true, TestNode.from( Pair.of( "name", "Max Muster" ) ) ); } @@ -101,7 +102,7 @@ public void insertNodeTest() { public void insertNodeWithManyLabelsTest() { execute( "CREATE (p:Person :Employee )" ); GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ) ) ); } @@ -110,7 +111,7 @@ public void insertNodeWithManyLabelsAndAsPropertyTest() { execute( "CREATE (n:Person:Employee {name :'Max'})" ); GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ) ); } @@ -119,8 +120,8 @@ public void insertNodeWithManyLabelsAndAsPropertyTest() { public void insertBigIntegerExceeded32BitAsPropertyValeTest() { execute( "CREATE (n : node { id : 4294967296 })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4294967296L ) ) ); + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4294967296L ) ) ); } @@ -128,8 +129,8 @@ public void insertBigIntegerExceeded32BitAsPropertyValeTest() { public void insertMaxLongAsPropertyValueTest() { execute( "CREATE (n : node { id : 9223372036854775807})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 9223372036854775807L ) ) ); + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 9223372036854775807L ) ) ); } @@ -138,8 +139,8 @@ public void insertMaxLongAsPropertyValueTest() { public void insertResultOfMathematicalOperationsTest() { execute( "CREATE (n : node { id : 1*2+6/3 })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 9223372036854775807L ) ) ); + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 9223372036854775807L ) ) ); } @@ -148,8 +149,8 @@ public void insertResultOfMathematicalOperationsTest() { public void insertENotationAsPropertyValueTest() { execute( "CREATE (n : node { id : 1e2})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 100 ) ) ); + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 100 ) ) ); } @@ -160,8 +161,8 @@ public void insertMaxLongAsResultOfMathematicalOperationsTest() { execute( "CREATE (n : node { id : 2^63-1})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4 ) ) ); + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4 ) ) ); } @@ -171,8 +172,8 @@ public void insertMinLongAsPropertyValueTest() { execute( "CREATE (n : node { id : -9223372036854775808L})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", -9223372036854775808L ) ) ); + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", -9223372036854775808L ) ) ); } @@ -180,8 +181,8 @@ public void insertMinLongAsPropertyValueTest() { public void insertMaxDoubleAsPropertyValueTest() { execute( "CREATE (n : node { id : 1.7976931348623157e+308})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 1.7976931348623157e+308 ) ) ); + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 1.7976931348623157e+308 ) ) ); } @@ -191,8 +192,8 @@ public void insertMinDoubleAsPropertyValueTest() { execute( "CREATE (n : node { id : 4.9e-324 })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4.9e-324 ) ) ); + assertEquals( res.getData().length, 1 ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4.9e-324 ) ) ); } @@ -201,8 +202,8 @@ public void insertHexadecimalIntegerAsPropertyValueTest() { execute( "CREATE (n : node { id : 0x13af})" ); execute( "CREATE (n : node { id : -0x66eff})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 5039 ) ), TestNode.from( List.of( "node" ), Pair.of( "id", -421631 ) ) ); @@ -216,8 +217,8 @@ public void insertOctalIntegerAsPropertyValueTest() { execute( "CREATE (n : node { id : 0o1372})" ); execute( "CREATE (n : node { id :-0o5671 })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 762 ) ), TestNode.from( List.of( "node" ), Pair.of( "id", -3001 ) ) ); } @@ -227,8 +228,8 @@ assert containsNodes( res, true, public void insertTabCharWithPropertyValueTest() { execute( "CREATE (n : node { title : \"Hello\\tWorld\" })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "title", "Hello\tWorld" ) ) ); } @@ -237,8 +238,8 @@ assert containsNodes( res, true, public void insertBackspaceCharWithPropertyValueTest() { execute( "CREATE (n : node { title : \"Hello\\bWorld\" })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "title", "Hello\bWorld" ) ) ); } @@ -247,8 +248,8 @@ assert containsNodes( res, true, public void insertNewlineWithPropertyValueTest() { execute( "CREATE (n : node { title : \"Hello\\nWorld\" })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "title", "Hello\nWorld" ) ) ); } @@ -257,8 +258,8 @@ assert containsNodes( res, true, public void insertSingleQuoteCharWithPropertyValueTest() { execute( "CREATE (n : node { title : 'Hello\\'World' })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "title", "Hello'World" ) ) ); } @@ -267,8 +268,8 @@ assert containsNodes( res, true, public void insertMultiplePropertiesWithSingleQuoteValuesTest() { execute( " CREATE (n:node { name: \"Xi'an\", url: \"http://dbpedia.org/resource/Xi'an\"})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "name", "Xi'an" ), Pair.of( "url", "http://dbpedia.org/resource/Xi'an" ) ) ); } @@ -278,8 +279,8 @@ assert containsNodes( res, true, public void insertDoubleQuoteCharWithPropertyValueTest() { execute( "CREATE (n : node { title : \"Hello\\\"World\" })" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; - assert containsNodes( res, true, + assertEquals( 1, res.getData().length ); + containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "title", "Hello\"World" ) ) ); } @@ -288,7 +289,7 @@ assert containsNodes( res, true, public void insertNodeWithPropertyContainsListTest() { execute( "CREATE ({l: [1 ,2,3]})" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -299,7 +300,7 @@ public void insertTwoNodeTest() { execute( CREATE_PERSON_MAX ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( Pair.of( "name", "Max Muster" ) ), TestNode.from( Pair.of( "name", "Max Muster" ) ) ); } @@ -310,7 +311,7 @@ public void insertMultipleNodesTest() { execute( "CREATE (p),(n),(m)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from(), TestNode.from(), TestNode.from() ); + containsNodes( res, true, TestNode.from(), TestNode.from(), TestNode.from() ); } @@ -319,7 +320,7 @@ public void insertPropertyTypeTest() { execute( "CREATE (p:Person {name: 'Max Muster', age: 13, height: 185.3, nicknames: [\"Maxi\",\"Musti\"]})" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( Pair.of( "name", "Max Muster" ), Pair.of( "age", 13 ), @@ -336,7 +337,7 @@ public void insertReturnNodeTest() { "CREATE (p:Person {name: 'Max Muster'})\n" + "RETURN p" ); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of() ) ); + containsNodes( res, true, TestNode.from( List.of() ) ); } @@ -345,7 +346,7 @@ public void insertSingleHopPathNoVariableTest() { execute( "CREATE (p:Person {name :'Max'}) -[ : OWNER_OF] ->(a: Animal {name :'Kira' , age: 3 , type :'dog'})" ); GraphResult res = matchAndReturnAllNodes(); // only select all nodes - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestNode.from( List.of( "Animal" ), @@ -355,7 +356,7 @@ assert containsNodes( res, true, // only select all edges res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); + containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); } @@ -364,7 +365,7 @@ assert containsNodes( res, true, public void insertSingleHopPathTest() { execute( "CREATE (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'})" ); GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestNode.from( List.of( "Animal" ), @@ -379,7 +380,7 @@ assert containsNodes( res, true, public void insertSingleHopPathEdgesTest() { execute( "CREATE (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'})" ); GraphResult res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); + containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); } @@ -389,7 +390,7 @@ public void insertSingleHopPathWithMultiplePropertiesTest() { // only select all nodes GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestNode.from( List.of( "Person" ), @@ -398,7 +399,7 @@ assert containsNodes( res, true, // only select all edges res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ), + containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ), Pair.of( "since", 1994 ), Pair.of( "relation", "friend" ) ) ); } @@ -409,7 +410,7 @@ public void insertSingleHopPathWithListPropertyTest() { execute( "Create (p:Person:Employee {name: 'Max'})-[role:ACTED_IN {roles:['Neo', 42, 'Thomas Anderson']}]->(matrix:Movie {title: 'The Matrix'})" ); // only select all nodes GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ), TestNode.from( List.of( "Movie" ), @@ -417,7 +418,7 @@ assert containsNodes( res, true, // only select all edges res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsEdges( res, true, TestEdge.from( List.of( "ACTED_IN" ), + containsEdges( res, true, TestEdge.from( List.of( "ACTED_IN" ), Pair.of( "roles", List.of( "Neo", 42, "Thomas Anderson" ) ) ) ); } @@ -428,14 +429,14 @@ public void insertMultipleHopPathTest() { // only select all nodes GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( List.of( "Person" ) ), TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestNode.from( List.of( "Animal" ), Pair.of( "name", "Kira" ) ) ); // only select all edges res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestEdge.from( List.of( "OWNER_OF" ) ) ), Row.of( TestEdge.from( List.of( "FRIEND_OF" ) ) ) ); } @@ -445,18 +446,18 @@ assert containsRows( res, true, false, public void insertAllInOneTest() { execute( CREATE_COMPLEX_GRAPH_1 ); GraphResult res = execute( "MATCH (n) RETURN n" ); - assert res.getData().length == 3; + assertEquals( 3, res.getData().length ); assertNode( res, 0 ); res = execute( "MATCH ()-[r]-() RETURN r" ); assertEdge( res, 0 ); // double matches of same path is correct, as no direction is specified - assert res.getData().length == 4; + assertEquals( 4, res.getData().length ); res = execute( "MATCH ()-[r]->() RETURN r" ); assertEdge( res, 0 ); // double matches of same path is correct, as no direction is specified - assert res.getData().length == 2; + assertEquals( 2, res.getData().length ); } @@ -464,12 +465,12 @@ public void insertAllInOneTest() { public void insertAllInOneCircleTest() { execute( CREATE_COMPLEX_GRAPH_2 ); GraphResult res = execute( "MATCH (n) RETURN n" ); - assert res.getData().length == 3; + assertEquals( 3, res.getData().length ); assertNode( res, 0 ); res = execute( "MATCH ()-[r]-() RETURN r" ); assertEdge( res, 0 ); - assert res.getData().length == 6; + assertEquals( 6, res.getData().length ); } @@ -483,7 +484,7 @@ public void insertAdditionalEdgeTest() { GraphResult res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestEdge.from( List.of( "KNOWS" ) ) ) ); } @@ -498,7 +499,7 @@ public void insertAdditionalEdgeOneSideTest() { GraphResult res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestEdge.from( List.of( "KNOWS" ) ) ) ); } @@ -514,7 +515,7 @@ public void insertAdditionalEdgeOneSideBothSideTest() { GraphResult res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestEdge.from( List.of( "KNOWS" ) ) ), Row.of( TestEdge.from( List.of( "KNOWS" ) ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java index 7ef05310c2..9fe5654283 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java @@ -42,7 +42,7 @@ public void updatePropertyTest() { + "SET a.age = 25" ); GraphResult res = matchAndReturnAllNodes(); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ), Pair.of( "age", 25 ) ) ) ); } @@ -54,7 +54,7 @@ public void updateLabelTest() { + "SET a:Swiss" ); GraphResult res = matchAndReturnAllNodes(); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestNode.from( List.of( "Person", "Swiss" ), Pair.of( "name", "Max" ) ) ) ); } @@ -66,7 +66,7 @@ public void updateLabelsTest() { + "SET a:Swiss:German" ); GraphResult res = matchAndReturnAllNodes(); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestNode.from( List.of( "Person", "Swiss", "German" ), Pair.of( "name", "Max" ) ) ) ); } @@ -78,7 +78,7 @@ public void updateVariablesReplaceTest() { + "SET a = {} " ); GraphResult res = matchAndReturnAllNodes(); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestNode.from( List.of( "Person" ) ) ) ); } @@ -90,7 +90,7 @@ public void updateVariablesIncrementTest() { + "SET a = { name : 'Max' , age: 13, job: 'Developer'} " ); GraphResult res = matchAndReturnAllNodes(); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ), @@ -121,7 +121,7 @@ public void updateVariablesIncrementAndDecrementTest() { + "RETURN p.name, p.age, p.position" ); GraphResult res = matchAndReturnAllNodes(); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Peter Smith" ), diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java index 9df533c82a..77327e4934 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java @@ -25,6 +25,8 @@ import org.polypheny.db.webui.models.results.GraphResult; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ForeachTest extends CypherTestTemplate { @BeforeEach @@ -42,8 +44,8 @@ public void createWithForeachTest() { + ")" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 3; - assert containsNodes( res, true, + assertEquals( 3, res.getData().length ); + containsNodes( res, true, TestNode.from( Pair.of( "name", "Alice" ) ), TestNode.from( Pair.of( "name", "Bob" ) ), TestNode.from( Pair.of( "name", "Charlie" ) ) ); @@ -60,8 +62,8 @@ public void mergeWithForeachTest() { + ")" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 3; - assert containsNodes( res, true, + assertEquals( 3, res.getData().length ); + containsNodes( res, true, TestNode.from( Pair.of( "name", "Alice" ) ), TestNode.from( Pair.of( "name", "Bob" ) ), TestNode.from( Pair.of( "name", "Charlie" ) ) ); @@ -97,7 +99,7 @@ public void removeWithForeachTest() { + ")" ); GraphResult res = matchAndReturnAllNodes(); - assert containsRows( res, true, false, Row.of( TestLiteral.from( null ) ), + containsRows( res, true, false, Row.of( TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ) ) ); } @@ -114,7 +116,7 @@ public void updateWithForeachTest() { + ")" ); GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ), Pair.of( "status", "active" ) ), TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "status", "active" ) ) ); } @@ -132,9 +134,9 @@ public void nestedForeachTest() { + " )\n" + ")" ); GraphResult res = execute( "MATCH (p1)-[r:KNOWS]->(p2) RETURN r" ); - assert res.getData().length == 4; + assertEquals( 4, res.getData().length ); res = execute( "MATCH (p1)-[r:KNOWS]-(p2) RETURN r" ); - assert res.getData().length == 6; + assertEquals( 6, res.getData().length ); } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java index d2ea48ebf4..c8df1a0e5b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java @@ -28,6 +28,9 @@ import java.util.Arrays; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + @Slf4j public class MergeTest extends CypherTestTemplate { @@ -51,7 +54,7 @@ public void singleNodeMergeTest() { execute( "MERGE (P)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of() ) ); + containsNodes( res, true, TestNode.from( List.of() ) ); } @@ -59,7 +62,7 @@ public void singleNodeMergeTest() { public void returnSingleNodeMergeTest() { GraphResult res = execute( "MERGE (P) Return P " ); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of() ) ); + containsNodes( res, true, TestNode.from( List.of() ) ); } @@ -71,7 +74,7 @@ public void singleNodeWithLabelMergeTest() { execute( "MERGE (p:Person)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Person" ) ) ); // System.out.print( res.getData().length ); return zero // exist node @@ -79,7 +82,7 @@ public void singleNodeWithLabelMergeTest() { res = matchAndReturnAllNodes(); // num of nodes should be one - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -90,12 +93,12 @@ public void singleNodeWithMultipleLabelsMergeTest() { execute( "MERGE (robert:Critic:Viewer)" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of( "Critic", "Viewer" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Critic", "Viewer" ) ) ); // exist node execute( "MERGE (robert:Critic:Viewer)" ); GraphResult allNodes = matchAndReturnAllNodes(); - assert allNodes.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -107,12 +110,12 @@ public void singleNodeWithSinglePropertyMergeTest() { GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of(), + containsNodes( res, true, TestNode.from( List.of(), Pair.of( "name", "Charlie Sheen" ) ) ); execute( "MERGE (charlie {name: 'Charlie Sheen'})" ); res = matchAndReturnAllNodes(); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -123,14 +126,14 @@ public void singleNodeWithMultiplePropertiesMergeTest() { execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of(), + containsNodes( res, true, TestNode.from( List.of(), Pair.of( "name", "Charlie Sheen" ), Pair.of( "age", 10 ) ) ); execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})" ); res = matchAndReturnAllNodes(); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -140,14 +143,14 @@ public void singleNodeWithPropertiesAndLabelMergeTest() { execute( "MERGE (michael:Person {name: 'Michael Douglas' , age : 10})" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); - assert containsNodes( res, true, TestNode.from( List.of( "Person" ), + containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Michael Douglas" ), Pair.of( "age", 10 ) ) ); execute( "MERGE (michael:Person {name: 'Michael Douglas' , age : 10})" ); res = matchAndReturnAllNodes(); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -171,7 +174,7 @@ public void singleNodeDerivedFromExistingNodeMergeTest() { res = execute( "MATCH (location:Location) RETURN location" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -190,7 +193,7 @@ public void createWithMergeTest() { + "ON CREATE SET keanu.age = 20" ); res = matchAndReturnAllNodes(); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -214,7 +217,7 @@ public void matchWithMergeTest() { List.of( "Person" ), Pair.of( "found", true ) ) ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -239,7 +242,7 @@ public void createOrMatchNodeWithMergeTest() { Pair.of( "age", 35 ), Pair.of( "name", "Alice" ) ) ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -254,19 +257,19 @@ public void singleRelationshipMergeTest() { + "MERGE (charlie)-[r:ACTED_IN]->(wallStreet)\n" ); GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Charlie Sheen" ) ), TestNode.from( List.of( "Person" ), Pair.of( "name", "Wall Street" ) ) ); res = execute( "MATCH ()-[r]->() RETURN r" ); - assert containsEdges( res, true, TestEdge.from( List.of( "ACTED_IN" ) ) ); + containsEdges( res, true, TestEdge.from( List.of( "ACTED_IN" ) ) ); execute( "MATCH\n" + " (charlie:Person {name: 'Charlie Sheen'}),\n" + " (wallStreet:Movie {title: 'Wall Street'})\n" + "MERGE (charlie)-[r:ACTED_IN]->(wallStreet)\n" ); res = execute( "MATCH ()-[r]->() RETURN r" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -285,7 +288,7 @@ public void multipleRelationshipsMergeTest() { GraphResult res = execute( "MATCH (p1:Person)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(p2:Person)\n" + "RETURN p1, p2, movie\n" ); - assert containsNodes( res, true, + containsNodes( res, true, TestNode.from( Pair.of( "name", "Charlie Sheen" ) ), TestNode.from( Pair.of( "name", "Martin Sheen" ) ), TestNode.from( List.of( "Movie" ) ) ); @@ -296,7 +299,7 @@ assert containsNodes( res, true, + "MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(reiner)\n" ); res = matchAndReturnAllNodes(); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -314,7 +317,7 @@ public void undirectedRelationshipMergeTest() { GraphResult res = execute( "MATCH (p1:Person)-[r:KNOWS]-(p2:Person)\n" + "RETURN KNOWS" ); - assert containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ) ) ); + containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ) ) ); execute( "MATCH\n" + " (charlie:Person {name: 'Charlie Sheen'}),\n" @@ -324,7 +327,7 @@ public void undirectedRelationshipMergeTest() { res = execute( "MATCH (p1:Person)-[r:KNOWS]-(p2:Person)\n" + "RETURN KNOWS" ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -345,8 +348,8 @@ public void relationshipOnTwoExistingNodeMergeTest() { Row.of( TestLiteral.from( "New Jersey" ) ) ); res = execute( "MATCH ()-[BORN_IN]->() RETURN BORN_IN" ); - assert res.getData().length == 3; - assert containsEdges( res, true, TestEdge.from( List.of( "BORN_IN" ) ) ); + assertEquals( 3, res.getData().length ); + containsEdges( res, true, TestEdge.from( List.of( "BORN_IN" ) ) ); execute( "MATCH (person:Person)\n" + "MERGE (location:Location {name: person.bornIn})\n" @@ -355,7 +358,7 @@ public void relationshipOnTwoExistingNodeMergeTest() { GraphResult edges = execute( "MATCH ()-[BORN_IN]->() RETURN BORN_IN" ); GraphResult nodes = execute( "MATCH (location:Location) RETURN Location " ); - assert edges.getData().length == 3 && nodes.getData().length == 3; + assertTrue( edges.getData().length == 3 && nodes.getData().length == 3 ); } @@ -370,19 +373,19 @@ public void relationshipOnExistingNodeAndMergeNodeDerivedFromAnodeProperty() { + "MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName})\n" ); GraphResult res = execute( "MATCH ( chauffeur :Chauffeur) Return Chauffeur.name" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( "John Brown" ) ), Row.of( TestLiteral.from( "Bob Brown" ) ), Row.of( TestLiteral.from( "John Brown" ) ) ); res = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); - assert res.getData().length == 3; - assert containsEdges( res, true, TestEdge.from( List.of( "HAS_CHAUFFEUR" ) ) ); + assertEquals( 3, res.getData().length ); + containsEdges( res, true, TestEdge.from( List.of( "HAS_CHAUFFEUR" ) ) ); execute( "MATCH (person:Person)\n" + "MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName})\n" ); GraphResult edges = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); GraphResult nodes = execute( "MATCH (n:Chauffeur) RETURN Chauffeur" ); - assert edges.getData().length == 3 && nodes.getData().length == 3; + assertTrue( edges.getData().length == 3 && nodes.getData().length == 3 ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java index 913a01692e..ce60845177 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java @@ -29,6 +29,8 @@ import java.util.Arrays; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; + @Slf4j public class RemoveTest extends CypherTestTemplate { @@ -48,7 +50,7 @@ public void labelRemoveTest() { execute( "MATCH (n:Person {name: 'Max'})\n" + "REMOVE n:Person " ); GraphResult res = execute( "MATCH (n :Person) RETURN n" ); - assert res.getData().length == 0; + assertEquals( 0, res.getData().length ); } @@ -60,7 +62,7 @@ public void returnWithRemoveTest() { GraphResult res = execute( "MATCH (n:Person {name: 'Max'})\n" + "REMOVE n:Person RETURN n " ); - assert res.getData().length == 1; + assertEquals( 1, res.getData().length ); } @@ -71,11 +73,11 @@ public void multipleLabelsRemoveTest() { execute( SINGLE_NODE_PERSON_EMPLOYEE ); GraphResult res = matchAndReturnAllNodes(); - assert containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ) ) ); + containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ) ) ); execute( "MATCH (n) REMOVE n:Person:Employee " ); res = execute( "MATCH (n :Person:Employee) RETURN n" ); - assert res.getData().length == 0; + assertEquals( 0, res.getData().length ); } @@ -86,7 +88,7 @@ public void singlePropertyNodeRemoveTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( "MATCH (n : Person {name: 'Ann'}) REMOVE a.age " ); GraphResult res = execute( "MATCH (n : Person) RETURN n.age , n.name" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); } @@ -99,7 +101,7 @@ public void multiplePropertiesRemoveTest() { + "REMOVE n.age, n.depno\n" ); GraphResult res = execute( "MATCH (n : Person) RETURN n.age , n.depno , n.name " ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); } @@ -109,7 +111,7 @@ public void allPropertiesNodeRemoveTest() { execute( SINGLE_NODE_PERSON_1 ); execute( "MATCH (n:Person) SET n = {}" ); GraphResult res = matchAndReturnAllNodes(); - assert res.getData().length == 0; + assertEquals( 0, res.getData().length ); } @@ -120,7 +122,7 @@ public void singlePropertyRelationshipRemoveTest() { execute( "MATCH(p1:Person)-[rel:KNOWS]->(p2:Person)\n" + "REMOVE rel.since" ); GraphResult res = execute( "MATCH ()-[r:KNOWS]->() RETURN r.since" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } @@ -132,7 +134,7 @@ public void multiplePropertiesRelationshipRemoveTest() { execute( "MATCH(p1:Person)-[rel:KNOWS]->(p2:Person)\n" + "REMOVE rel.since , rel.relation" ); GraphResult res = execute( "MATCH ()-[r:KNOWS]->() RETURN r.since , r.relation" ); - assert containsRows( res, true, true, + containsRows( res, true, true, Row.of( TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ) ) ); } @@ -143,7 +145,7 @@ public void allPropertiesRelationshipRemoveTest() { execute( SINGLE_EDGE_2 ); execute( "MATCH ()-[r:KNOWS]->() RETURN SET r = {}" ); GraphResult res = execute( "MATCH ()-[r:KNOWS]->() RETURN r.since" ); - assert containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } From 264a7adfc9f75d95e03e3b68c91c34728d32e5d9 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 18 Aug 2024 15:44:50 +0300 Subject: [PATCH 48/55] Refactor: "replace concatenation with text block remove unused import statement --- .../db/cypher/Functions/ListFunTest.java | 7 +- .../db/cypher/Functions/NumericFunTest.java | 40 ++-- .../db/cypher/Functions/OtherFunTest.java | 38 ++-- .../db/cypher/Functions/SpatialFunTest.java | 40 ++-- .../db/cypher/Functions/StringFunTest.java | 42 ++--- .../db/cypher/Functions/TemporalFunTest.java | 82 ++++---- .../db/cypher/Operators/BooleanOperators.java | 20 +- .../Operators/ComparisonOperations.java | 16 +- .../db/cypher/Operators/ListOperators.java | 10 +- .../Operators/MathematicalOperators.java | 15 +- .../db/cypher/Operators/StringOperators.java | 2 +- .../cypher/Subqueries/CallSubqueriesTest.java | 90 +++++---- .../Subqueries/CollectSubQueriesTest.java | 118 ++++++------ .../Subqueries/CountSubQueriesTest.java | 96 +++++----- .../Subqueries/ExistsSubQueriesTest.java | 113 +++++------ .../db/cypher/clause/general/CallTest.java | 135 +++++++------- .../db/cypher/clause/general/CaseTest.java | 32 +++- .../db/cypher/clause/general/FilterTest.java | 176 ++++++++++-------- .../db/cypher/clause/general/LimitTest.java | 32 ++-- .../db/cypher/clause/general/SkipTest.java | 7 +- .../db/cypher/clause/general/UnionTest.java | 117 +++++++----- .../db/cypher/clause/write/DmlDeleteTest.java | 6 +- .../db/cypher/clause/write/DmlInsertTest.java | 13 +- .../db/cypher/clause/write/DmlUpdateTest.java | 21 ++- .../db/cypher/clause/write/ForeachTest.java | 66 ++++--- .../db/cypher/clause/write/MergeTest.java | 119 +++++++----- .../db/cypher/clause/write/RemoveTest.java | 12 +- 27 files changed, 802 insertions(+), 663 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java index 1980524844..9f8f933cc4 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java @@ -54,9 +54,10 @@ public void nullSizeFunTest() { public void patternExpressionSizeFunTest() { execute( SINGLE_EDGE_1 ); execute( SINGLE_EDGE_1 ); - GraphResult res = execute( "MATCH (a)\n" - + "WHERE a.name = 'Max'\n" - + "RETURN size((a)-[]->())) AS fof" ); + GraphResult res = execute( """ + MATCH (a) + WHERE a.name = 'Max' + RETURN size((a)-[]->())) AS fof""" ); containsRows( res, true, true, Row.of( TestLiteral.from( 2 ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java index 7e2f153239..d780802709 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java @@ -35,32 +35,32 @@ public void reset() { public void absFunTest() { GraphResult res = execute( "RETURN ABS(-5) " ); - containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); res = execute( "RETURN ABS(5)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); res = execute( "RETURN ABS(0)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); } @Test public void roundFunTest() { GraphResult res = execute( "RETURN ROUND(3)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN ROUND(-3)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); res = execute( "RETURN ROUND(3.4)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN ROUND(3.5)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN ROUND(-3.5)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); } @@ -70,35 +70,35 @@ public void roundFunTest() { public void floorFunTest() { GraphResult res = execute( "RETURN FLOOR(3)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN FLOOR(-3)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( -3 ) ) ); res = execute( "RETURN FLOOR(3.16)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN FLOOR(3.9)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN FLOOR(-3.16)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); } @Test public void ceilFunTest() { GraphResult res = execute( "RETURN CEIL(3)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN CEIL(-3)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN CEIL(3.16)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); res = execute( "RETURN CEIL(3.5)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); } @@ -106,17 +106,17 @@ public void ceilFunTest() { @Test public void sqrtFunTest() { GraphResult res = execute( "RETURN SQRT(9)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); res = execute( "RETURN SQRT(0)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 0 ) ) ); } @Test public void nonPerfectSquareSqrtFunTest() { GraphResult res = execute( "RETURN SQRT(8)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( Math.sqrt( 8 ) ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( Math.sqrt( 8 ) ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java index 45de224f50..fa50c50552 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java @@ -16,14 +16,12 @@ package org.polypheny.db.cypher.Functions; -import org.checkerframework.checker.units.qual.K; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; -import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; public class OtherFunTest extends CypherTestTemplate { @@ -40,10 +38,12 @@ public void reset() { @Test public void typeFunTest() { execute( SINGLE_EDGE_1 ); - GraphResult res = execute( "MATCH (a)-[r]->(b)\n" - + "RETURN TYPE(r)\n" ); + GraphResult res = execute( """ + MATCH (a)-[r]->(b) + RETURN TYPE(r) + """ ); - containsRows( res, true, true, Row.of( TestLiteral.from( "OWNER_OF" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "OWNER_OF" ) ) ); } @@ -51,8 +51,10 @@ public void typeFunTest() { @Test public void idFunTest() { execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" - + "RETURN ID(p)\n" ); + GraphResult res = execute( """ + MATCH (p:Person { name: 'Max' }) + RETURN ID(p) + """ ); } @@ -64,7 +66,7 @@ public void testCoalesceFunTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); GraphResult result = execute( "MATCH (p) RETURN p.name, coalesce(p.age, 0) AS age" ); - containsRows( result, true, false, + containsRows( result, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 0 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 0 ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); @@ -80,7 +82,7 @@ public void testDefaultValuesWithCoalesceFunTest() { assertNode( result, 0 ); - containsRows( result, true, false, + containsRows( result, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "unknown" ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( "unknown" ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( "unknown" ) ) ); @@ -93,15 +95,19 @@ public void testDefaultValuesWithCoalesceFunTest() { @Test public void ExistFunTest() { execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (p:Person { name: 'Max' })\n" - + "RETURN EXISTS(p.age)\n" ); + GraphResult res = execute( """ + MATCH (p:Person { name: 'Max' }) + RETURN EXISTS(p.age) + """ ); - containsRows( res, true, true, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( false ) ) ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( "MATCH (p:Person { name: 'Ann' })\n" - + "RETURN EXISTS(p.age)\n" ); - containsRows( res, true, true, Row.of( TestLiteral.from( true ) ) ); + execute( """ + MATCH (p:Person { name: 'Ann' }) + RETURN EXISTS(p.age) + """ ); + containsRows( res, true, true, Row.of( TestLiteral.from( true ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java index 6900dab39f..14fb958507 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java @@ -16,7 +16,7 @@ package org.polypheny.db.cypher.Functions; -import javassist.bytecode.CodeIterator.Gap; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -35,14 +35,15 @@ public void reset() { @Test public void cartesian2DPointFunTest() { - GraphResult res = execute( "WITH point({x: 3, y: 4}) AS p\n" - + "RETURN\n" - + " p.x AS x,\n" - + " p.y AS y,\n" - + " p.crs AS crs,\n" - + " p.srid AS srid" ); + GraphResult res = execute( """ + WITH point({x: 3, y: 4}) AS p + RETURN + p.x AS x, + p.y AS y, + p.crs AS crs, + p.srid AS srid""" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 3.0 ), TestLiteral.from( 4.0 ), TestLiteral.from( "cartesian" ), TestLiteral.from( 7203 ) ) ); } @@ -50,18 +51,19 @@ public void cartesian2DPointFunTest() { @Test public void WGS_843DPointFunTest() { - GraphResult res = execute( "WITH point({latitude: 3, longitude: 4, height: 4321}) AS p\n" - + "RETURN\n" - + " p.latitude AS latitude,\n" - + " p.longitude AS longitude,\n" - + " p.height AS height,\n" - + " p.x AS x,\n" - + " p.y AS y,\n" - + " p.z AS z,\n" - + " p.crs AS crs,\n" - + " p.srid AS srid" ); + GraphResult res = execute( """ + WITH point({latitude: 3, longitude: 4, height: 4321}) AS p + RETURN + p.latitude AS latitude, + p.longitude AS longitude, + p.height AS height, + p.x AS x, + p.y AS y, + p.z AS z, + p.crs AS crs, + p.srid AS srid""" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 3.0 ), TestLiteral.from( 4.0 ), TestLiteral.from( 4321.0 ), diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java index 527496e428..c2470a67d9 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java @@ -34,9 +34,9 @@ public void reset() { @Test public void upperFunTest() { GraphResult res = execute( "RETURN UPPER('hello')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); res = execute( "RETURN UPPER('hElLo')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); } @@ -45,85 +45,85 @@ public void upperFunTest() { @Test public void EmptyUpperFunTest() { GraphResult res = execute( "RETURN UPPER('')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void nullUpperFunTest() { GraphResult res = execute( "RETURN UPPER(null)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } @Test public void LowerFunTest() { GraphResult res = execute( "RETURN LOWER('WORLD')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); res = execute( "RETURN LOWER('WOrLd')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); } @Test public void emptyLowerFunTest() { GraphResult res = execute( "RETURN LOWER('')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void nullLowerFunTest() { GraphResult res = execute( "RETURN LOWER(null)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } @Test public void normalSubstringFunTest() { GraphResult res = execute( "RETURN SUBSTRING('Hello, world!', 0, 5)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); res = execute( "RETURN SUBSTRING('Hello, world!', 7, 5)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); res = execute( "RETURN SUBSTRING('Hello, world!', 7, 0)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void exceedLengthSubstringFunTest() { GraphResult res = execute( "RETURN SUBSTRING('Hello', 0, 10)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello" ) ) ); } @Test public void trimFunTest() { GraphResult res = execute( "RETURN TRIM(' hello ')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); res = execute( "RETURN TRIM('hello')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "hello" ) ) ); res = execute( "RETURN TRIM(' ')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void emptyTrimFunTest() { GraphResult res = execute( "RETURN TRIM('')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @Test public void normalReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', 'Cypher') " ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); } @@ -131,28 +131,28 @@ public void normalReplaceFunTest() { @Test public void caseSensitiveReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'WORLD', 'Cypher')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, world!" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, world!" ) ) ); } @Test public void removeSpacesReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', ' ', '')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Hello,world!" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello,world!" ) ) ); } @Test public void removeSubstringReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', '')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, !" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, !" ) ) ); } @Test public void stringLengthFunTest() { GraphResult res = execute( "RETURN LENGTH('Hello, world!')" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 13 ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( 13 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java index adb973d2b9..333dab11dc 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java @@ -35,19 +35,19 @@ public void reset() { public void stringIntoDateFunTest() { GraphResult res = execute( "RETURN date('2015-07-21')\n" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); res = execute( "RETURN date('2015-07')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); res = execute( "RETURN date('201507')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-01" ) ) ); res = execute( "RETURN date('2015-W30-2')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); res = execute( "RETURN date('2015')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01" ) ) ); } @@ -55,29 +55,29 @@ public void stringIntoDateFunTest() { public void yearMonthDayDateFunTest() { GraphResult res = execute( "RETURN date({year: 1984, month: 10, day: 11})" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11" ) ) ); res = execute( "RETURN date({year: 1984, month: 10})" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-01" ) ) ); res = execute( "RETURN date({year: 1984})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-01-01" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-01-01" ) ) ); } @Test public void yearWeekDayDateFunTest() { GraphResult res = execute( "RETURN date({year: 1984, week: 10, dayOfWeek: 3})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07" ) ) ); } @Test public void yearQuarterDayDateFunTest() { GraphResult res = execute( "RETURN date({year: 1984, quarter: 3, dayOfQuarter: 45})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14" ) ) ); } @@ -85,13 +85,13 @@ public void yearQuarterDayDateFunTest() { public void yearMonthDayZonedTimeDateFunTest() { GraphResult res = execute( "RETURN datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 123, microsecond: 456, nanosecond: 789}) AS theDate" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.123456789Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.123456789Z" ) ) ); res = execute( "datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 645, timezone: '+01:00'})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.645+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.645+01:00" ) ) ); res = execute( "RETURN datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14Z" ) ) ); } @@ -100,14 +100,14 @@ public void yearMonthDayZonedTimeDateFunTest() { @Test public void yearWeekDayTimeDateFunTest() { GraphResult res = execute( "RETURN datetime({year: 1984, week: 10, dayOfWeek: 3, hour: 12, minute: 31, second: 14, millisecond: 645})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07T12:31:14.645Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-03-07T12:31:14.645Z" ) ) ); } @Test public void yearQuarterDayTimeDateFunTest() { GraphResult res = execute( "RETURN datetime({year: 1984, quarter: 3, dayOfQuarter: 45, hour: 12, minute: 31, second: 14, microsecond: 645876})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14T12:31:14.645876Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14T12:31:14.645876Z" ) ) ); } @@ -116,22 +116,22 @@ public void yearQuarterDayTimeDateFunTest() { public void stringIntoTimeDateFunTest() { GraphResult res = execute( "RETURN datetime('2015-07-21T21:40:32.142+0100')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142+01:00" ) ) ); res = execute( "RETURN datetime('2015-W30-2T214032.142Z')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142Z" ) ) ); res = execute( "RETURN datetime('2015T214032-0100')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01T21:40:32-01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01T21:40:32-01:00" ) ) ); res = execute( "RETURN datetime('20150721T21:40-01:30')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40-01:30" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40-01:30" ) ) ); res = execute( "RETURN datetime('2015-07-21T21:40:32.142[Europe/London]')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "datetime('2015-07-21T21:40:32.142[Europe/London]')" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "datetime('2015-07-21T21:40:32.142[Europe/London]')" ) ) ); } @@ -140,19 +140,19 @@ public void stringIntoTimeDateFunTest() { public void timeFunTest() { GraphResult res = execute( "RETURN time({hour: 12, minute: 31, second: 14, millisecond: 123, microsecond: 456, nanosecond: 789})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.123456789Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.123456789Z" ) ) ); res = execute( "RETURN time({hour: 12, minute: 31, second: 14, nanosecond: 645876123})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876123Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876123Z" ) ) ); res = execute( "RETURN time({hour: 12, minute: 31, second: 14, microsecond: 645876, timezone: '+01:00'})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876000+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.645876000+01:00" ) ) ); res = execute( "time({hour: 12, minute: 31, timezone: '+01:00'})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:00+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:00+01:00" ) ) ); res = execute( "RETURN time({hour: 12, timezone: '+01:00'})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "12:00:00+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "12:00:00+01:00" ) ) ); } @@ -160,16 +160,16 @@ public void timeFunTest() { @Test public void stringIntoTimeFunTest() { GraphResult res = execute( "RETURN time('21:40:32.142+0100')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000+01:00" ) ) ); res = execute( "RETURN time('214032.142Z')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000Z" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32.142000000Z" ) ) ); res = execute( "RETURN time('21:40:32+01:00')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32+01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32+01:00" ) ) ); res = execute( "RETURN time('214032-0100')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32-01:00" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32-01:00" ) ) ); } @@ -179,22 +179,22 @@ public void stringIntoTimeFunTest() { public void durationFunTest() { GraphResult res = execute( "RETURN duration({days: 14, hours:16, minutes: 12})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); res = execute( "RETURN duration({months: 5, days: 1.5})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); res = execute( "RETURN duration({months: 0.75})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); res = execute( "RETURN duration({weeks: 2.5})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P17DT12H" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P17DT12H" ) ) ); res = execute( "RETURN duration({minutes: 1.5, seconds: 1, milliseconds: 123, microseconds: 456, nanoseconds: 789})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); res = execute( "RETURN duration({minutes: 1.5, seconds: 1, nanoseconds: 123456789})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); } @@ -203,18 +203,18 @@ public void durationFunTest() { @Test public void stringIntoDurationFunTest() { GraphResult res = execute( "RETURN duration(\"P14DT16H12M\") " ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); res = execute( "RETURN duration(\"P5M1.5D\")" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); res = execute( "RETURN duration(\"P0.75M\") " ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P22DT19H51M49.5S" ) ) ); res = execute( "RETURN duration(\"PT0.75M\")" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "PT45S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "PT45S" ) ) ); res = execute( "RETURN duration(\"P2012-02-02T14:37:21.545\")" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P2012Y2M2DT14H37M21.545S" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P2012Y2M2DT14H37M21.545S" ) ) ); } @@ -223,7 +223,7 @@ public void stringIntoDurationFunTest() { @Test public void durationBetweenFunTest() { GraphResult res = execute( "RETURN duration.between(date('1984-10-11'), date('2015-06-24')) AS theDuration" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "P30Y8M13D" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "P30Y8M13D" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java index a547accbe5..5a49b3ffe8 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java @@ -16,7 +16,7 @@ package org.polypheny.db.cypher.Operators; -import net.bytebuddy.description.type.TypeList.Generic; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -35,9 +35,9 @@ public void setUp() { @Test public void conjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a AND b " ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH true as a , true as b RETURN a AND b " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @@ -45,9 +45,9 @@ public void conjunctionOperatorTest() { @Test public void disjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a OR b " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "WITH false as a , false as b RETURN a OR b " ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @@ -55,11 +55,11 @@ public void disjunctionOperatorTest() { @Test public void exclusiveDisjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a XOR b " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "WITH true as a , true as b RETURN a XOR b " ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH false as a , false as b RETURN a XOR b " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @@ -67,10 +67,10 @@ public void exclusiveDisjunctionOperatorTest() { @Test public void negationOperatorTest() { GraphResult res = execute( "WITH true as a RETURN NOT a " ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); res = execute( "WITH false as a RETURN NOT a " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java index 87afb96ddf..5e3c1212a6 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java @@ -34,14 +34,14 @@ public void setUp() { @Test public void IsNullOperatorTest() { GraphResult res = execute( "Return null is not null as Result" ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @Test public void IsNotNullFunction() { GraphResult res = execute( "Return null is null as Result" ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @@ -49,42 +49,42 @@ public void IsNotNullFunction() { @Test public void greaterThanOperatorTest() { GraphResult res = execute( "Return 1 > 2 as result " ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @Test public void smallerThanOperatorTest() { GraphResult res = execute( "Return 1 < 2 as result " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @Test public void greaterThanOrEqualOperatorTest() { GraphResult res = execute( "Return 1 >= 2 as result " ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @Test public void smallerThanOrEqualOperatorTest() { GraphResult res = execute( "Return 1 <= 2 as result " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @Test public void equalityOperatorTest() { GraphResult res = execute( "Return 2 = 2 as result " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); } @Test public void inequalityOperatorTest() { GraphResult res = execute( "Return 1 <> 2 as result " ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java index 10a68b5c19..d1829c439c 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java @@ -16,7 +16,7 @@ package org.polypheny.db.cypher.Operators; -import javassist.bytecode.CodeIterator.Gap; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -35,20 +35,20 @@ public void setUp() { @Test public void checkIfNumberInListOperatorTest() { GraphResult res = execute( "RETURN 1 IN [ 1 ,2 ]" ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "RETURN 3 IN [ 1 ,2 ]" ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } @Test public void checkIfListInListOperatorTest() { GraphResult res = execute( "RETURN [2, 1] IN [1, [2, 1], 3] " ); - containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); res = execute( "RETURN [1, 2] IN [1, 2] " ); - containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java index 06cccbb6a9..e70701d091 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java @@ -16,13 +16,12 @@ package org.polypheny.db.cypher.Operators; -import javassist.bytecode.CodeIterator.Gap; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; public class MathematicalOperators extends CypherTestTemplate { @@ -36,7 +35,7 @@ public void reset() { @Test public void additionOperator() { GraphResult res = execute( "RETURN 2 + 3" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 5 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 5 ) ) ); } @@ -44,7 +43,7 @@ public void additionOperator() { public void minisOperatorTest() { GraphResult res = execute( "RETURN 3 - 2" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } @@ -53,7 +52,7 @@ public void minisOperatorTest() { public void multiplicationOperatorTest() { GraphResult res = execute( "RETURN 2 * 3" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 6 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 6 ) ) ); } @@ -61,14 +60,14 @@ public void multiplicationOperatorTest() { public void divisionOperatorTest() { GraphResult res = execute( "RETURN 6 / 3 " ); - containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @Test public void moduleOperatorTest() { GraphResult res = execute( "RETURN 3 % 2 " ); - containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } @@ -77,7 +76,7 @@ public void moduleOperatorTest() { public void exponentiationOperator() { GraphResult res = execute( "RETURN 2 ^ 3" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 8.0 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 8.0 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java index 861d71a58e..210eff42f6 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java @@ -35,7 +35,7 @@ public void setUp() { @Test public void concatenateWithPlusOperatorTest() { GraphResult res = execute( "RETURN 'neo' + '4j' AS result" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "neo4j" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "neo4j" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java index 501d0da942..1aa0687eac 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java @@ -16,7 +16,7 @@ package org.polypheny.db.cypher.Subqueries; -import com.google.common.util.concurrent.AbstractScheduledService; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -25,7 +25,6 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; import java.util.List; -import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -52,9 +51,10 @@ public void simpleCallTest() { @Test public void repeatCallTest() { - GraphResult res = execute( "UNWIND [0, 1, 2] AS x\n" - + "CALL { RETURN 'hello' AS innerReturn }\n" - + "RETURN innerReturn" ); + GraphResult res = execute( """ + UNWIND [0, 1, 2] AS x + CALL { RETURN 'hello' AS innerReturn } + RETURN innerReturn""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "hello" ) ), @@ -65,9 +65,10 @@ public void repeatCallTest() { @Test public void unwindVariablesAsInputsIntoCallTest() { - GraphResult res = execute( "UNWIND [0, 1, 2] AS x\n" - + "CALL { WITH x RETURN x * 10 AS y }\n" - + "RETURN x, y" ); + GraphResult res = execute( """ + UNWIND [0, 1, 2] AS x + CALL { WITH x RETURN x * 10 AS y } + RETURN x, y""" ); containsRows( res, true, true, Row.of( TestLiteral.from( 0 ), TestLiteral.from( 0 ) ), @@ -90,10 +91,12 @@ public void countNodesCallTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "CALL {\n" - + " MATCH (p)\n" - + " RETURN count(p) AS totalPeople}\n" - + "RETURN totalPeople\n" ); + GraphResult res = execute( """ + CALL { + MATCH (p) + RETURN count(p) AS totalPeople} + RETURN totalPeople + """ ); containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); @@ -104,10 +107,12 @@ public void countNodesCallTest() { public void countRelationshipsCallTest() { execute( SINGLE_EDGE_1 ); execute( SINGLE_EDGE_2 ); - GraphResult res = execute( "CALL {\n" - + " MATCH ()-[r]->()\n" - + " RETURN count(r) AS totalRelationships }\n" - + "RETURN totalRelationships\n" ); + GraphResult res = execute( """ + CALL { + MATCH ()-[r]->() + RETURN count(r) AS totalRelationships } + RETURN totalRelationships + """ ); containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @@ -117,13 +122,14 @@ public void countRelationshipsCallTest() { public void useMatchedNodesAsInputsIntoCallTest() { execute( SINGLE_EDGE_2 ); - GraphResult res = execute( "MATCH (p:Person)\n" - + "CALL {\n" - + " WITH p\n" - + " MATCH (p)-[:KNOWS]-(c:Person)\n" - + " RETURN c.name AS friend\n" - + "}\n" - + "RETURN p.name, friend" ); + GraphResult res = execute( """ + MATCH (p:Person) + CALL { + WITH p + MATCH (p)-[:KNOWS]-(c:Person) + RETURN c.name AS friend + } + RETURN p.name, friend""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Hans" ) ) ); @@ -135,12 +141,14 @@ public void FilterMatchedNodesByOutputOfCallTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "CALL {\n" - + " MATCH (p:Person { name: 'Bob' })\n" - + " RETURN p.age AS age}\n" - + "MATCH (p:Person)\n" - + "WHERE p.age > age\n" - + "RETURN p\n" ); + GraphResult res = execute( """ + CALL { + MATCH (p:Person { name: 'Bob' }) + RETURN p.age AS age} + MATCH (p:Person) + WHERE p.age > age + RETURN p + """ ); assertEquals( 2, res.getData().length ); containsNodes( res, true, @@ -155,13 +163,14 @@ public void UnionCallTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "CALL { MATCH (p:Person)\n" - + " RETURN p\n" - + "UNION\n" - + " MATCH (p:Person)\n" - + " RETURN p\n" - + "}\n" - + "RETURN p.name, p.age" ); + GraphResult res = execute( """ + CALL { MATCH (p:Person) + RETURN p + UNION + MATCH (p:Person) + RETURN p + } + RETURN p.name, p.age""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), @@ -174,10 +183,11 @@ public void unitSubQueryCallTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (p:Person) CALL { \n" - + "WITH p\n" - + " CREATE (:Person {name: p.name}) \n" - + "} RETURN count(*)" ); + GraphResult res = execute( """ + MATCH (p:Person) CALL { \s + WITH p + CREATE (:Person {name: p.name})\s + } RETURN count(*)""" ); //the number of rows present after the subquery is the same as was going into the subquery containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java index bfd8f129d5..1f4a7442b0 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java @@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; -import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; import java.util.List; @@ -41,11 +40,12 @@ public void reset() { public void simpleCollectSubQueryTest() { execute( SINGLE_EDGE_1 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "WHERE 'Kira' IN COLLECT { MATCH (person)-[:OWNER_OF]->(a:Animal) RETURN a.name }\n" - + "RETURN person.name AS name" ); + GraphResult res = execute( """ + MATCH (person:Person) + WHERE 'Kira' IN COLLECT { MATCH (person)-[:OWNER_OF]->(a:Animal) RETURN a.name } + RETURN person.name AS name""" ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -54,14 +54,15 @@ public void simpleCollectSubQueryTest() { public void useCollectSubQueryInReturnTest() { execute( SINGLE_NODE_PERSON_1 ); execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN person.name,\n" - + " COLLECT {\n" - + " MATCH (person)-[:OWNER_OF]->(d:Dog)\n" - + " RETURN d.name\n" - + " } as DogNames" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + RETURN person.name, + COLLECT { + MATCH (person)-[:OWNER_OF]->(d:Dog) + RETURN d.name + } as DogNames""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); } @@ -70,15 +71,17 @@ public void useCollectSubQueryInReturnTest() { @Test public void whereWithCollectSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "\n" - + "MATCH (person:Person)\n" - + "RETURN person.name as name, COLLECT {\n" - + " MATCH (person)-[r:OWNER_OF]->(a:Dog)\n" - + " WHERE a.age <= 3\n" - + " RETURN a.name\n" - + "} as youngDog \n" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + + MATCH (person:Person) + RETURN person.name as name, COLLECT { + MATCH (person)-[r:OWNER_OF]->(a:Dog) + WHERE a.age <= 3 + RETURN a.name + } as youngDog\s + """ ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); } @@ -87,18 +90,19 @@ public void whereWithCollectSubQueryTest() { @Test public void unionWithCollectSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN\n" - + " person.name AS name,\n" - + " COLLECT {\n" - + " MATCH (person)-[:HAS_DOG]->(dog:Dog)\n" - + " RETURN dog.name AS petName\n" - + " UNION\n" - + " MATCH (person)-[:HAS_CAT]->(cat:Cat)\n" - + " RETURN cat.name AS petName\n" - + " } AS petNames" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + RETURN + person.name AS name, + COLLECT { + MATCH (person)-[:HAS_DOG]->(dog:Dog) + RETURN dog.name AS petName + UNION + MATCH (person)-[:HAS_CAT]->(cat:Cat) + RETURN cat.name AS petName + } AS petNames""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( List.of( "Andy", "Mittens" ) ) ) ); @@ -108,15 +112,16 @@ public void unionWithCollectSubQueryTest() { @Test public void withClauseWithCollectSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN person.name AS name, COLLECT {\n" - + " WITH 1999 AS yearOfTheDog\n" - + " MATCH (person)-[r:OWNER_OF]->(d:Dog)\n" - + " WHERE r.since = yearOfTheDog\n" - + " RETURN d.name\n" - + "} as dogsOfTheYear" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + RETURN person.name AS name, COLLECT { + WITH 1999 AS yearOfTheDog + MATCH (person)-[r:OWNER_OF]->(d:Dog) + WHERE r.since = yearOfTheDog + RETURN d.name + } as dogsOfTheYear""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); } @@ -125,14 +130,15 @@ public void withClauseWithCollectSubQueryTest() { public void caseWithCollectSubQueryTest() { execute( EDGE_3 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN\n" - + " CASE\n" - + " WHEN COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name } = [] THEN \" No Dogs \" + person.name\n" - + " ELSE person.name\n" - + " END AS result" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + RETURN + CASE + WHEN COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name } = [] THEN " No Dogs " + person.name + ELSE person.name + END AS result""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "No Dogs" ) ), Row.of( TestLiteral.from( "Max" ) ) ); @@ -143,12 +149,12 @@ public void caseWithCollectSubQueryTest() { public void updateWithCollectSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)" - + " WHERE person.name = \"Hans\"\n" - + "SET person.dogNames = COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name }\n" - + "RETURN person.dogNames as dogNames" ); + GraphResult res = execute( """ + MATCH (person:Person) WHERE person.name = "Hans" + SET person.dogNames = COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name } + RETURN person.dogNames as dogNames""" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Andy" ) ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java index 9e048a8127..a6c6bf800f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java @@ -16,7 +16,7 @@ package org.polypheny.db.cypher.Subqueries; -import org.bouncycastle.crypto.modes.G3413CBCBlockCipher; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -40,11 +40,12 @@ public void simpleCountSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "WHERE COUNT { (person)-[r:OWNER_OF]->(:Animal) } > 1\n" - + "RETURN person.name AS name" ); + GraphResult res = execute( """ + MATCH (person:Person) + WHERE COUNT { (person)-[r:OWNER_OF]->(:Animal) } > 1 + RETURN person.name AS name""" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -55,7 +56,7 @@ public void useCountSubQueryInReturnTest() { GraphResult res = execute( "MATCH (person:Person)\n" + "RETURN person.name, COUNT { (person)-[:OWNER_OF]->(:Dog) } as howManyDogs" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 1 ) ) ); } @@ -65,13 +66,14 @@ public void useCountSubQueryInReturnTest() { public void whereWithCountSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "WHERE COUNT {\n" - + " (person)-[r:OWNER_OF]->(dog:Dog)\n" - + " WHERE person.name = dog.name } = 1\n" - + "RETURN person.name AS name" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + WHERE COUNT { + (person)-[r:OWNER_OF]->(dog:Dog) + WHERE person.name = dog.name } = 1 + RETURN person.name AS name""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -80,18 +82,19 @@ public void whereWithCountSubQueryTest() { public void unionWithCountSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN\n" - + " person.name AS name,\n" - + " COUNT {\n" - + " MATCH (person)-[:OWNER_OF]->(dog:Dog)\n" - + " RETURN dog.name AS petName\n" - + " UNION\n" - + " MATCH (person)-[:OWNER_OF]->(cat:Cat)\n" - + " RETURN cat.name AS petName\n" - + " } AS numPets" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + RETURN + person.name AS name, + COUNT { + MATCH (person)-[:OWNER_OF]->(dog:Dog) + RETURN dog.name AS petName + UNION + MATCH (person)-[:OWNER_OF]->(cat:Cat) + RETURN cat.name AS petName + } AS numPets""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 2 ) ) ); } @@ -99,15 +102,16 @@ public void unionWithCountSubQueryTest() { @Test public void withClauseWithCountSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "WHERE COUNT {\n" - + " WITH \"Andy\" AS dogName\n" - + " MATCH (person)-[:OWNER_OF]->(d:Dog)\n" - + " WHERE d.name = dogName\n" - + "} = 1\n" - + "RETURN person.name AS name" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + WHERE COUNT { + WITH "Andy" AS dogName + MATCH (person)-[:OWNER_OF]->(d:Dog) + WHERE d.name = dogName + } = 1 + RETURN person.name AS name""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -117,11 +121,12 @@ public void withClauseWithCountSubQueryTest() { public void updateWithCountSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person) WHERE person.name =\"Max\"\n" - + "SET person.howManyDogs = COUNT { (person)-[:OWNER_OF]->(:Dog) }\n" - + "RETURN person.howManyDogs as howManyDogs" ); + GraphResult res = execute( """ + MATCH (person:Person) WHERE person.name ="Max" + SET person.howManyDogs = COUNT { (person)-[:OWNER_OF]->(:Dog) } + RETURN person.howManyDogs as howManyDogs""" ); - containsRows( res, true, false, Row.of( + containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); @@ -132,13 +137,14 @@ public void updateWithCountSubQueryTest() { public void caseWithCountSubQueryTest() { execute( EDGE_3 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN\n" - + " CASE\n" - + " WHEN COUNT { (person)-[:OWNER_OF]->(:Dog) } >= 1 THEN \"DogLover \" + person.name\n" - + " ELSE person.name\n" - + " END AS result" ); - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + RETURN + CASE + WHEN COUNT { (person)-[:OWNER_OF]->(:Dog) } >= 1 THEN "DogLover " + person.name + ELSE person.name + END AS result""" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "DogLover" ) ), Row.of( TestLiteral.from( "Hans" ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java index 86a4ad47f1..1e700ff44f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java @@ -37,35 +37,38 @@ public void reset() { @Test public void simpleExistsSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "WHERE EXISTS {\n" - + " (person)-[:OWNER_OF]->(:Dog)\n" - + "}\n" - + "RETURN person.name AS name" ); - - containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); + GraphResult res = execute( """ + MATCH (person:Person) + WHERE EXISTS { + (person)-[:OWNER_OF]->(:Dog) + } + RETURN person.name AS name""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); execute( EDGE_3 ); - execute( "MATCH (person:Person)\n" - + "WHERE EXISTS {\n" - + " (person)-[:OWNER_OF]->(:Dog)\n" - + "}\n" - + "RETURN person.name AS name" ); - - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + execute( """ + MATCH (person:Person) + WHERE EXISTS { + (person)-[:OWNER_OF]->(:Dog) + } + RETURN person.name AS name""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @Test public void whereWithExistsSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "WHERE EXISTS {\n" - + " MATCH (person)-[:OWNER_OF]->(dog:Dog)\n" - + " WHERE person.name = \"Max\" \n" - + "}\n" - + "RETURN dog.name AS name" ); + GraphResult res = execute( """ + MATCH (person:Person) + WHERE EXISTS { + MATCH (person)-[:OWNER_OF]->(dog:Dog) + WHERE person.name = "Max"\s + } + RETURN dog.name AS name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Andy" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Andy" ) ) ); } @@ -74,17 +77,18 @@ public void whereWithExistsSubQueryTest() { public void nestedExistsSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "WHERE EXISTS {\n" - + " MATCH (person)-[:OWNER_OF]->(dog:Dog)\n" - + " WHERE EXISTS {\n" - + " MATCH (dog)-[:HAS_TOY]->(toy:Toy)\n" - + " WHERE toy.name = 'Banana'\n" - + " }\n" - + "}\n" - + "RETURN person.name AS name" ); + GraphResult res = execute( """ + MATCH (person:Person) + WHERE EXISTS { + MATCH (person)-[:OWNER_OF]->(dog:Dog) + WHERE EXISTS { + MATCH (dog)-[:HAS_TOY]->(toy:Toy) + WHERE toy.name = 'Banana' + } + } + RETURN person.name AS name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -93,12 +97,13 @@ public void nestedExistsSubQueryTest() { @Test public void returnExistsSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN person.name AS name, EXISTS {\n" - + " MATCH (person)-[:OWNER_OF]->(:Dog)\n" - + "} AS hasDog" ); + GraphResult res = execute( """ + MATCH (person:Person) + RETURN person.name AS name, EXISTS { + MATCH (person)-[:OWNER_OF]->(:Dog) + } AS hasDog""" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( true ) ) ); } @@ -108,15 +113,16 @@ public void unionWithExistsSubQueryTest() { execute( EDGE_3 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN\n" - + " person.name AS name,\n" - + " EXISTS {\n" - + " MATCH (person)-[:HAS_DOG]->(:Dog)\n" - + " UNION\n" - + " MATCH (person)-[:HAS_CAT]->(:Cat)\n" - + " } AS hasPet" ); - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person) + RETURN + person.name AS name, + EXISTS { + MATCH (person)-[:HAS_DOG]->(:Dog) + UNION + MATCH (person)-[:HAS_CAT]->(:Cat) + } AS hasPet""" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( true ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( false ) ) ); } @@ -125,14 +131,15 @@ public void unionWithExistsSubQueryTest() { @Test public void withClauseWithExistsSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person {name: name})\n" - + "WHERE EXISTS {\n" - + " WITH \"Andy\" AS name\n" - + " MATCH (person)-[:OWNER_OF]->(d:Dog)\n" - + " WHERE d.name = name\n" - + "}\n" - + "RETURN person.name AS name" ); - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (person:Person {name: name}) + WHERE EXISTS { + WITH "Andy" AS name + MATCH (person)-[:OWNER_OF]->(d:Dog) + WHERE d.name = name + } + RETURN person.name AS name""" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java index 51b3252eb8..84b143dc2e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java @@ -34,47 +34,46 @@ public void reset() { @Test public void simpleCallProcedureTest() { GraphResult res = execute( "CALL db.labels()" ); - assertEmpty (res); + assertEmpty( res ); execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); - res = execute( "CALL db.labels()" ); + res = execute( "CALL db.labels()" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); - execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); res = execute( "CALL db.labels()" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ), - Row.of( TestLiteral.from( "Animal" ) )); + Row.of( TestLiteral.from( "Animal" ) ) ); } - @Test public void callLabelsYieldTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); - GraphResult res = execute( "CALL db.labels() YIELD label" ); - containsRows( res, true, false, + GraphResult res = execute( "CALL db.labels() YIELD label" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); } + @Test public void renameCallLabelsYieldTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); - GraphResult res = execute( "CALL db.labels() YIELD label As Label" ); - containsRows( res, true, false, + GraphResult res = execute( "CALL db.labels() YIELD label As Label" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); } @@ -84,97 +83,103 @@ public void renameCallLabelsYieldTest() { public void callLabelsYieldCountTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); - GraphResult res = execute( "CALL db.labels() YIELD *" ); - containsRows( res, true, false, - Row.of( TestLiteral.from( 2 ) )); + GraphResult res = execute( "CALL db.labels() YIELD *" ); + containsRows( res, true, false, + Row.of( TestLiteral.from( 2 ) ) ); } + @Test public void returnCallLabelsYieldTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); - GraphResult res = execute( "CALL db.labels() YIELD label\n" + GraphResult res = execute( "CALL db.labels() YIELD label\n" + "RETURN label" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } + @Test public void returnFilterCallLabelsYieldTest() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_ANIMAL); - GraphResult res = execute("CALL db.labels() YIELD label WHERE label = 'Person' RETURN count(label) AS numLabels"); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult res = execute( "CALL db.labels() YIELD label WHERE label = 'Person' RETURN count(label) AS numLabels" ); - containsRows(res, true, false, - Row.of(TestLiteral.from(1))); + containsRows( res, true, false, + Row.of( TestLiteral.from( 1 ) ) ); } + @Test public void callLabelsYieldWithOrderingTest() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_PERSON_2); - execute(SINGLE_NODE_ANIMAL); - GraphResult res = execute("CALL db.labels() YIELD label RETURN label ORDER BY label"); - - containsRows(res, true, false, - Row.of(TestLiteral.from("Animal")), - Row.of(TestLiteral.from("Person")), - Row.of(TestLiteral.from("Person"))); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_PERSON_2 ); + execute( SINGLE_NODE_ANIMAL ); + GraphResult res = execute( "CALL db.labels() YIELD label RETURN label ORDER BY label" ); + + containsRows( res, true, false, + Row.of( TestLiteral.from( "Animal" ) ), + Row.of( TestLiteral.from( "Person" ) ), + Row.of( TestLiteral.from( "Person" ) ) ); } + @Test public void callLabelsYieldWithAggregationTest() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_ANIMAL); - execute(SINGLE_NODE_PERSON_2); - GraphResult res = execute("CALL db.labels() YIELD label RETURN label, count(*) AS labelCount"); - - containsRows(res, true, false, - Row.of(TestLiteral.from("Person"), TestLiteral.from(2)), - Row.of(TestLiteral.from("Animal"), TestLiteral.from(1))); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "CALL db.labels() YIELD label RETURN label, count(*) AS labelCount" ); + + containsRows( res, true, false, + Row.of( TestLiteral.from( "Person" ), TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( "Animal" ), TestLiteral.from( 1 ) ) ); } + @Test public void simpleCallPropertyKeysYieldTest() { - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_ANIMAL); - execute(SINGLE_NODE_PERSON_2); - GraphResult res = execute("CALL db.propertyKeys() YIELD propertyKey "); - containsRows(res, true, false, - Row.of(TestLiteral.from("name")), - Row.of(TestLiteral.from("age")), - Row.of(TestLiteral.from("type"))); + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "CALL db.propertyKeys() YIELD propertyKey " ); + containsRows( res, true, false, + Row.of( TestLiteral.from( "name" ) ), + Row.of( TestLiteral.from( "age" ) ), + Row.of( TestLiteral.from( "type" ) ) ); } + @Test public void renameCallPropertyKeysYieldTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); - GraphResult res = execute( "CALL db.propertyKeys() YIELD propertyKey AS prop" ); - containsRows( res, true, false, + GraphResult res = execute( "CALL db.propertyKeys() YIELD propertyKey AS prop" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); } + + @Test - public void callPropertyKeysYieldWithMatchTest() - { - - execute(SINGLE_NODE_PERSON_1); - execute(SINGLE_NODE_ANIMAL); - execute(SINGLE_NODE_PERSON_2); - GraphResult res = execute( "CALL db.propertyKeys() YIELD propertyKey AS prop\n" - + "MATCH (n)\n" - + "WHERE n[prop] IS NOT NULL\n" - + "RETURN prop, count(n) AS numNodes" ); - - - containsRows(res, true, false, - Row.of(TestLiteral.from("name") , TestLiteral.from( 3 )), - Row.of(TestLiteral.from("age") ,TestLiteral.from( 1)), - Row.of(TestLiteral.from("type") ,TestLiteral.from( 1 ))); - } + public void callPropertyKeysYieldWithMatchTest() { + execute( SINGLE_NODE_PERSON_1 ); + execute( SINGLE_NODE_ANIMAL ); + execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( """ + CALL db.propertyKeys() YIELD propertyKey AS prop + MATCH (n) + WHERE n[prop] IS NOT NULL + RETURN prop, count(n) AS numNodes""" ); + + containsRows( res, true, false, + Row.of( TestLiteral.from( "name" ), TestLiteral.from( 3 ) ), + Row.of( TestLiteral.from( "age" ), TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( "type" ), TestLiteral.from( 1 ) ) ); + } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java index 2f4a59fdd7..5f3921dd39 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java @@ -42,14 +42,14 @@ public void simpleCaseTest() { execute( PERSON_NODE_ALICE ); execute( PERSON_NODE_BOB ); execute( PERSON_NODE_CHARLIE ); - GraphResult res = execute(""" + GraphResult res = execute( """ MATCH (n:Person) RETURN CASE n.eyes WHEN 'blue' THEN 1 WHEN 'brown' THEN 2 ELSE 3 - END AS result, n.eyes"""); + END AS result, n.eyes""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); @@ -63,7 +63,14 @@ public void GenericCaseTest() { execute( PERSON_NODE_BOB ); execute( PERSON_NODE_CHARLIE ); - GraphResult res = execute( "MATCH (n:Person)\n" + "RETURN\n" + "CASE\n" + " WHEN n.eyes = 'blue' THEN 1\n" + " WHEN n.age < 40 THEN 2\n" + " ELSE 3\n" + "END AS result, n.eyes, n.age" ); + GraphResult res = execute( """ + MATCH (n:Person) + RETURN + CASE + WHEN n.eyes = 'blue' THEN 1 + WHEN n.age < 40 THEN 2 + ELSE 3 + END AS result, n.eyes, n.age""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); @@ -78,7 +85,13 @@ public void nullWithCaseTest() { execute( PERSON_NODE_CHARLIE ); execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (n:Person)\n" + "RETURN n.name,\n" + "CASE n.age\n" + " WHEN null THEN -1\n" + " ELSE n.age - 10\n" + "END AS age_10_years_ago" ); + GraphResult res = execute( """ + MATCH (n:Person) + RETURN n.name, + CASE n.age + WHEN null THEN -1 + ELSE n.age - 10 + END AS age_10_years_ago""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 28 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 15 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 43 ) ), Row.of( TestLiteral.from( "MAX" ), TestLiteral.from( null ) ) ); @@ -92,7 +105,16 @@ public void expressionsAndSucceedingClauses() { execute( PERSON_NODE_BOB ); execute( PERSON_NODE_CHARLIE ); - GraphResult res = execute( "MATCH (n:Person)\n" + "WITH n,\n" + "CASE n.eyes\n" + " WHEN 'blue' THEN 1\n" + " WHEN 'brown' THEN 2\n" + " ELSE 3\n" + "END AS colorCode\n" + "SET n.colorCode = colorCode\n" + "RETURN n.name, n.colorCode" ); + GraphResult res = execute( """ + MATCH (n:Person) + WITH n, + CASE n.eyes + WHEN 'blue' THEN 1 + WHEN 'brown' THEN 2 + ELSE 3 + END AS colorCode + SET n.colorCode = colorCode + RETURN n.name, n.colorCode""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 70a9107b6a..78801bf984 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -21,7 +21,6 @@ import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; import java.util.List; public class FilterTest extends CypherTestTemplate { @@ -42,11 +41,12 @@ public void nodeLabelFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_ANIMAL ); - GraphResult res = execute( "MATCH (n)\n" - + "WHERE n:Person\n" - + "RETURN n.name, n.age" ); + GraphResult res = execute( """ + MATCH (n) + WHERE n:Person + RETURN n.name, n.age""" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ) ) ); } @@ -60,23 +60,24 @@ public void nodePropertyFilterTest() { assertNode( result, 0 ); - containsRows( result, true, false ); + containsRows( result, true, false ); result = execute( "MATCH (p) WHERE p.age >= 3 RETURN p" ); assertNode( result, 0 ); - containsRows( result, true, false, Row.of( KIRA ) ); + containsRows( result, true, false, Row.of( KIRA ) ); } @Test public void relationPropertyFilterTest() { execute( SINGLE_EDGE_2 ); - GraphResult res = execute( "MATCH (n:Person)-[k:KNOWS]->(f)\n" - + "WHERE k.since < 1995\n" - + "RETURN f.name" ); + GraphResult res = execute( """ + MATCH (n:Person)-[k:KNOWS]->(f) + WHERE k.since < 1995 + RETURN f.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -87,7 +88,7 @@ public void NodePatternFilterTest() { GraphResult res = execute( "MATCH (a:Person WHERE a.name = 'Max')-[:KNOWS]->(b:Person WHERE b.name = 'Hans')\n" + "RETURN b.name" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -98,7 +99,7 @@ public void relationshipPatternFilterTest() { GraphResult res = execute( "MATCH (a:Person)-[r:KNOWS WHERE r.since < 2000 ]->(b:Person)\n" + "RETURN r.since" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 1994 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 1994 ) ) ); } @@ -107,11 +108,12 @@ public void propertyExistenceCheckFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "WHERE n.age IS NOT NULL\n" - + "RETURN n.name, n.age" ); + GraphResult res = execute( """ + MATCH (n:Person) + WHERE n.age IS NOT NULL + RETURN n.name, n.age""" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } @@ -120,11 +122,12 @@ public void propertyExistenceCheckFilterTest() { public void propertyNonExistenceCheckFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "WHERE n.age IS NULL\n" - + "RETURN n.name" ); + GraphResult res = execute( """ + MATCH (n:Person) + WHERE n.age IS NULL + RETURN n.name""" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -134,7 +137,7 @@ public void rangeFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) WHERE 21 < n.age <= 32 RETURN n.name" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Bob" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Bob" ) ) ); } @@ -145,11 +148,11 @@ public void booleanConditionFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult result = execute( "MATCH (p) WHERE p.age >= 45 AND p.depno = 13 RETURN p.name" ); - containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); + containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); result = execute( "MATCH (p) WHERE p.age <= 32 OR p.depno = 13 RETURN p.name " ); - containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ), + containsRows( result, true, false, Row.of( TestLiteral.from( "Ann" ) ), Row.of( TestLiteral.from( "Bob" ) ), Row.of( TestLiteral.from( "Alex" ) ) ); } @@ -160,13 +163,15 @@ public void multiBooleanOperatorsFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "WHERE (n.name = 'Alex' XOR (n.age < 30 AND n.name = 'Bob')) OR NOT (n.name = 'Bob' OR n.name = 'Alex')\n" - + "RETURN\n" - + " n.name AS name,\n" - + " n.age AS age\n" ); - - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (n:Person) + WHERE (n.name = 'Alex' XOR (n.age < 30 AND n.name = 'Bob')) OR NOT (n.name = 'Bob' OR n.name = 'Alex') + RETURN + n.name AS name, + n.age AS age + """ ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( 32 ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } @@ -175,12 +180,13 @@ public void multiBooleanOperatorsFilterTest() { @Test public void withFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "WITH n.name as name\n" - + "WHERE n.age = 45\n" - + "RETURN name" ); + GraphResult res = execute( """ + MATCH (n:Person) + WITH n.name as name + WHERE n.age = 45 + RETURN name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); } @@ -194,7 +200,7 @@ public void existFilterTest() { result = execute( "MATCH (p) WHERE exists(p.name) RETURN p" ); assertNode( result, 0 ); - containsRows( result, true, false, Row.of( MAX ) ); + containsRows( result, true, false, Row.of( MAX ) ); } @@ -208,7 +214,7 @@ public void startWithFilterTest() { execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "MATCH (p) WHERE p.name STARTS WITH 'M' RETURN p.name" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -218,11 +224,12 @@ public void startWithFilterTest() { public void endWithFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n)\n" - + "WHERE n.name ENDS WITH 's'\n" - + "RETURN n.name" ); + GraphResult res = execute( """ + MATCH (n) + WHERE n.name ENDS WITH 's' + RETURN n.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -231,10 +238,11 @@ public void endWithFilterTest() { public void notEndWithFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "WHERE NOT n.name ENDS WITH 's'\n" - + "RETURN n.name, n.age" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + GraphResult res = execute( """ + MATCH (n:Person) + WHERE NOT n.name ENDS WITH 's' + RETURN n.name, n.age""" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -246,34 +254,37 @@ public void containsFilterTest() { execute( SINGLE_NODE_ANIMAL ); GraphResult result = execute( "MATCH (p) WHERE p.name CONTAINS 'H' RETURN p.name" ); - containsRows( result, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + containsRows( result, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @Test public void patternFilterTest() { execute( SINGLE_EDGE_2 ); - GraphResult res = execute( "MATCH\n" - + " (p:Person {name: 'Max'}),\n" - + " (other:Person)\n" - + "WHERE (p)-->(other)\n" - + "RETURN other.name" ); - - containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); - - res = execute( "MATCH\n" - + " (p:Person {name: 'Max'}),\n" - + " (other:Person)\n" - + "WHERE (p)--(other)\n" - + "RETURN other.name" ); - - containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); - - res = execute( "MATCH\n" - + " (p:Person {name: 'Max'}),\n" - + " (other:Person)\n" - + "WHERE (p)<--(other)\n" - + "RETURN other.name" ); + GraphResult res = execute( """ + MATCH + (p:Person {name: 'Max'}), + (other:Person) + WHERE (p)-->(other) + RETURN other.name""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + + res = execute( """ + MATCH + (p:Person {name: 'Max'}), + (other:Person) + WHERE (p)--(other) + RETURN other.name""" ); + + containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); + + res = execute( """ + MATCH + (p:Person {name: 'Max'}), + (other:Person) + WHERE (p)<--(other) + RETURN other.name""" ); assertEmpty( res ); } @@ -281,11 +292,12 @@ public void patternFilterTest() { @Test public void patternWithPropertiesFilterTest() { execute( SINGLE_EDGE_2 ); - GraphResult res = execute( "MATCH (other:Person)\n" - + "WHERE (other)-[:KNOWS]-({name: 'Hans'})\n" - + "RETURN other.name" ); + GraphResult res = execute( """ + MATCH (other:Person) + WHERE (other)-[:KNOWS]-({name: 'Hans'}) + RETURN other.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -295,7 +307,7 @@ public void listComprehensionFilterTest() { GraphResult res = execute( "MATCH (a:Person {name: 'Max'})\n" + "RETURN [(a)-->(b WHERE b:Person) | b.name] AS friends" ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Hans" ) ) ) ); } @@ -305,11 +317,12 @@ public void listComprehensionFilterTest() { public void useInOperatorWithFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (a:Person)\n" - + "WHERE a.name IN ['Peter', 'Max']\n" - + "RETURN a.name" ); + GraphResult res = execute( """ + MATCH (a:Person) + WHERE a.name IN ['Peter', 'Max'] + RETURN a.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -318,10 +331,11 @@ public void missingPropertyFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "WHERE n.age >= 40 \n" - + "RETURN n.name, n.age" ); - containsRows( res, true, false, + GraphResult res = execute( """ + MATCH (n:Person) + WHERE n.age >= 40\s + RETURN n.name, n.age""" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java index db4afc8f8c..c37637e74a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java @@ -51,9 +51,10 @@ public void simpleLimitTest() { @Test public void InsertNodeLimitTest() { - GraphResult res = execute( "CREATE (n:person)\n" - + "RETURN n\n" - + "LIMIT 0" ); + GraphResult res = execute( """ + CREATE (n:person) + RETURN n + LIMIT 0""" ); assertEquals( 0, res.getData().length ); res = matchAndReturnAllNodes(); @@ -64,10 +65,11 @@ public void InsertNodeLimitTest() { @Test public void updateNodeLimitTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - GraphResult res = execute( "MATCH (n {name: 'MAX'})\n" - + "SET n.age = 60\n" - + "RETURN n\n" - + "LIMIT 0" ); + GraphResult res = execute( """ + MATCH (n {name: 'MAX'}) + SET n.age = 60 + RETURN n + LIMIT 0""" ); } @@ -109,9 +111,10 @@ public void withAndOrderByLimitTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (n)\n" - + "WITH n ORDER BY n.name LIMIT 1\n" - + "RETURN n" ); + GraphResult res = execute( """ + MATCH (n) + WITH n ORDER BY n.name LIMIT 1 + RETURN n""" ); assertEquals( 1, res.getData().length ); @@ -128,10 +131,11 @@ public void numberOfUpdatesLimitTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n)\n" - + "WITH n ORDER BY n.name LIMIT 1\n" - + "SET n.locked = true\n" - + "RETURN n.name" ); + GraphResult res = execute( """ + MATCH (n) + WITH n ORDER BY n.name LIMIT 1 + SET n.locked = true + RETURN n.name""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java index ef16283a1d..26ca6e90a5 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java @@ -100,9 +100,10 @@ public void withAndOrderBySkipTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (n)\n" - + "WITH n ORDER BY n.name SKIP 1\n" - + "RETURN n" ); + GraphResult res = execute( """ + MATCH (n) + WITH n ORDER BY n.name SKIP 1 + RETURN n""" ); assertEquals( 1, res.getData().length ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java index f6661c0db1..6a5350e7d5 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java @@ -41,11 +41,12 @@ public void simpleUnionTest() { execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN n.name \n" - + "UNION \n" - + "MATCH (n:Person)\n" - + "RETURN n.name " ); + GraphResult res = execute( """ + MATCH (n:Person) + RETURN n.name + UNION + MATCH (n:Person) + RETURN n.name""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), @@ -59,13 +60,15 @@ public void DifferentStructureUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_MOVIE ); - GraphResult res = execute( "MATCH (p:Person)\n" - + "RETURN p.name AS name\n" - + "UNION\n" - + "MATCH (m :Movie)\n" - + "RETURN p.Title AS name\n" ); + GraphResult res = execute( """ + MATCH (p:Person) + RETURN p.name AS name + UNION + MATCH (m :Movie) + RETURN p.Title AS name + """ ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Wall Street" ) ) ); } @@ -77,13 +80,15 @@ public void NullPropertiesUnionTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_MOVIE ); - GraphResult res = execute( "MATCH (p:Person)\n" - + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" - + "UNION\n" - + "MATCH (m:Movie)\n" - + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); + GraphResult res = execute( """ + MATCH (p:Person) + RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released + UNION + MATCH (m:Movie) + RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released + """ ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ) ); } @@ -96,11 +101,12 @@ public void allUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN n.name \n" - + "UNION ALL \n" - + "MATCH (n:Person)\n" - + "RETURN n.name " ); + GraphResult res = execute( """ + MATCH (n:Person) + RETURN n.name + UNION ALL + MATCH (n:Person) + RETURN n.name""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), @@ -119,13 +125,15 @@ public void DifferentStructureAllUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_MOVIE ); - GraphResult res = execute( "MATCH (p:Person)\n" - + "RETURN p.name AS name\n" - + "UNION ALL\n" - + "MATCH (m :Movie)\n" - + "RETURN p.Title AS name\n" ); + GraphResult res = execute( """ + MATCH (p:Person) + RETURN p.name AS name + UNION ALL + MATCH (m :Movie) + RETURN p.Title AS name + """ ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Wall Street" ) ), Row.of( TestLiteral.from( "Max" ) ), @@ -140,13 +148,15 @@ public void NullPropertiesAllUnionTest() { execute( SINGLE_NODE_MOVIE ); execute( SINGLE_NODE_MOVIE ); - GraphResult res = execute( "MATCH (p:Person)\n" - + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" - + "UNION ALL\n" - + "MATCH (m:Movie)\n" - + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); + GraphResult res = execute( """ + MATCH (p:Person) + RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released + UNION ALL + MATCH (m:Movie) + RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released + """ ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ), @@ -161,11 +171,12 @@ public void distinctUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n:Person)\n" - + "RETURN n.name \n" - + "UNION DISTINCT \n" - + "MATCH (n:Person)\n" - + "RETURN n.name " ); + GraphResult res = execute( """ + MATCH (n:Person) + RETURN n.name + UNION DISTINCT + MATCH (n:Person) + RETURN n.name""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), @@ -179,13 +190,15 @@ public void DifferentStructureDistinctUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_MOVIE ); - GraphResult res = execute( "MATCH (p:Person)\n" - + "RETURN p.name AS name\n" - + "UNION DISTINCT\n" - + "MATCH (m :Movie)\n" - + "RETURN p.Title AS name\n" ); + GraphResult res = execute( """ + MATCH (p:Person) + RETURN p.name AS name + UNION DISTINCT + MATCH (m :Movie) + RETURN p.Title AS name + """ ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Wall Street" ) ) ); } @@ -197,13 +210,15 @@ public void NullPropertiesDistinctUnionTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_MOVIE ); - GraphResult res = execute( "MATCH (p:Person)\n" - + "RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released\n" - + "UNION DISTINCT \n" - + "MATCH (m:Movie)\n" - + "RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released\n" ); + GraphResult res = execute( """ + MATCH (p:Person) + RETURN p.name AS name, p.age AS age, NULL AS title, NULL AS released + UNION DISTINCT + MATCH (m:Movie) + RETURN NULL AS name, NULL AS age, m.title AS title, m.released AS released + """ ); - containsRows( res, true, false, + containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( null ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Wall Street" ), TestLiteral.from( 2002 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java index 9b88f133d8..e1ef604276 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java @@ -124,8 +124,10 @@ public void pathDeleteTest() { execute( SINGLE_EDGE_1 ); - execute( "MATCH p = (person:Person {name: 'Max'})-[rel:OWNER_OF]->( animal :Animal {name: 'Kira'})\n" - + "DELETE p\n" ); + execute( """ + MATCH p = (person:Person {name: 'Max'})-[rel:OWNER_OF]->( animal :Animal {name: 'Kira'}) + DELETE p + """ ); GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) RETURN rel " ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java index 718ed8d104..ff7da8df55 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java @@ -35,12 +35,13 @@ public class DmlInsertTest extends CypherTestTemplate { public static final String CREATE_PERSON_MAX = "CREATE (p:Person {name: 'Max Muster'})"; public static final String CREATE_COMPLEX_GRAPH_1 = - "CREATE\n" - + " (adam:User {name: 'Adam'}),\n" - + " (pernilla:User {name: 'Pernilla'}),\n" - + " (david:User {name: 'David'}),\n" - + " (adam)-[:FRIEND]->(pernilla),\n" - + " (pernilla)-[:FRIEND]->(david)"; + """ + CREATE + (adam:User {name: 'Adam'}), + (pernilla:User {name: 'Pernilla'}), + (david:User {name: 'David'}), + (adam)-[:FRIEND]->(pernilla), + (pernilla)-[:FRIEND]->(david)"""; public static final String CREATE_COMPLEX_GRAPH_2 = "CREATE (adam:User {name: 'Adam'}), (pernilla:User {name: 'Pernilla'}), (david:User {name: 'David'}), (adam)-[:FRIEND]->(pernilla), (pernilla)-[:FRIEND]->(david), (david)-[:FRIEND]->(adam)"; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java index 9fe5654283..0117c8ab4a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java @@ -21,7 +21,6 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; -import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; @@ -116,9 +115,10 @@ public void updateVariablesDecrementTest() { @Test public void updateVariablesIncrementAndDecrementTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( "MATCH (p {name: 'Ann'})\n" - + "SET p = {name: 'Peter Smith', position: 'Entrepreneur'}\n" - + "RETURN p.name, p.age, p.position" ); + execute( """ + MATCH (p {name: 'Ann'}) + SET p = {name: 'Peter Smith', position: 'Entrepreneur'} + RETURN p.name, p.age, p.position""" ); GraphResult res = matchAndReturnAllNodes(); containsRows( res, true, true, @@ -134,9 +134,10 @@ public void updateVariablesIncrementAndDecrementTest() { @Test @Disabled // Extension of Cypher implementation required public void updatePropertyReturnTest() { - execute( "MATCH (a:Animal {name: 'Kira'})\n" - + "SET a.age = 4\n" - + "RETURN a" ); + execute( """ + MATCH (a:Animal {name: 'Kira'}) + SET a.age = 4 + RETURN a""" ); } @@ -182,8 +183,10 @@ public void updateCaseWhenTest() { @Test public void updatePropertyWithNullTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( "MATCH (n {name: 'Ann'})\n" - + "SET n.name = null\n" ); + execute( """ + MATCH (n {name: 'Ann'}) + SET n.name = null + """ ); GraphResult res = matchAndReturnAllNodes(); containsNodes( res, true, diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java index 77327e4934..69f26b211d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java @@ -38,10 +38,11 @@ public void reset() { @Test public void createWithForeachTest() { - execute( "WITH ['Alice', 'Bob', 'Charlie'] AS names\n" - + "FOREACH (name IN names |\n" - + " CREATE (p:Person {name: name})\n" - + ")" ); + execute( """ + WITH ['Alice', 'Bob', 'Charlie'] AS names + FOREACH (name IN names | + CREATE (p:Person {name: name}) + )""" ); GraphResult res = matchAndReturnAllNodes(); assertEquals( 3, res.getData().length ); @@ -56,10 +57,11 @@ public void createWithForeachTest() { @Test public void mergeWithForeachTest() { - execute( "WITH ['Alice', 'Bob', 'Charlie'] AS names\n" - + "FOREACH (name IN names |\n" - + " MERGE (p:Person {name: name})\n" - + ")" ); + execute( """ + WITH ['Alice', 'Bob', 'Charlie'] AS names + FOREACH (name IN names | + MERGE (p:Person {name: name}) + )""" ); GraphResult res = matchAndReturnAllNodes(); assertEquals( 3, res.getData().length ); @@ -76,11 +78,12 @@ public void deleteWithForeachTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - execute( "MATCH (p:Person)\n" - + "WITH collect(p) AS people\n" - + "FOREACH (p IN people |\n" - + " DELETE p\n" - + ")" ); + execute( """ + MATCH (p:Person) + WITH collect(p) AS people + FOREACH (p IN people | + DELETE p + )""" ); GraphResult res = matchAndReturnAllNodes(); assertEmpty( res ); @@ -92,11 +95,12 @@ public void removeWithForeachTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - execute( "MATCH (p:Person)\n" - + "WITH collect(p) AS people\n" - + "FOREACH (p IN people |\n" - + " REMOVE p.name \n" - + ")" ); + execute( """ + MATCH (p:Person) + WITH collect(p) AS people + FOREACH (p IN people | + REMOVE p.name\s + )""" ); GraphResult res = matchAndReturnAllNodes(); containsRows( res, true, false, Row.of( TestLiteral.from( null ) ), @@ -109,11 +113,12 @@ public void removeWithForeachTest() { public void updateWithForeachTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - execute( "MATCH (p:Person)\n" - + "WITH collect(p) AS people\n" - + "FOREACH (p IN people |\n" - + " SET p.status = 'active'\n" - + ")" ); + execute( """ + MATCH (p:Person) + WITH collect(p) AS people + FOREACH (p IN people | + SET p.status = 'active' + )""" ); GraphResult res = matchAndReturnAllNodes(); containsNodes( res, true, @@ -126,13 +131,14 @@ public void updateWithForeachTest() { public void nestedForeachTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - execute( "MATCH (p:Person)\n" - + "WITH collect(p) AS people\n" - + "FOREACH (p1 IN people |\n" - + " FOREACH (p2 IN people |\n" - + " CREATE (p1)-[:KNOWS]->(p2)\n" - + " )\n" - + ")" ); + execute( """ + MATCH (p:Person) + WITH collect(p) AS people + FOREACH (p1 IN people | + FOREACH (p2 IN people | + CREATE (p1)-[:KNOWS]->(p2) + ) + )""" ); GraphResult res = execute( "MATCH (p1)-[r:KNOWS]->(p2) RETURN r" ); assertEquals( 4, res.getData().length ); res = execute( "MATCH (p1)-[r:KNOWS]-(p2) RETURN r" ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java index c8df1a0e5b..6862123d86 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java @@ -25,7 +25,6 @@ import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -160,8 +159,10 @@ public void singleNodeDerivedFromExistingNodeMergeTest() { execute( SINGLE_NODE_PERSON_COMPLEX_5 ); execute( SINGLE_NODE_PERSON_COMPLEX_6 ); - execute( "MATCH (person:Person)\n" - + "MERGE (location:Location {name: person.bornIn})\n" ); + execute( """ + MATCH (person:Person) + MERGE (location:Location {name: person.bornIn}) + """ ); GraphResult res = execute( "MATCH (location:Location) RETURN location.name" ); containsRows( res, true, true, @@ -169,8 +170,10 @@ public void singleNodeDerivedFromExistingNodeMergeTest() { Row.of( TestLiteral.from( "Ohio" ) ), Row.of( TestLiteral.from( "New Jersey" ) ) ); - execute( "MATCH (person:Person)\n" - + "MERGE (location:Location {name: person.bornIn})\n" ); + execute( """ + MATCH (person:Person) + MERGE (location:Location {name: person.bornIn}) + """ ); res = execute( "MATCH (location:Location) RETURN location" ); @@ -200,8 +203,10 @@ public void createWithMergeTest() { @Test public void matchWithMergeTest() { - execute( "MERGE (person:Person{ found : false})\n" - + "ON MATCH SET person.found = true\n" ); + execute( """ + MERGE (person:Person{ found : false}) + ON MATCH SET person.found = true + """ ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); @@ -209,8 +214,10 @@ public void matchWithMergeTest() { List.of( "Person" ), Pair.of( "found", false ) ) ); - execute( "MERGE (person:Person{ found : false})\n" - + "ON MATCH SET person.found = true\n" ); + execute( """ + MERGE (person:Person{ found : false}) + ON MATCH SET person.found = true + """ ); res = matchAndReturnAllNodes(); containsNodes( res, true, TestNode.from( @@ -251,10 +258,12 @@ public void singleRelationshipMergeTest() { execute( SINGLE_NODE_PERSON_COMPLEX_4 ); execute( SINGLE_NODE_MOVIE ); - execute( "MATCH\n" - + " (charlie:Person {name: 'Charlie Sheen'}),\n" - + " (wallStreet:Movie {title: 'Wall Street'})\n" - + "MERGE (charlie)-[r:ACTED_IN]->(wallStreet)\n" ); + execute( """ + MATCH + (charlie:Person {name: 'Charlie Sheen'}), + (wallStreet:Movie {title: 'Wall Street'}) + MERGE (charlie)-[r:ACTED_IN]->(wallStreet) + """ ); GraphResult res = matchAndReturnAllNodes(); containsNodes( res, true, @@ -263,10 +272,12 @@ public void singleRelationshipMergeTest() { res = execute( "MATCH ()-[r]->() RETURN r" ); containsEdges( res, true, TestEdge.from( List.of( "ACTED_IN" ) ) ); - execute( "MATCH\n" - + " (charlie:Person {name: 'Charlie Sheen'}),\n" - + " (wallStreet:Movie {title: 'Wall Street'})\n" - + "MERGE (charlie)-[r:ACTED_IN]->(wallStreet)\n" ); + execute( """ + MATCH + (charlie:Person {name: 'Charlie Sheen'}), + (wallStreet:Movie {title: 'Wall Street'}) + MERGE (charlie)-[r:ACTED_IN]->(wallStreet) + """ ); res = execute( "MATCH ()-[r]->() RETURN r" ); assertEquals( 1, res.getData().length ); @@ -280,23 +291,29 @@ public void multipleRelationshipsMergeTest() { execute( SINGLE_NODE_PERSON_COMPLEX_4 ); execute( SINGLE_NODE_PERSON_COMPLEX_5 ); - execute( "MATCH\n" - + " (charlie:Person {name: 'Charlie Sheen'}),\n" - + " (martin:Person {name: 'Martin Sheen'})\n" - + "MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(reiner)\n" ); + execute( """ + MATCH + (charlie:Person {name: 'Charlie Sheen'}), + (martin:Person {name: 'Martin Sheen'}) + MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(reiner) + """ ); - GraphResult res = execute( "MATCH (p1:Person)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(p2:Person)\n" - + "RETURN p1, p2, movie\n" ); + GraphResult res = execute( """ + MATCH (p1:Person)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(p2:Person) + RETURN p1, p2, movie + """ ); containsNodes( res, true, TestNode.from( Pair.of( "name", "Charlie Sheen" ) ), TestNode.from( Pair.of( "name", "Martin Sheen" ) ), TestNode.from( List.of( "Movie" ) ) ); - execute( "MATCH\n" - + " (charlie:Person {name: 'Charlie Sheen'}),\n" - + " (martin:Person {name: 'Martin Sheen'})\n" - + "MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(reiner)\n" ); + execute( """ + MATCH + (charlie:Person {name: 'Charlie Sheen'}), + (martin:Person {name: 'Martin Sheen'}) + MERGE (oliver)-[:DIRECTED]->(movie:Movie)<-[:DIRECTED]-(reiner) + """ ); res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); @@ -309,20 +326,24 @@ public void undirectedRelationshipMergeTest() { execute( SINGLE_NODE_PERSON_COMPLEX_4 ); execute( SINGLE_NODE_PERSON_COMPLEX_5 ); - execute( "MATCH\n" - + " (charlie:Person {name: 'Charlie Sheen'}),\n" - + " (martin:Person {name: 'Martin Sheen'})\n" - + "MERGE (charlie)-[r:KNOWS]-(oliver)\n" ); + execute( """ + MATCH + (charlie:Person {name: 'Charlie Sheen'}), + (martin:Person {name: 'Martin Sheen'}) + MERGE (charlie)-[r:KNOWS]-(oliver) + """ ); GraphResult res = execute( "MATCH (p1:Person)-[r:KNOWS]-(p2:Person)\n" + "RETURN KNOWS" ); containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ) ) ); - execute( "MATCH\n" - + " (charlie:Person {name: 'Charlie Sheen'}),\n" - + " (martin:Person {name: 'Martin Sheen'})\n" - + "MERGE (charlie)-[r:KNOWS]-(oliver)\n" ); + execute( """ + MATCH + (charlie:Person {name: 'Charlie Sheen'}), + (martin:Person {name: 'Martin Sheen'}) + MERGE (charlie)-[r:KNOWS]-(oliver) + """ ); res = execute( "MATCH (p1:Person)-[r:KNOWS]-(p2:Person)\n" + "RETURN KNOWS" ); @@ -337,9 +358,11 @@ public void relationshipOnTwoExistingNodeMergeTest() { execute( SINGLE_NODE_PERSON_COMPLEX_5 ); execute( SINGLE_NODE_PERSON_COMPLEX_6 ); - execute( "MATCH (person:Person)\n" - + "MERGE (location:Location {name: person.bornIn})\n" - + "MERGE (person)-[r:BORN_IN]->(location)\n" ); + execute( """ + MATCH (person:Person) + MERGE (location:Location {name: person.bornIn}) + MERGE (person)-[r:BORN_IN]->(location) + """ ); GraphResult res = execute( "MATCH (location:Location) RETURN location.name" ); containsRows( res, true, true, @@ -351,9 +374,11 @@ public void relationshipOnTwoExistingNodeMergeTest() { assertEquals( 3, res.getData().length ); containsEdges( res, true, TestEdge.from( List.of( "BORN_IN" ) ) ); - execute( "MATCH (person:Person)\n" - + "MERGE (location:Location {name: person.bornIn})\n" - + "MERGE (person)-[r:BORN_IN]->(location)\n" ); + execute( """ + MATCH (person:Person) + MERGE (location:Location {name: person.bornIn}) + MERGE (person)-[r:BORN_IN]->(location) + """ ); GraphResult edges = execute( "MATCH ()-[BORN_IN]->() RETURN BORN_IN" ); GraphResult nodes = execute( "MATCH (location:Location) RETURN Location " ); @@ -369,8 +394,10 @@ public void relationshipOnExistingNodeAndMergeNodeDerivedFromAnodeProperty() { execute( SINGLE_NODE_PERSON_COMPLEX_5 ); execute( SINGLE_NODE_PERSON_COMPLEX_6 ); - execute( "MATCH (person:Person)\n" - + "MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName})\n" ); + execute( """ + MATCH (person:Person) + MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName}) + """ ); GraphResult res = execute( "MATCH ( chauffeur :Chauffeur) Return Chauffeur.name" ); containsRows( res, true, true, @@ -381,8 +408,10 @@ public void relationshipOnExistingNodeAndMergeNodeDerivedFromAnodeProperty() { res = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); assertEquals( 3, res.getData().length ); containsEdges( res, true, TestEdge.from( List.of( "HAS_CHAUFFEUR" ) ) ); - execute( "MATCH (person:Person)\n" - + "MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName})\n" ); + execute( """ + MATCH (person:Person) + MERGE (person)-[r:HAS_CHAUFFEUR]->(chauffeur:Chauffeur {name: person.chauffeurName}) + """ ); GraphResult edges = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); GraphResult nodes = execute( "MATCH (n:Chauffeur) RETURN Chauffeur" ); assertTrue( edges.getData().length == 3 && nodes.getData().length == 3 ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java index ce60845177..6792fd7002 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java @@ -16,17 +16,15 @@ package org.polypheny.db.cypher.clause.write; -import io.activej.codegen.expression.impl.Null; + import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; -import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; -import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; + import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -97,8 +95,10 @@ public void singlePropertyNodeRemoveTest() { @Test public void multiplePropertiesRemoveTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - execute( "MATCH (n:Person {name: 'Ann'})\n" - + "REMOVE n.age, n.depno\n" ); + execute( """ + MATCH (n:Person {name: 'Ann'}) + REMOVE n.age, n.depno + """ ); GraphResult res = execute( "MATCH (n : Person) RETURN n.age , n.depno , n.name " ); containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); From e7e74e79ff44880a8c59196ddcd42cdde844be54 Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Sun, 18 Aug 2024 17:00:59 +0300 Subject: [PATCH 49/55] Refactor: rename files --- .../{BooleanOperators.java => BooleanOperatorsTest.java} | 2 +- ...{ComparisonOperations.java => ComparisonOperationsTest.java} | 2 +- .../Operators/{ListOperators.java => ListOperatorsTest.java} | 2 +- ...athematicalOperators.java => MathematicalOperatorsTest.java} | 2 +- .../{StringOperators.java => StringOperatorsTest.java} | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename dbms/src/test/java/org/polypheny/db/cypher/Operators/{BooleanOperators.java => BooleanOperatorsTest.java} (97%) rename dbms/src/test/java/org/polypheny/db/cypher/Operators/{ComparisonOperations.java => ComparisonOperationsTest.java} (97%) rename dbms/src/test/java/org/polypheny/db/cypher/Operators/{ListOperators.java => ListOperatorsTest.java} (96%) rename dbms/src/test/java/org/polypheny/db/cypher/Operators/{MathematicalOperators.java => MathematicalOperatorsTest.java} (96%) rename dbms/src/test/java/org/polypheny/db/cypher/Operators/{StringOperators.java => StringOperatorsTest.java} (95%) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperatorsTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java rename to dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperatorsTest.java index 5a49b3ffe8..91df7332bf 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperatorsTest.java @@ -23,7 +23,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -public class BooleanOperators extends CypherTestTemplate { +public class BooleanOperatorsTest extends CypherTestTemplate { @BeforeEach public void setUp() { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperationsTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java rename to dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperationsTest.java index 5e3c1212a6..ac3d9a2a79 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperations.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperationsTest.java @@ -22,7 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -public class ComparisonOperations extends CypherTestTemplate { +public class ComparisonOperationsTest extends CypherTestTemplate { @BeforeEach public void setUp() { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperatorsTest.java similarity index 96% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java rename to dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperatorsTest.java index d1829c439c..29a30bb4f3 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperatorsTest.java @@ -23,7 +23,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -public class ListOperators extends CypherTestTemplate { +public class ListOperatorsTest extends CypherTestTemplate { @BeforeEach public void setUp() { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperatorsTest.java similarity index 96% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java rename to dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperatorsTest.java index e70701d091..e6f3c8b0bc 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperatorsTest.java @@ -23,7 +23,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -public class MathematicalOperators extends CypherTestTemplate { +public class MathematicalOperatorsTest extends CypherTestTemplate { @BeforeEach public void reset() { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperatorsTest.java similarity index 95% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java rename to dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperatorsTest.java index 210eff42f6..b5ddfc5bc2 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperators.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperatorsTest.java @@ -22,7 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -public class StringOperators extends CypherTestTemplate { +public class StringOperatorsTest extends CypherTestTemplate { @BeforeEach From 90467f281bc0c204ea14f9fd2ad78e27bbc517ec Mon Sep 17 00:00:00 2001 From: alyaa999 Date: Mon, 19 Aug 2024 05:23:33 +0300 Subject: [PATCH 50/55] update the output test --- .../db/cypher/CypherTestTemplate.java | 2 +- .../db/cypher/Functions/AggregateTest.java | 6 ++-- .../db/cypher/Functions/NumericFunTest.java | 2 +- .../db/cypher/Functions/OtherFunTest.java | 3 ++ .../db/cypher/clause/general/FilterTest.java | 1 + .../db/cypher/clause/general/LimitTest.java | 22 +++++++++++-- .../db/cypher/clause/general/SkipTest.java | 2 +- .../db/cypher/clause/general/UnwindTest.java | 9 ++++-- .../db/cypher/clause/general/WithTest.java | 31 +++++++++++++++---- .../db/cypher/clause/write/MergeTest.java | 2 +- 10 files changed, 62 insertions(+), 18 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java index 1f66ec83eb..e8a59081b9 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java @@ -280,7 +280,7 @@ protected boolean is( GraphResult res, Type type, int index ) { protected void assertEmpty( GraphResult res ) { - assert res.getData().length == 0; + assertEquals( 0 , res.getData().length ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java index 3475891c56..073c805cae 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java @@ -25,6 +25,8 @@ import java.util.Arrays; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class AggregateTest extends CypherTestTemplate { @@ -98,7 +100,7 @@ public void countRenameFieldAggregateTest() { execute( SINGLE_EDGE_2 ); GraphResult res = execute( "MATCH (n) RETURN n.name, count(*) AS c" ); - res.getHeader()[1].name.equals( "c" ); + assertEquals("c", res.getHeader()[1].name); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 3 ) ), @@ -242,7 +244,7 @@ public void collectNullAggregationTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( List.of( null, null ) ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( ) ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java index d780802709..4419a1a3ce 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java @@ -122,7 +122,7 @@ public void nonPerfectSquareSqrtFunTest() { @Test public void sqrtFunTestNegative() { - GraphResult res = execute( "RETURN SQRT(-9)" ); + execute( "RETURN SQRT(-9)" ); // containsRows(res, true, true, Row.of(TestLiteral.from(null))); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java index fa50c50552..ffe58012d2 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java @@ -23,6 +23,8 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class OtherFunTest extends CypherTestTemplate { @BeforeEach @@ -56,6 +58,7 @@ public void idFunTest() { RETURN ID(p) """ ); + assertEquals(1 , res.getData().length); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 78801bf984..1f414dd348 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -196,6 +196,7 @@ public void existFilterTest() { GraphResult result = execute( "MATCH (p) WHERE exists(p.age) RETURN p" ); assertEmpty( result ); + execute( SINGLE_NODE_PERSON_COMPLEX_1 ); result = execute( "MATCH (p) WHERE exists(p.name) RETURN p" ); assertNode( result, 0 ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java index c37637e74a..c3fa85a12a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java @@ -24,6 +24,8 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; public class LimitTest extends CypherTestTemplate { @@ -64,14 +66,28 @@ public void InsertNodeLimitTest() { @Test public void updateNodeLimitTest() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); + execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( """ - MATCH (n {name: 'MAX'}) + MATCH (n {name: 'Max'}) SET n.age = 60 RETURN n LIMIT 0""" ); + assertEquals( 0, res.getData().length ); + res = matchAndReturnAllNodes(); + containsNodes( res, true, + TestNode.from( List.of( "Person" ), + Pair.of( "name", "Max" ) ) ); - + res = execute( """ + MATCH (n {name: 'Max'}) + SET n.age = 60 + RETURN n + LIMIT 1""" ); + assertEquals( 1, res.getData().length ); + containsNodes( res, true, + TestNode.from( List.of( "Person" ), + Pair.of( "name", "Max" ), + Pair.of( "age", 60 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java index 26ca6e90a5..cd766a87e8 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java @@ -23,7 +23,7 @@ import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; + import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java index d43d855442..2f19c5a7c0 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java @@ -6,6 +6,8 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; public class UnwindTest extends CypherTestTemplate { @@ -82,9 +84,9 @@ public void minMaxAggregateSimpleUnWind() { @Test public void minMaxAggregateListOfListUnwind() { GraphResult res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN min(val)" ); - + containsRows( res , true , false , Row.of( TestLiteral.from( List.of('a','c' , 23) ) ) ); res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN max(val)" ); - + containsRows( res , true , false , Row.of( TestLiteral.from( 'd' ) ) ); } @@ -130,10 +132,11 @@ public void CollectAggregateUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); - + containsRows( res , true , false , Row.of( TestLiteral.from( List.of(45 , 31) ) ) ); } + @Test public void countUnWind() { GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java index 068d03c76d..4ab61fbcbf 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java @@ -23,6 +23,8 @@ import org.polypheny.db.webui.models.results.GraphResult; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -204,6 +206,8 @@ public void collectAggregationWithTest() { @Test public void mapStructureRenameWithTest() { GraphResult res = execute( "WITH {person: {name: 'Anne', age: 25}} AS p RETURN p" ); + assertEquals( 1, res.getData().length ); + } @@ -213,37 +217,52 @@ public void filterWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (p:Person) WITH p WHERE p.age > 31 RETURN p.name, p.age" ); - - + containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), + Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( 32 ) ) ); } @Test - public void calculationWithTest() { + public void mathematicalOperationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p, p.age * 2 AS double_age RETURN p.name, double_age;" ); + GraphResult res = execute( "MATCH (p:Person) WITH p, p.age * 2 AS double_age RETURN p.name, double_age" ); + containsRows( res, true, false, + Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 90.0 ) ), + Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( 62.0 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 64.0 ) ) ); } @Test public void listWithTest() { GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers RETURN numbers" ); - + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 1, 2, 3, 4, 5 ) ) ) ); } @Test public void unWindListWithTest() { - GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number RETURN number;" ); + GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number RETURN number" ); + containsRows( res, true, false, + Row.of( TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( 3 ) ), + Row.of( TestLiteral.from( 4 ) ), + Row.of( TestLiteral.from( 5 ) ) ); + } @Test public void unWindAndFilterListWithTest() { GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number WITH number WHERE number > 3 RETURN number" ); + containsRows( res, true, false, + Row.of( TestLiteral.from( 4 ) ), + Row.of( TestLiteral.from( 5 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java index 6862123d86..64735a2ff1 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java @@ -96,7 +96,7 @@ public void singleNodeWithMultipleLabelsMergeTest() { // exist node execute( "MERGE (robert:Critic:Viewer)" ); - GraphResult allNodes = matchAndReturnAllNodes(); + res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); } From 57a87b542bf25b5b97c6bc2a37312400bb099f3a Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Sun, 25 Aug 2024 14:29:14 +0200 Subject: [PATCH 51/55] Minor formatting and style improvements and rename folders to lower case --- .../db/cypher/CypherTestTemplate.java | 44 ++++++------- .../java/org/polypheny/db/cypher/DdlTest.java | 9 +-- .../db/cypher/clause/general/CallTest.java | 3 +- .../db/cypher/clause/general/CaseTest.java | 17 ++--- .../db/cypher/clause/general/FilterTest.java | 28 ++------- .../db/cypher/clause/general/LimitTest.java | 9 +-- .../db/cypher/clause/general/OrderByTest.java | 22 +------ .../db/cypher/clause/general/SkipTest.java | 10 +-- .../db/cypher/clause/general/UnionTest.java | 7 +-- .../db/cypher/clause/general/UnwindTest.java | 37 +++-------- .../db/cypher/clause/general/WithTest.java | 50 ++++----------- .../db/cypher/clause/read/MatchTest.java | 40 ++---------- .../db/cypher/clause/write/DmlDeleteTest.java | 14 +---- .../db/cypher/clause/write/DmlInsertTest.java | 28 +-------- .../db/cypher/clause/write/DmlUpdateTest.java | 5 +- .../db/cypher/clause/write/ForeachTest.java | 11 +--- .../db/cypher/clause/write/MergeTest.java | 34 ++-------- .../db/cypher/clause/write/RemoveTest.java | 20 +----- .../AggregateTest.java | 62 ++++--------------- .../{Functions => functions}/ListFunTest.java | 16 ++--- .../NumericFunTest.java | 12 +--- .../OtherFunTest.java | 18 +++--- .../SpatialFunTest.java | 5 +- .../StringFunTest.java | 8 +-- .../TemporalFunTest.java | 26 ++------ .../polypheny/db/cypher/helper/TestEdge.java | 1 + .../db/cypher/helper/TestGraphObject.java | 6 +- .../db/cypher/helper/TestLiteral.java | 1 + .../polypheny/db/cypher/helper/TestNode.java | 1 - .../db/cypher/helper/TestObject.java | 1 + .../polypheny/db/cypher/helper/TestPath.java | 2 +- .../BooleanOperatorsTest.java | 10 +-- .../ComparisonOperationsTest.java | 4 +- .../ListOperatorsTest.java | 5 +- .../MathematicalOperatorsTest.java | 11 +--- .../StringOperatorsTest.java | 4 +- .../CallSubqueriesTest.java | 17 +++-- .../CollectSubQueriesTest.java | 25 ++++---- .../CountSubQueriesTest.java | 22 +++---- .../ExistsSubQueriesTest.java | 21 +++---- 40 files changed, 172 insertions(+), 494 deletions(-) rename dbms/src/test/java/org/polypheny/db/cypher/{Functions => functions}/AggregateTest.java (97%) rename dbms/src/test/java/org/polypheny/db/cypher/{Functions => functions}/ListFunTest.java (98%) rename dbms/src/test/java/org/polypheny/db/cypher/{Functions => functions}/NumericFunTest.java (97%) rename dbms/src/test/java/org/polypheny/db/cypher/{Functions => functions}/OtherFunTest.java (97%) rename dbms/src/test/java/org/polypheny/db/cypher/{Functions => functions}/SpatialFunTest.java (98%) rename dbms/src/test/java/org/polypheny/db/cypher/{Functions => functions}/StringFunTest.java (99%) rename dbms/src/test/java/org/polypheny/db/cypher/{Functions => functions}/TemporalFunTest.java (99%) rename dbms/src/test/java/org/polypheny/db/cypher/{Operators => operators}/BooleanOperatorsTest.java (98%) rename dbms/src/test/java/org/polypheny/db/cypher/{Operators => operators}/ComparisonOperationsTest.java (98%) rename dbms/src/test/java/org/polypheny/db/cypher/{Operators => operators}/ListOperatorsTest.java (97%) rename dbms/src/test/java/org/polypheny/db/cypher/{Operators => operators}/MathematicalOperatorsTest.java (97%) rename dbms/src/test/java/org/polypheny/db/cypher/{Operators => operators}/StringOperatorsTest.java (96%) rename dbms/src/test/java/org/polypheny/db/cypher/{Subqueries => subqueries}/CallSubqueriesTest.java (99%) rename dbms/src/test/java/org/polypheny/db/cypher/{Subqueries => subqueries}/CollectSubQueriesTest.java (98%) rename dbms/src/test/java/org/polypheny/db/cypher/{Subqueries => subqueries}/CountSubQueriesTest.java (99%) rename dbms/src/test/java/org/polypheny/db/cypher/{Subqueries => subqueries}/ExistsSubQueriesTest.java (98%) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java index 42d9c96cd1..203f4a4632 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/CypherTestTemplate.java @@ -50,6 +50,7 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; + @Slf4j public class CypherTestTemplate { @@ -57,14 +58,11 @@ public class CypherTestTemplate { protected static final String SINGLE_NODE_PERSON_1 = "CREATE (p:Person {name: 'Max'})"; protected static final String SINGLE_NODE_PERSON_2 = "CREATE (p:Person {name: 'Hans'})"; - protected static final String SINGLE_NODE_PERSON_COMPLEX_1 = "CREATE (p:Person {name: 'Ann', age: 45, depno: 13})"; protected static final String SINGLE_NODE_PERSON_COMPLEX_2 = "CREATE (p:Person {name: 'Bob', age: 31, depno: 13})"; - protected static final String SINGLE_NODE_PERSON_COMPLEX_3 = "CREATE (p:Person {name: 'Alex', age: 32, depno: 14})"; - protected static final String SINGLE_NODE_ANIMAL = "CREATE (a:Animal {name:'Kira', age:3, type:'dog'})"; protected static final String SINGLE_NODE_GEOM = "CREATE (c:City {name:'Basel', location:'POINT (7.586052 47.559152)'})"; protected static final String SINGLE_EDGE_1 = "CREATE (p:Person {name: 'Max'})-[rel:OWNER_OF]->(a:Animal {name:'Kira', age:3, type:'dog'})"; @@ -179,7 +177,6 @@ public boolean containsIn( GraphResult actual, boolean exclusive, int index, @Nu } return contains; - } @@ -194,11 +191,10 @@ public static boolean containsRows( GraphResult actual, boolean exclusive, boole } // Use assert to validate exclusive condition - assertTrue(!exclusive || actual.getData().length >= rows.length, "Exclusive condition failed: actual data has fewer rows than expected."); - + assertTrue( !exclusive || actual.getData().length >= rows.length, "Exclusive condition failed: actual data has fewer rows than expected." ); // Use the appropriate matching method based on the 'ordered' flag - return ordered ? matchesExactRows(parsed, rows) : matchesUnorderedRows(parsed, rows); + return ordered ? matchesExactRows( parsed, rows ) : matchesUnorderedRows( parsed, rows ); } catch ( Throwable t ) { fail( "Error while evaluating result: " + t.getMessage() ); @@ -207,51 +203,50 @@ public static boolean containsRows( GraphResult actual, boolean exclusive, boole } - private static boolean matchesUnorderedRows(List> parsed, Row[] rows) { + private static boolean matchesUnorderedRows( List> parsed, Row[] rows ) { List used = new ArrayList<>(); - for (Row row : rows) { + for ( Row row : rows ) { boolean matches = false; - for (int i = 0; i < parsed.size(); i++) { - if (!matches && !used.contains(i) && row.matches(parsed.get(i))) { - used.add(i); + for ( int i = 0; i < parsed.size(); i++ ) { + if ( !matches && !used.contains( i ) && row.matches( parsed.get( i ) ) ) { + used.add( i ); matches = true; break; } } // Use assert to validate that each row finds a match - assertTrue(matches, "Row " + row + " could not be matched in the parsed data."); + assertTrue( matches, "Row " + row + " could not be matched in the parsed data." ); } return true; } - - private static boolean matchesExactRows(List> parsed, Row[] rows) { - for (int j = 0; j < rows.length; j++) { + private static boolean matchesExactRows( List> parsed, Row[] rows ) { + for ( int j = 0; j < rows.length; j++ ) { // Use assert to ensure each row matches - assertTrue(rows[j].matches(parsed.get(j)), "Row " + j + " does not match the expected value."); + assertTrue( rows[j].matches( parsed.get( j ) ), "Row " + j + " does not match the expected value." ); } return true; } @SneakyThrows - private boolean contains(String[][] actual, boolean exclusive, int index, Class clazz, TestObject[] expected) { + private boolean contains( String[][] actual, boolean exclusive, int index, Class clazz, TestObject[] expected ) { List parsed = new ArrayList<>(); - for (String[] entry : actual) { - parsed.add(PolyValue.JSON_WRAPPER.readValue(entry[index], clazz)); + for ( String[] entry : actual ) { + parsed.add( PolyValue.JSON_WRAPPER.readValue( entry[index], clazz ) ); } // Assert that if exclusive is true, the number of parsed items equals the number of expected items - assertEquals(exclusive ? expected.length : parsed.size(), parsed.size(), "Exclusive condition failed: parsed size does not match expected length."); + assertEquals( exclusive ? expected.length : parsed.size(), parsed.size(), "Exclusive condition failed: parsed size does not match expected length." ); - for (TestObject node : expected) { + for ( TestObject node : expected ) { // Assert that each expected node matches at least one parsed element - assertTrue(parsed.stream().anyMatch(n -> node.matches(n, exclusive)), "Expected node does not match any parsed element."); + assertTrue( parsed.stream().anyMatch( n -> node.matches( n, exclusive ) ), "Expected node does not match any parsed element." ); } return true; @@ -281,7 +276,7 @@ protected boolean is( GraphResult res, Type type, int index ) { protected void assertEmpty( GraphResult res ) { - assertEquals( 0 , res.getData().length ); + assertEquals( 0, res.getData().length ); } @@ -362,5 +357,4 @@ public boolean matches( List objects ) { } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java b/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java index 8b3c42844f..dbec2903ed 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java @@ -16,7 +16,6 @@ package org.polypheny.db.cypher; - import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -37,6 +36,7 @@ import org.polypheny.db.cypher.clause.write.DmlInsertTest; import org.polypheny.db.webui.models.results.GraphResult; + @Tag("adapter") @Slf4j public class DdlTest extends CypherTestTemplate { @@ -59,7 +59,6 @@ public void addGraphTest() { assertTrue( Catalog.snapshot().getNamespace( graphName ).isPresent() ); execute( "DROP DATABASE " + graphName ); - } @@ -71,7 +70,6 @@ public void createNamespaceTest( String namespaceName ) { execute( format( "CREATE %s %s", namespaceName, name ) ); execute( format( "DROP %s %s", namespaceName, name ) ); - } @@ -101,7 +99,6 @@ public void addPlacementTest() throws SQLException { removeStore( "store1" ); } - } @@ -129,7 +126,6 @@ public void initialPlacementTest() throws SQLException { } finally { removeStore( "store1" ); } - } @@ -161,13 +157,11 @@ public void deletePlacementTest() throws SQLException { } finally { removeStore( "store1" ); } - } @Test public void deletePlacementDataTest() throws SQLException { - execute( "CREATE DATABASE " + graphName + " IF NOT EXISTS" ); execute( DmlInsertTest.CREATE_COMPLEX_GRAPH_2, graphName ); @@ -192,7 +186,6 @@ public void deletePlacementDataTest() throws SQLException { } finally { removeStore( "store1" ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java index 84b143dc2e..bd1802ede2 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java @@ -22,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class CallTest extends CypherTestTemplate { @BeforeEach @@ -53,7 +54,6 @@ public void simpleCallProcedureTest() { Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); - } @@ -148,7 +148,6 @@ public void simpleCallPropertyKeysYieldTest() { Row.of( TestLiteral.from( "name" ) ), Row.of( TestLiteral.from( "age" ) ), Row.of( TestLiteral.from( "type" ) ) ); - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java index 5f3921dd39..7fe68ba82b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java @@ -25,6 +25,11 @@ public class CaseTest extends CypherTestTemplate { + protected static final String PERSON_NODE_ALICE = "CREATE (:Person {name:'Alice', age: 38, eyes: 'brown'})"; + protected static final String PERSON_NODE_BOB = "CREATE (:Person {name: 'Bob', age: 25, eyes: 'blue'})"; + protected static final String PERSON_NODE_CHARLIE = "CREATE (:Person {name: 'Charlie', age: 53, eyes: 'green'})"; + + @BeforeEach public void reset() { tearDown(); @@ -32,11 +37,6 @@ public void reset() { } - protected static final String PERSON_NODE_ALICE = "CREATE (:Person {name:'Alice', age: 38, eyes: 'brown'})"; - protected static final String PERSON_NODE_BOB = "CREATE (:Person {name: 'Bob', age: 25, eyes: 'blue'})"; - protected static final String PERSON_NODE_CHARLIE = "CREATE (:Person {name: 'Charlie', age: 53, eyes: 'green'})"; - - @Test public void simpleCaseTest() { execute( PERSON_NODE_ALICE ); @@ -52,8 +52,6 @@ public void simpleCaseTest() { END AS result, n.eyes""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); - - } @@ -73,7 +71,6 @@ public void GenericCaseTest() { END AS result, n.eyes, n.age""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); - } @@ -94,8 +91,6 @@ public void nullWithCaseTest() { END AS age_10_years_ago""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 28 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 15 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 43 ) ), Row.of( TestLiteral.from( "MAX" ), TestLiteral.from( null ) ) ); - - } @@ -117,8 +112,6 @@ public void expressionsAndSucceedingClauses() { RETURN n.name, n.colorCode""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 1f414dd348..1229499937 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -16,12 +16,13 @@ package org.polypheny.db.cypher.clause.general; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; + public class FilterTest extends CypherTestTemplate { @@ -35,7 +36,6 @@ public void setUp() { /////////// FILTER /////////////////////////////////////////////// - @Test public void nodeLabelFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); @@ -45,7 +45,6 @@ public void nodeLabelFilterTest() { MATCH (n) WHERE n:Person RETURN n.name, n.age""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ) ) ); @@ -76,27 +75,22 @@ public void relationPropertyFilterTest() { MATCH (n:Person)-[k:KNOWS]->(f) WHERE k.since < 1995 RETURN f.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); - } @Test public void NodePatternFilterTest() { execute( SINGLE_EDGE_2 ); - GraphResult res = execute( "MATCH (a:Person WHERE a.name = 'Max')-[:KNOWS]->(b:Person WHERE b.name = 'Hans')\n" + "RETURN b.name" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); - } @Test public void relationshipPatternFilterTest() { execute( SINGLE_EDGE_2 ); - GraphResult res = execute( "MATCH (a:Person)-[r:KNOWS WHERE r.since < 2000 ]->(b:Person)\n" + "RETURN r.since" ); containsRows( res, true, false, Row.of( TestLiteral.from( 1994 ) ) ); @@ -112,7 +106,6 @@ public void propertyExistenceCheckFilterTest() { MATCH (n:Person) WHERE n.age IS NOT NULL RETURN n.name, n.age""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } @@ -126,7 +119,6 @@ public void propertyNonExistenceCheckFilterTest() { MATCH (n:Person) WHERE n.age IS NULL RETURN n.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -170,7 +162,6 @@ public void multiBooleanOperatorsFilterTest() { n.name AS name, n.age AS age """ ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( 32 ) ), Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); @@ -185,7 +176,6 @@ public void withFilterTest() { WITH n.name as name WHERE n.age = 45 RETURN name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ) ) ); } @@ -208,16 +198,15 @@ public void existFilterTest() { /////////////////////////////////// ///// STRING matching ///////////////////////////////////// + + @Test public void startWithFilterTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "MATCH (p) WHERE p.name STARTS WITH 'M' RETURN p.name" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); - - } @@ -229,9 +218,7 @@ public void endWithFilterTest() { MATCH (n) WHERE n.name ENDS WITH 's' RETURN n.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); - } @@ -244,7 +231,6 @@ public void notEndWithFilterTest() { WHERE NOT n.name ENDS WITH 's' RETURN n.name, n.age""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); - } @@ -254,7 +240,6 @@ public void containsFilterTest() { execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_ANIMAL ); GraphResult result = execute( "MATCH (p) WHERE p.name CONTAINS 'H' RETURN p.name" ); - containsRows( result, true, false, Row.of( TestLiteral.from( "Hans" ) ) ); } @@ -297,7 +282,6 @@ public void patternWithPropertiesFilterTest() { MATCH (other:Person) WHERE (other)-[:KNOWS]-({name: 'Hans'}) RETURN other.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -307,10 +291,8 @@ public void listComprehensionFilterTest() { execute( SINGLE_EDGE_2 ); GraphResult res = execute( "MATCH (a:Person {name: 'Max'})\n" + "RETURN [(a)-->(b WHERE b:Person) | b.name] AS friends" ); - containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Hans" ) ) ) ); - } @@ -322,7 +304,6 @@ public void useInOperatorWithFilterTest() { MATCH (a:Person) WHERE a.name IN ['Peter', 'Max'] RETURN a.name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -341,5 +322,4 @@ public void missingPropertyFilterTest() { } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java index c3fa85a12a..31837b8f9e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java @@ -16,6 +16,9 @@ package org.polypheny.db.cypher.clause.general; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -24,9 +27,6 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; public class LimitTest extends CypherTestTemplate { @@ -137,8 +137,6 @@ public void withAndOrderByLimitTest() { containsNodes( res, true, TestNode.from( Pair.of( "name", "Ann" ), Pair.of( "age", 45 ), Pair.of( "depno", 13 ) ) ); - - } @@ -156,5 +154,4 @@ public void numberOfUpdatesLimitTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java index 1f000e1a5d..b4c3d1ca86 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java @@ -24,6 +24,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class OrderByTest extends CypherTestTemplate { @BeforeEach @@ -52,7 +53,6 @@ public void singleOrderByTest() { Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Hans" ) ) ); - } @@ -72,7 +72,6 @@ public void doubleOrderByTest() { containsRows( res, true, true, Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ), Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Ann" ) ) ); - } @@ -92,7 +91,6 @@ public void nullOrderByTest() { assertTrue( containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( null ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 3 ) ) ) ); - } @@ -139,7 +137,6 @@ public void renameWithClauseSortTest() { containsRows( res, true, true, Row.of( TestLiteral.from( 31 ) ), Row.of( TestLiteral.from( 45 ) ) ); - } @@ -153,8 +150,6 @@ public void renameWithClauseOrderByWithLimitTest() { containsRows( res, true, true, Row.of( TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( 32 ) ) ); - - } @@ -170,8 +165,6 @@ public void renameWithClauseDoubleOrderByTest() { Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Ann" ) ), Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ), Row.of( TestLiteral.from( 14 ), TestLiteral.from( "Alex" ) ) ); - - } @@ -187,8 +180,6 @@ public void renameWithClauseDoubleOrderByWithLimitTest() { Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Ann" ) ), Row.of( TestLiteral.from( 13 ), TestLiteral.from( "Bob" ) ), Row.of( TestLiteral.from( 14 ), TestLiteral.from( "Alex" ) ) ); - - } @@ -199,16 +190,12 @@ public void UnwindSortTest() { Row.of( TestLiteral.from( true ) ), Row.of( TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( 3.14 ) ) ); - - } @Test public void renameWithClauseWithUnwindSortTest() { - GraphResult res = execute( "WITH [1 ,2 ,3] AS number UNWIND number AS n RETURN n ORDER BY n" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( 2 ) ), @@ -218,9 +205,7 @@ public void renameWithClauseWithUnwindSortTest() { @Test public void renameWithMixedTypesWithUnwindSortTest() { - GraphResult res = execute( "WITH [1 ,2 ,'4'] AS number UNWIND number AS n RETURN n ORDER BY n" ); - containsRows( res, true, true, Row.of( TestLiteral.from( '4' ) ), Row.of( TestLiteral.from( 1 ) ), @@ -237,7 +222,6 @@ public void AvgAggregateFieldSortTest() { containsRows( res, true, true, Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ), Row.of( TestLiteral.from( 13 ), TestLiteral.from( 38 ) ) ); - } @@ -247,12 +231,8 @@ public void renameWithClauseOrderByWithSkipLimitTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (p:Person) WITH p.age AS age ORDER BY age DESC SKIP 1 Limit 1 RETURN age" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 32 ) ) ); - - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java index cd766a87e8..6ea39bca3f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/SkipTest.java @@ -16,6 +16,8 @@ package org.polypheny.db.cypher.clause.general; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -25,8 +27,6 @@ import org.polypheny.db.webui.models.results.GraphResult; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class SkipTest extends CypherTestTemplate { @BeforeEach @@ -75,7 +75,6 @@ public void withAndSkipTest() { GraphResult res = execute( "MATCH (n) WITH n SKIP 2 RETURN n.name, n.age" ); assertEquals( 1, res.getData().length ); - } @@ -90,8 +89,6 @@ public void returnSubsetSkipTest() { GraphResult res = execute( "MATCH (n) RETURN n.name SKIP 3 LIMIT 1" ); assertEquals( 1, res.getData().length ); - - } @@ -111,9 +108,6 @@ public void withAndOrderBySkipTest() { TestNode.from( Pair.of( "name", "Bob" ), Pair.of( "age", 31 ), Pair.of( "depno", 13 ) ) ); - - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java index 6a5350e7d5..5b30eae878 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java @@ -24,6 +24,8 @@ public class UnionTest extends CypherTestTemplate { + protected static final String SINGLE_NODE_MOVIE = "CREATE (wallStreet:Movie {title: 'Wall Street' , released : 2002})"; + @BeforeEach public void reset() { @@ -32,9 +34,6 @@ public void reset() { } - protected static final String SINGLE_NODE_MOVIE = "CREATE (wallStreet:Movie {title: 'Wall Street' , released : 2002})"; - - @Test public void simpleUnionTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -113,8 +112,6 @@ public void allUnionTest() { Row.of( TestLiteral.from( "Hans" ) ), Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Hans" ) ) ); - - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java index 2f19c5a7c0..df83bfdcfa 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java @@ -1,15 +1,14 @@ package org.polypheny.db.cypher.clause.general; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - public class UnwindTest extends CypherTestTemplate { @BeforeEach @@ -22,19 +21,16 @@ public void reset() { @Test public void simpleUnwindTest() { GraphResult res = execute( "UNWIND [1, 3, null] AS x RETURN x, 'val' AS y" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 1 ), TestLiteral.from( "val" ) ), Row.of( TestLiteral.from( 3 ), TestLiteral.from( "val" ) ), Row.of( TestLiteral.from( null ), TestLiteral.from( "val" ) ) ); - } @Test public void emptyUnwind() { GraphResult res = execute( "UNWIND [] AS x RETURN x, 'val' AS y" ); - assertEmpty( res ); } @@ -42,7 +38,6 @@ public void emptyUnwind() { @Test public void nullUnwind() { GraphResult res = execute( "UNWIND null AS x RETURN x, 'val' AS y" ); - assertEmpty( res ); } @@ -50,7 +45,6 @@ public void nullUnwind() { @Test public void listOfListUnwind() { GraphResult res = execute( "WITH [[1], [2, 4], 3] AS nested UNWIND nested AS x UNWIND x AS y RETURN y" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( 2 ) ), @@ -63,7 +57,6 @@ public void listOfListUnwind() { public void nodePropertyUnwind() { execute( "CREATE (n {key: [3,1]})" ); GraphResult res = execute( "MATCH (n) UNWIND n.key AS x RETURN x" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( 1 ) ) ); @@ -77,17 +70,16 @@ public void minMaxAggregateSimpleUnWind() { res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] As val RETURN max(val)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); - } @Test public void minMaxAggregateListOfListUnwind() { GraphResult res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN min(val)" ); - containsRows( res , true , false , Row.of( TestLiteral.from( List.of('a','c' , 23) ) ) ); - res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN max(val)" ); - containsRows( res , true , false , Row.of( TestLiteral.from( 'd' ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 'a', 'c', 23 ) ) ) ); + res = execute( "UNWIND ['d', [1, 2], ['a', 'c', 23]] AS val RETURN max(val)" ); + containsRows( res, true, false, Row.of( TestLiteral.from( 'd' ) ) ); } @@ -98,10 +90,9 @@ public void maxMinAggregateNodePropertyUnWind() { GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN max(age)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); - res = execute( "MATCH (n) UNWIND n.age AS age RETURN min(age)" ); + res = execute( "MATCH (n) UNWIND n.age AS age RETURN min(age)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); - } @@ -109,10 +100,8 @@ public void maxMinAggregateNodePropertyUnWind() { public void sumAggregateNodePropertyUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN sum(age)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); - } @@ -120,10 +109,8 @@ public void sumAggregateNodePropertyUnWind() { public void AvgAggregateNodePropertyUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 38 ) ) ); - } @@ -132,18 +119,15 @@ public void CollectAggregateUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); - containsRows( res , true , false , Row.of( TestLiteral.from( List.of(45 , 31) ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); } - @Test public void countUnWind() { GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ) ); - } @@ -154,8 +138,6 @@ public void distinctUnWind() { containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 1 ) ) ); - - } @@ -166,7 +148,6 @@ public void ConditionalLogicUnWind() { Row.of( TestLiteral.from( 1 ), TestLiteral.from( "odd" ) ), Row.of( TestLiteral.from( 2 ), TestLiteral.from( "even" ) ), Row.of( TestLiteral.from( 3 ), TestLiteral.from( "odd" ) ) ); - } @@ -174,8 +155,6 @@ public void ConditionalLogicUnWind() { public void mapStructureUnWind() { GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ) ), Row.of( TestLiteral.from( 30 ) ) ); - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java index 4ab61fbcbf..d9a865423c 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java @@ -16,6 +16,10 @@ package org.polypheny.db.cypher.clause.general; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -23,12 +27,6 @@ import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - - public class WithTest extends CypherTestTemplate { @BeforeEach @@ -47,7 +45,6 @@ public void singleVariableWithTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Hans" ) ) ); - } @@ -60,7 +57,6 @@ public void multipleRenameVariablesWithTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ), TestLiteral.from( 13 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 31 ), TestLiteral.from( 13 ) ) ); - } @@ -73,7 +69,6 @@ public void renameWithTest() { containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ), Row.of( TestLiteral.from( "Hans" ), HANS ) ); - } @@ -83,10 +78,8 @@ public void startWithTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person) WITH n.name, n WHERE n.name STARTS WITH 'H' RETURN n" ); - containsRows( res, true, true, Row.of( HANS ) ); - } @@ -97,10 +90,8 @@ public void startRenameWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name as name , n WHERE name STARTS WITH 'H' RETURN n" ); assertNode( res, 0 ); - containsRows( res, true, true, Row.of( HANS ) ); - } @@ -111,9 +102,7 @@ public void endWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name , n WHERE n.name ENDS WITH 'x' RETURN name, n" ); assertNode( res, 1 ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); - } @@ -124,9 +113,7 @@ public void endRenameWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name AS name, n WHERE name ENDS WITH 'x' RETURN name, n" ); assertNode( res, 1 ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); - } @@ -139,9 +126,7 @@ public void containsWithTest() { GraphResult res = execute( "MATCH (n:Person)-[]->(p:Animal) WITH *, n.name AS username WHERE username CONTAINS 'a' RETURN username, p" ); assertNode( res, 1 ); - containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), KIRA ) ); - } @@ -150,10 +135,9 @@ public void containsWithTest() { public void avgAggregationRenameWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH avg(p.age) as ageAvg RETURN ageAvg " ); + GraphResult res = execute( "MATCH (p:Person) WITH avg(p.age) as ageAvg RETURN ageAvg " ); containsRows( res, true, true, Row.of( TestLiteral.from( 38 ) ) ); - } @@ -161,11 +145,11 @@ public void avgAggregationRenameWithTest() { public void maxMinAggregationRenameWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH MAX(p.age) as ageMax RETURN ageMax " ); + GraphResult res = execute( "MATCH (p:Person) WITH MAX(p.age) as ageMax RETURN ageMax " ); containsRows( res, true, true, Row.of( TestLiteral.from( 45 ) ) ); - res = execute( "MATCH (p:Person) WITH MIN(p.age) as ageMin RETURN ageMin " ); + res = execute( "MATCH (p:Person) WITH MIN(p.age) as ageMin RETURN ageMin " ); containsRows( res, true, true, Row.of( TestLiteral.from( 31 ) ) ); } @@ -174,8 +158,8 @@ public void maxMinAggregationRenameWithTest() { public void countAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH COUNT(*) as count RETURN count " ); + GraphResult res = execute( "MATCH (p:Person) WITH COUNT(*) as count RETURN count " ); containsRows( res, true, true, Row.of( TestLiteral.from( 2 ) ) ); } @@ -185,8 +169,8 @@ public void countAggregationWithTest() { public void stDevAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH STDEV(p.age) as ageStdev RETURN ageStdev " ); + GraphResult res = execute( "MATCH (p:Person) WITH STDEV(p.age) as ageStdev RETURN ageStdev " ); containsRows( res, true, true, Row.of( TestLiteral.from( 9.8994949 ) ) ); } @@ -196,8 +180,8 @@ public void stDevAggregationWithTest() { public void collectAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH COLLECT(p.age) as ageList RETURN ageList " ); + GraphResult res = execute( "MATCH (p:Person) WITH COLLECT(p.age) as ageList RETURN ageList " ); containsRows( res, true, true, Row.of( TestLiteral.from( 45 ), TestLiteral.from( 31 ) ) ); } @@ -207,7 +191,6 @@ public void collectAggregationWithTest() { public void mapStructureRenameWithTest() { GraphResult res = execute( "WITH {person: {name: 'Anne', age: 25}} AS p RETURN p" ); assertEquals( 1, res.getData().length ); - } @@ -216,6 +199,7 @@ public void filterWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person) WITH p WHERE p.age > 31 RETURN p.name, p.age" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ), @@ -253,7 +237,6 @@ public void unWindListWithTest() { Row.of( TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( 4 ) ), Row.of( TestLiteral.from( 5 ) ) ); - } @@ -287,7 +270,6 @@ public void unWindAndLogicalOperatorsListWithTest() { public void unWindAndWhereInListWithTest() { GraphResult res = execute( "WITH [2, 3, 4, 5] AS numberlist UNWIND numberlist AS number WITH number WHERE number IN [2, 3, 8] RETURN number" ); containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 3 ) ) ); - } @@ -296,7 +278,6 @@ public void createNodeWithTest() { execute( "WITH [1, 1.0] AS list CREATE ({l: list})" ); GraphResult res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); - } @@ -308,8 +289,6 @@ public void distinctWithTest() { GraphResult res = execute( "MATCH (p:Person) WITH Distinct(p) Return p " ); assertEquals( 2, res.getData().length ); - - } @@ -320,8 +299,6 @@ public void existsWithTest() { GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age;" ); containsRows( res, true, true, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); - - } @@ -330,12 +307,12 @@ public void conditionalLogicWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( "MATCH (p:Person) WITH p, CASE WHEN p.age < 30 THEN 'Young' THEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' ELSE 'Elderly END AS ageGroup RETURN p.name, ageGroup;" ); containsRows( res, true, true, Row.of( TestLiteral.from( "Ana" ), TestLiteral.from( "Middle-aged" ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( "Middle-aged" ) ), Row.of( TestLiteral.from( "Alex" ), TestLiteral.from( "Middle-aged" ) ) ); - } @@ -343,12 +320,11 @@ public void conditionalLogicWithTest() { public void orderByWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p.name" ); + GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p.name" ); containsRows( res, true, true, Row.of( TestLiteral.from( "Hans" ) ), Row.of( TestLiteral.from( "Max" ) ) ); - } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java index 86114691f1..835d4aedf8 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java @@ -16,27 +16,22 @@ package org.polypheny.db.cypher.clause.read; -import java.util.Arrays; import java.util.List; -import io.activej.codegen.expression.impl.Null; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.polypheny.db.adapter.annotations.AdapterSettingList; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestEdge; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.cypher.helper.TestNode; -import org.polypheny.db.cypher.helper.TestObject; import org.polypheny.db.cypher.helper.TestPath; -import org.polypheny.db.interpreter.Row; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; + @Slf4j public class MatchTest extends CypherTestTemplate { - @BeforeEach public void reset() { tearDown(); @@ -47,6 +42,8 @@ public void reset() { /////////////////////////////////////////////// ///////// MATCH /////////////////////////////////////////////// + + @Test public void simpleMatchTest() { GraphResult res = execute( "MATCH (n) RETURN n" ); @@ -63,7 +60,6 @@ public void simpleMatchNoneTest() { GraphResult res = execute( "MATCH (n:Villain) RETURN n" ); assertNode( res, 0 ); assertEmpty( res ); - } @@ -75,7 +71,6 @@ public void simpleMatchLabelTest() { GraphResult res = execute( "MATCH (n:Person) RETURN n" ); assertNode( res, 0 ); containsNodes( res, true, MAX ); - } @@ -112,14 +107,12 @@ public void simpleMatchMultiplePropertyTest() { res = execute( "MATCH (n {name: 'Kira', age: 3}) RETURN n" ); assertNode( res, 0 ); containsNodes( res, true, TestNode.from( List.of( "Animal" ), Pair.of( "name", "Kira" ), Pair.of( "age", 3 ), Pair.of( "type", "dog" ) ) ); - } /////////////////////////////////////////////// ///////// PROJECT /////////////////////////////////////////////// - @Test public void NoLabelPropertyTest() { execute( SINGLE_NODE_PERSON_1 ); @@ -127,7 +120,6 @@ public void NoLabelPropertyTest() { GraphResult res = execute( "MATCH (n) RETURN n.age" ); containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( null ) ) ); - } @@ -163,7 +155,6 @@ public void mixedNodeAndPropertyProjectTest() { ///////// EDGE /////////////////////////////////////////////// - @Test public void simpleEdgeTest() { execute( SINGLE_EDGE_1 ); @@ -257,7 +248,6 @@ public void variableHopTest() { ///////// MIXED /////////////////////////////////////////////// - @Test public void simpleMixedRelationshipTest() { execute( SINGLE_EDGE_1 ); @@ -271,21 +261,18 @@ public void simpleMixedRelationshipTest() { Pair.of( "name", "Kira" ), Pair.of( "age", 3 ), Pair.of( "type", "dog" ) ) ); - } /////////////////////////////////////////////// ///////// "CROSS PRODUCT" MATCH /////////////////////////////////////////////// - @Test public void simpleCrossProductMatchTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( "MATCH (p:Person),(n) RETURN p,n" ); assertNode( res, 0 ); assertNode( res, 1 ); - containsRows( res, true, true, Row.of( MAX, MAX ) ); } @@ -297,7 +284,6 @@ public void simpleCrossProductBiMatchTest() { GraphResult res = execute( "MATCH (p:Person),(n) RETURN p,n" ); assertNode( res, 0 ); assertNode( res, 1 ); - containsRows( res, true, false, Row.of( MAX, MAX ), Row.of( HANS, MAX ), @@ -313,9 +299,7 @@ public void simpleTriCrossProductMatchTest() { assertNode( res, 0 ); assertNode( res, 1 ); assertNode( res, 2 ); - containsRows( res, true, true, Row.of( MAX, MAX, MAX ) ); - } @@ -325,9 +309,9 @@ public void simpleNeighborMatchTest() { execute( SINGLE_EDGE_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (p:Person {name:'Max'})-[]-(t) RETURN t" ); assertNode( res, 0 ); - containsRows( res, true, false, Row.of( KIRA ), Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "age", 31 ) ) ) ); @@ -336,8 +320,6 @@ public void simpleNeighborMatchTest() { containsRows( res, true, false, Row.of( KIRA ), Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "age", 31 ) ) ) ); - - } @@ -365,13 +347,12 @@ public void triCrossProductMatchTest() { ///////// PATH /////////////////////////////////////////////// - @Test public void matchPathTest() { execute( SINGLE_EDGE_1 ); + GraphResult res = execute( "MATCH (m {name:'Max'}), (k {name:'Kira'}), p = (m)-[]-(k)\n" + "RETURN p" ); - containsRows( res, true, true, Row.of( TestPath.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), @@ -384,8 +365,6 @@ public void matchPathTest() { TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ) ); - - } @@ -393,11 +372,8 @@ public void matchPathTest() { public void returnPathsByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH Path = () -[]->() RETURN *" ); - containsRows( res, true, false, Row.of( TestPath.of( MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ) ); - - } @@ -405,7 +381,6 @@ public void returnPathsByAsteriskMatchTest() { public void returnNodesByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH (p) RETURN *" ); - containsRows( res, true, false, Row.of( MAX ), Row.of( KIRA ) ); @@ -437,7 +412,6 @@ public void returnEdgesByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH ()-[r]-() RETURN *" ); containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); - } @@ -447,15 +421,11 @@ public void shortestPathMatchTest() { GraphResult res = execute( "MATCH (b:Person {name: 'Max'}), (a:Animal {name: 'Kira'})\n" + "MATCH p = shortestPath((b)-[*]-(a))\n" + "RETURN p\n" ); - containsRows( res, true, true, Row.of( TestPath.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ) ); - - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java index e1ef604276..ed10b96588 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java @@ -16,6 +16,8 @@ package org.polypheny.db.cypher.clause.write; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,7 +26,6 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import static org.junit.jupiter.api.Assertions.assertTrue; public class DmlDeleteTest extends CypherTestTemplate { @@ -82,6 +83,7 @@ public void simpleRelationshipDeleteTest() { execute( SINGLE_EDGE_1 ); execute( "MATCH (:Person {name: 'Max'})-[rel:OWNER_OF]->(:Animal {name: 'Kira'}) \n" + "DELETE rel" ); + GraphResult res = execute( "MATCH (n)-[rel:OWNER_OF]->(a) \n" + "RETURN rel" ); assertEmpty( res ); @@ -94,7 +96,6 @@ public void simpleRelationshipDeleteTest() { Pair.of( "name", "Kira" ), Pair.of( "age", 3 ), Pair.of( "type", "dog" ) ) ) ); - } @@ -114,16 +115,12 @@ public void relationshipWithPropertiesDeleteTest() { List.of( "Person" ), Pair.of( "name", "Hans" ), Pair.of( "age", 31 ) ) ) ); - - } @Test public void pathDeleteTest() { - execute( SINGLE_EDGE_1 ); - execute( """ MATCH p = (person:Person {name: 'Max'})-[rel:OWNER_OF]->( animal :Animal {name: 'Kira'}) DELETE p @@ -132,8 +129,6 @@ public void pathDeleteTest() { GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) RETURN rel " ); assertTrue( res.getData().length == 0 && relations.getData().length == 0 ); - - } @@ -146,7 +141,6 @@ public void NodeWithAllRelationshipsDeleteTest() { GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) Return rel" ); assertTrue( res.getData().length == 0 && relations.getData().length == 0 ); - } @@ -161,8 +155,6 @@ public void allNodesAndRelationshipsDeleteTest() { GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) Return rel" ); assertTrue( res.getData().length == 0 && relations.getData().length == 0 ); - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java index ff7da8df55..bb89632d33 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlInsertTest.java @@ -16,6 +16,8 @@ package org.polypheny.db.cypher.clause.write; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -26,12 +28,9 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class DmlInsertTest extends CypherTestTemplate { - public static final String CREATE_PERSON_MAX = "CREATE (p:Person {name: 'Max Muster'})"; public static final String CREATE_COMPLEX_GRAPH_1 = @@ -110,10 +109,8 @@ public void insertNodeWithManyLabelsTest() { @Test public void insertNodeWithManyLabelsAndAsPropertyTest() { execute( "CREATE (n:Person:Employee {name :'Max'})" ); - GraphResult res = matchAndReturnAllNodes(); containsNodes( res, true, TestNode.from( List.of( "Person", "Employee" ), Pair.of( "name", "Max" ) ) ); - } @@ -132,7 +129,6 @@ public void insertMaxLongAsPropertyValueTest() { GraphResult res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 9223372036854775807L ) ) ); - } @@ -142,7 +138,6 @@ public void insertResultOfMathematicalOperationsTest() { GraphResult res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 9223372036854775807L ) ) ); - } @@ -152,25 +147,20 @@ public void insertENotationAsPropertyValueTest() { GraphResult res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 100 ) ) ); - - } @Test public void insertMaxLongAsResultOfMathematicalOperationsTest() { - execute( "CREATE (n : node { id : 2^63-1})" ); GraphResult res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 4 ) ) ); - } @Test public void insertMinLongAsPropertyValueTest() { - execute( "CREATE (n : node { id : -9223372036854775808L})" ); GraphResult res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); @@ -184,13 +174,11 @@ public void insertMaxDoubleAsPropertyValueTest() { GraphResult res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 1.7976931348623157e+308 ) ) ); - } @Test public void insertMinDoubleAsPropertyValueTest() { - execute( "CREATE (n : node { id : 4.9e-324 })" ); GraphResult res = matchAndReturnAllNodes(); assertEquals( res.getData().length, 1 ); @@ -207,14 +195,11 @@ public void insertHexadecimalIntegerAsPropertyValueTest() { containsNodes( res, true, TestNode.from( List.of( "node" ), Pair.of( "id", 5039 ) ), TestNode.from( List.of( "node" ), Pair.of( "id", -421631 ) ) ); - - } @Test public void insertOctalIntegerAsPropertyValueTest() { - execute( "CREATE (n : node { id : 0o1372})" ); execute( "CREATE (n : node { id :-0o5671 })" ); GraphResult res = matchAndReturnAllNodes(); @@ -291,7 +276,6 @@ public void insertNodeWithPropertyContainsListTest() { execute( "CREATE ({l: [1 ,2,3]})" ); GraphResult res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); - } @@ -358,7 +342,6 @@ public void insertSingleHopPathNoVariableTest() { // only select all edges res = execute( "MATCH ()-[r]->() RETURN r" ); containsEdges( res, true, TestEdge.from( List.of( "OWNER_OF" ) ) ); - } @@ -373,7 +356,6 @@ public void insertSingleHopPathTest() { Pair.of( "name", "Kira" ), Pair.of( "age", 3 ), Pair.of( "type", "dog" ) ) ); - } @@ -402,7 +384,6 @@ public void insertSingleHopPathWithMultiplePropertiesTest() { res = execute( "MATCH ()-[r]->() RETURN r" ); containsEdges( res, true, TestEdge.from( List.of( "KNOWS" ), Pair.of( "since", 1994 ), Pair.of( "relation", "friend" ) ) ); - } @@ -446,6 +427,7 @@ public void insertMultipleHopPathTest() { @Test public void insertAllInOneTest() { execute( CREATE_COMPLEX_GRAPH_1 ); + GraphResult res = execute( "MATCH (n) RETURN n" ); assertEquals( 3, res.getData().length ); assertNode( res, 0 ); @@ -502,7 +484,6 @@ public void insertAdditionalEdgeOneSideTest() { containsRows( res, true, true, Row.of( TestEdge.from( List.of( "KNOWS" ) ) ) ); - } @@ -513,13 +494,10 @@ public void insertAdditionalEdgeOneSideBothSideTest() { execute( "MATCH (max:Person {name: 'Max'})\n" + "CREATE (max)-[:KNOWS]->(hans:Person {name: 'Hans'})-[:KNOWS]->(peter:Person {name: 'Peter'})" ); - GraphResult res = execute( "MATCH ()-[r]->() RETURN r" ); - containsRows( res, true, true, Row.of( TestEdge.from( List.of( "KNOWS" ) ) ), Row.of( TestEdge.from( List.of( "KNOWS" ) ) ) ); - } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java index 0117c8ab4a..f99b982d38 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlUpdateTest.java @@ -25,6 +25,7 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; + public class DmlUpdateTest extends CypherTestTemplate { @BeforeEach @@ -108,7 +109,6 @@ public void updateVariablesDecrementTest() { containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "'Ann Smith" ) ) ); - } @@ -126,8 +126,6 @@ public void updateVariablesIncrementAndDecrementTest() { List.of( "Person" ), Pair.of( "name", "Peter Smith" ), Pair.of( "position", "Entrepreneur" ) ) ) ); - - } @@ -208,5 +206,4 @@ public void updateMultiplePropertiesWithOneSetTest() { Pair.of( "surname", "Taylor " ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java index 69f26b211d..980b4f35b6 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java @@ -16,6 +16,9 @@ package org.polypheny.db.cypher.clause.write; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -23,9 +26,6 @@ import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; public class ForeachTest extends CypherTestTemplate { @@ -50,8 +50,6 @@ public void createWithForeachTest() { TestNode.from( Pair.of( "name", "Alice" ) ), TestNode.from( Pair.of( "name", "Bob" ) ), TestNode.from( Pair.of( "name", "Charlie" ) ) ); - - } @@ -69,7 +67,6 @@ public void mergeWithForeachTest() { TestNode.from( Pair.of( "name", "Alice" ) ), TestNode.from( Pair.of( "name", "Bob" ) ), TestNode.from( Pair.of( "name", "Charlie" ) ) ); - } @@ -86,7 +83,6 @@ WITH collect(p) AS people )""" ); GraphResult res = matchAndReturnAllNodes(); assertEmpty( res ); - } @@ -105,7 +101,6 @@ WITH collect(p) AS people GraphResult res = matchAndReturnAllNodes(); containsRows( res, true, false, Row.of( TestLiteral.from( null ) ), Row.of( TestLiteral.from( null ) ) ); - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java index 64735a2ff1..46b3f50fa1 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java @@ -16,6 +16,10 @@ package org.polypheny.db.cypher.clause.write; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,15 +29,10 @@ import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; @Slf4j public class MergeTest extends CypherTestTemplate { - protected static final String SINGLE_NODE_PERSON_COMPLEX_4 = "CREATE (charlie:Person {name: 'Charlie Sheen', bornIn: 'New York', chauffeurName: 'John Brown'})"; protected static final String SINGLE_NODE_PERSON_COMPLEX_5 = "CREATE (martin:Person {name: 'Martin Sheen', bornIn: 'Ohio', chauffeurName: 'Bob Brown'})"; protected static final String SINGLE_NODE_PERSON_COMPLEX_6 = "CREATE (michael:Person {name: 'Michael Douglas', bornIn: 'New Jersey', chauffeurName: 'John Brown'})"; @@ -62,8 +61,6 @@ public void returnSingleNodeMergeTest() { GraphResult res = execute( "MERGE (P) Return P " ); assertNode( res, 0 ); containsNodes( res, true, TestNode.from( List.of() ) ); - - } @@ -87,7 +84,6 @@ public void singleNodeWithLabelMergeTest() { @Test public void singleNodeWithMultipleLabelsMergeTest() { - // new node execute( "MERGE (robert:Critic:Viewer)" ); GraphResult res = matchAndReturnAllNodes(); @@ -98,16 +94,14 @@ public void singleNodeWithMultipleLabelsMergeTest() { execute( "MERGE (robert:Critic:Viewer)" ); res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); - } @Test public void singleNodeWithSinglePropertyMergeTest() { - execute( "MERGE (charlie {name: 'Charlie Sheen'})" ); - GraphResult res = matchAndReturnAllNodes(); + GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); containsNodes( res, true, TestNode.from( List.of(), Pair.of( "name", "Charlie Sheen" ) ) ); @@ -115,13 +109,11 @@ public void singleNodeWithSinglePropertyMergeTest() { execute( "MERGE (charlie {name: 'Charlie Sheen'})" ); res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); - } @Test public void singleNodeWithMultiplePropertiesMergeTest() { - execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); @@ -131,14 +123,12 @@ public void singleNodeWithMultiplePropertiesMergeTest() { execute( "MERGE (charlie {name: 'Charlie Sheen', age: 10})" ); res = matchAndReturnAllNodes(); - assertEquals( 1, res.getData().length ); } @Test public void singleNodeWithPropertiesAndLabelMergeTest() { - execute( "MERGE (michael:Person {name: 'Michael Douglas' , age : 10})" ); GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); @@ -148,7 +138,6 @@ public void singleNodeWithPropertiesAndLabelMergeTest() { execute( "MERGE (michael:Person {name: 'Michael Douglas' , age : 10})" ); res = matchAndReturnAllNodes(); - assertEquals( 1, res.getData().length ); } @@ -158,7 +147,6 @@ public void singleNodeDerivedFromExistingNodeMergeTest() { execute( SINGLE_NODE_PERSON_COMPLEX_4 ); execute( SINGLE_NODE_PERSON_COMPLEX_5 ); execute( SINGLE_NODE_PERSON_COMPLEX_6 ); - execute( """ MATCH (person:Person) MERGE (location:Location {name: person.bornIn}) @@ -176,18 +164,15 @@ public void singleNodeDerivedFromExistingNodeMergeTest() { """ ); res = execute( "MATCH (location:Location) RETURN location" ); - assertEquals( 1, res.getData().length ); } @Test public void createWithMergeTest() { - execute( "MERGE (keanu:Person {name: 'Keanu Reeves', bornIn: 'Beirut', chauffeurName: 'Eric Brown'})\n" + "ON CREATE SET keanu.age = 20" ); - GraphResult res = matchAndReturnAllNodes(); assertNode( res, 0 ); containsNodes( res, true, @@ -197,7 +182,6 @@ public void createWithMergeTest() { ); res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); - } @@ -225,8 +209,6 @@ public void matchWithMergeTest() { Pair.of( "found", true ) ) ); assertEquals( 1, res.getData().length ); - - } @@ -281,8 +263,6 @@ public void singleRelationshipMergeTest() { res = execute( "MATCH ()-[r]->() RETURN r" ); assertEquals( 1, res.getData().length ); - - } @@ -317,7 +297,6 @@ public void multipleRelationshipsMergeTest() { res = matchAndReturnAllNodes(); assertEquals( 1, res.getData().length ); - } @@ -384,7 +363,6 @@ public void relationshipOnTwoExistingNodeMergeTest() { GraphResult nodes = execute( "MATCH (location:Location) RETURN Location " ); assertTrue( edges.getData().length == 3 && nodes.getData().length == 3 ); - } @@ -415,8 +393,6 @@ public void relationshipOnExistingNodeAndMergeNodeDerivedFromAnodeProperty() { GraphResult edges = execute( "MATCH ()-[HAS_CHAUFFEUR]->() RETURN HAS_CHAUFFEUR" ); GraphResult nodes = execute( "MATCH (n:Chauffeur) RETURN Chauffeur" ); assertTrue( edges.getData().length == 3 && nodes.getData().length == 3 ); - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java index 6792fd7002..257c9c64d8 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/RemoveTest.java @@ -16,7 +16,9 @@ package org.polypheny.db.cypher.clause.write; +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,9 +27,6 @@ import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; @Slf4j public class RemoveTest extends CypherTestTemplate { @@ -49,8 +48,6 @@ public void labelRemoveTest() { + "REMOVE n:Person " ); GraphResult res = execute( "MATCH (n :Person) RETURN n" ); assertEquals( 0, res.getData().length ); - - } @@ -59,10 +56,7 @@ public void returnWithRemoveTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( "MATCH (n:Person {name: 'Max'})\n" + "REMOVE n:Person RETURN n " ); - assertEquals( 1, res.getData().length ); - - } @@ -76,8 +70,6 @@ public void multipleLabelsRemoveTest() { execute( "MATCH (n) REMOVE n:Person:Employee " ); res = execute( "MATCH (n :Person:Employee) RETURN n" ); assertEquals( 0, res.getData().length ); - - } @@ -87,8 +79,6 @@ public void singlePropertyNodeRemoveTest() { execute( "MATCH (n : Person {name: 'Ann'}) REMOVE a.age " ); GraphResult res = execute( "MATCH (n : Person) RETURN n.age , n.name" ); containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); - - } @@ -99,10 +89,8 @@ public void multiplePropertiesRemoveTest() { MATCH (n:Person {name: 'Ann'}) REMOVE n.age, n.depno """ ); - GraphResult res = execute( "MATCH (n : Person) RETURN n.age , n.depno , n.name " ); containsRows( res, true, true, Row.of( TestLiteral.from( null ), TestLiteral.from( null ), TestLiteral.from( "Ann" ) ) ); - } @@ -112,7 +100,6 @@ public void allPropertiesNodeRemoveTest() { execute( "MATCH (n:Person) SET n = {}" ); GraphResult res = matchAndReturnAllNodes(); assertEquals( 0, res.getData().length ); - } @@ -123,8 +110,6 @@ public void singlePropertyRelationshipRemoveTest() { + "REMOVE rel.since" ); GraphResult res = execute( "MATCH ()-[r:KNOWS]->() RETURN r.since" ); containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); - - } @@ -148,5 +133,4 @@ public void allPropertiesRelationshipRemoveTest() { containsRows( res, true, true, Row.of( TestLiteral.from( null ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java index 073c805cae..db4ababd1b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java @@ -14,18 +14,18 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Functions; +package org.polypheny.db.cypher.functions; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.Arrays; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; public class AggregateTest extends CypherTestTemplate { @@ -60,8 +60,6 @@ public void singleCountAggregateTest() { containsRows( res, true, true, Row.of( TestLiteral.from( 7 ) ) ); - - } @@ -78,15 +76,12 @@ public void countFieldAggregateTest() { Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 2 ) ) ); - } @Test public void countNullAggregateTest() { - GraphResult res = execute( "MATCH (n) RETURN count(*)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 0 ) ) ); } @@ -100,13 +95,12 @@ public void countRenameFieldAggregateTest() { execute( SINGLE_EDGE_2 ); GraphResult res = execute( "MATCH (n) RETURN n.name, count(*) AS c" ); - assertEquals("c", res.getHeader()[1].name); + assertEquals( "c", res.getHeader()[1].name ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 3 ) ), Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 2 ) ) ); - } @@ -124,7 +118,6 @@ public void doubleCountRenameAggregateTest() { Row.of( TestLiteral.from( "Kira" ), TestLiteral.from( 3 ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( null ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 31 ), TestLiteral.from( 1 ) ) ); - } @@ -144,16 +137,13 @@ public void countDistinctFunctionTest() { GraphResult res = execute( "MATCH (n) RETURN COUNT(DISTINCT n.name)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); - - } @Test public void singleAvgAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); - execute( SINGLE_NODE_PERSON_2 - ); + execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_EDGE_1 ); execute( SINGLE_EDGE_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); @@ -164,7 +154,6 @@ public void singleAvgAggregateTest() { System.out.println( Arrays.deepToString( data ) ); containsRows( res, true, false, Row.of( TestLiteral.from( 26.33333333333333 ) ) ); - } @@ -172,8 +161,8 @@ public void singleAvgAggregateTest() { public void avgNullAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (p:Person) RETURN AVG(p.age)" ); + GraphResult res = execute( "MATCH (p:Person) RETURN AVG(p.age)" ); containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); } @@ -211,7 +200,6 @@ public void singleCollectAggregationTest() { GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age) " ); containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); - } @@ -222,7 +210,6 @@ public void collectRenameAggregationTest() { GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age) AS ages" ); containsRows( res, true, false, Row.of( TestLiteral.from( List.of( 45, 31 ) ) ) ); - } @@ -244,7 +231,7 @@ public void collectNullAggregationTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (p:Person) RETURN COLLECT(p.age)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( List.of( ) ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( List.of() ) ) ); } @@ -263,7 +250,6 @@ public void singleMinMaxAggregateTest() { res = execute( "MATCH (n) RETURN max(n.age)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); - } @@ -271,17 +257,14 @@ public void singleMinMaxAggregateTest() { void minMaxNullAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); + GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); res = execute( "MATCH (n) RETURN max(n.age) as ageMax" ); - containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); - - } @@ -292,38 +275,30 @@ public void minMaxRenameAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (n) RETURN min(n.age) as ageMin" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 31 ) ) ); res = execute( "MATCH (n) RETURN max(n.age) as ageMax" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 45 ) ) ); - - } @Test public void minMaxRenameFieldAggregateTest() { - execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); GraphResult res = execute( "MATCH (n) RETURN n.depno as depNumber , min(n.age) as ageMin" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 13 ), TestLiteral.from( 31 ) ), Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); res = execute( "MATCH (n) RETURN n.depno as depNumber , max(n.age) as ageMax" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 13 ), TestLiteral.from( 45 ) ), Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); - } @@ -348,12 +323,6 @@ public void sumNullAggregationTest() { GraphResult res = execute( "MATCH (n) RETURN sum(n.age)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 0 ) ) ); - - /// Printing the data using Arrays.deepToString - System.out.print( "Alyaa :" ); - String[][] data = res.getData(); - System.out.println( Arrays.deepToString( data ) ); - } @@ -365,8 +334,6 @@ public void sumRenameAggregationTest() { GraphResult res = execute( "MATCH (p:Person) RETURN sum(p.age) As totalAge " ); containsRows( res, true, false, Row.of( TestLiteral.from( 76 ) ) ); - - } @@ -380,8 +347,6 @@ public void sumRenameFieldAggregationTest() { containsRows( res, true, false, Row.of( TestLiteral.from( 13 ), TestLiteral.from( 76 ) ), Row.of( TestLiteral.from( 14 ), TestLiteral.from( 32 ) ) ); - - } @@ -389,11 +354,10 @@ public void sumRenameFieldAggregationTest() { public void singleStDevAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) " ); containsRows( res, true, false, Row.of( TestLiteral.from( 9.8994949 ) ) ); - - } @@ -401,6 +365,7 @@ public void singleStDevAggregateTest() { public void stDevNullAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) " ); containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); @@ -411,10 +376,10 @@ public void stDevNullAggregateTest() { public void stDevRenameAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( "MATCH (p:Person) RETURN stdev(p.age) AS Stdev " ); containsRows( res, true, false, Row.of( TestLiteral.from( 9.8994949 ) ) ); - } @@ -428,5 +393,4 @@ public void stDevRenameFieldAggregateTest() { Row.of( TestLiteral.from( 9.8994949 ), TestLiteral.from( 13 ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/ListFunTest.java similarity index 98% rename from dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/functions/ListFunTest.java index 9f8f933cc4..93a94620c3 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/ListFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/ListFunTest.java @@ -14,16 +14,17 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Functions; +package org.polypheny.db.cypher.functions; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; public class ListFunTest extends CypherTestTemplate { @@ -58,19 +59,15 @@ public void patternExpressionSizeFunTest() { MATCH (a) WHERE a.name = 'Max' RETURN size((a)-[]->())) AS fof""" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 2 ) ) ); - } @Test public void stringSizeFunTest() { execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (a) RETURN size(a.name)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); } @@ -78,9 +75,7 @@ public void stringSizeFunTest() { @Test public void simpleRangeFunTest() { - GraphResult res = execute( "RETURN RANGE(1, 3)" ); - containsRows( res, true, true, Row.of( TestLiteral.from( 1 ), TestLiteral.from( 2 ), TestLiteral.from( 3 ) ) ); } @@ -91,7 +86,6 @@ public void returnLabelsFunTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH (a)" + "RETURN labels(a)" ); - containsRows( res, true, false, Row.of( TestLiteral.from( List.of( "Person" ) ) ) ); } @@ -103,7 +97,6 @@ public void returnNodesFunTest() { + "RETURN nodes(p)" ); assertEquals( 1, res.getData().length ); containsRows( res, true, false, Row.of( TestLiteral.from( List.of( MAX, KIRA ) ) ) ); - } @@ -124,5 +117,4 @@ public void returnRelationAndNodesFunTest() { assertEquals( 1, res.getData().length ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/NumericFunTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/functions/NumericFunTest.java index 4419a1a3ce..801703a73f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/NumericFunTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Functions; +package org.polypheny.db.cypher.functions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,7 +34,6 @@ public void reset() { @Test public void absFunTest() { GraphResult res = execute( "RETURN ABS(-5) " ); - containsRows( res, true, true, Row.of( TestLiteral.from( 5 ) ) ); res = execute( "RETURN ABS(5)" ); @@ -61,14 +60,11 @@ public void roundFunTest() { res = execute( "RETURN ROUND(-3.5)" ); containsRows( res, true, true, Row.of( TestLiteral.from( -4 ) ) ); - - } @Test public void floorFunTest() { - GraphResult res = execute( "RETURN FLOOR(3)" ); containsRows( res, true, true, Row.of( TestLiteral.from( 3 ) ) ); @@ -99,7 +95,6 @@ public void ceilFunTest() { res = execute( "RETURN CEIL(3.5)" ); containsRows( res, true, true, Row.of( TestLiteral.from( 4 ) ) ); - } @@ -120,12 +115,11 @@ public void nonPerfectSquareSqrtFunTest() { } + // Todo missing @Test public void sqrtFunTestNegative() { - execute( "RETURN SQRT(-9)" ); + execute( "RETURN SQRT(-9)" ); // containsRows(res, true, true, Row.of(TestLiteral.from(null))); } } - - diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/OtherFunTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/functions/OtherFunTest.java index ffe58012d2..9cc0990f55 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/OtherFunTest.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Functions; +package org.polypheny.db.cypher.functions; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,7 +24,6 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import static org.junit.jupiter.api.Assertions.assertEquals; public class OtherFunTest extends CypherTestTemplate { @@ -44,9 +44,7 @@ public void typeFunTest() { MATCH (a)-[r]->(b) RETURN TYPE(r) """ ); - containsRows( res, true, true, Row.of( TestLiteral.from( "OWNER_OF" ) ) ); - } @@ -57,8 +55,7 @@ public void idFunTest() { MATCH (p:Person { name: 'Max' }) RETURN ID(p) """ ); - - assertEquals(1 , res.getData().length); + assertEquals( 1, res.getData().length ); } @@ -68,7 +65,6 @@ public void testCoalesceFunTest() { execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); GraphResult result = execute( "MATCH (p) RETURN p.name, coalesce(p.age, 0) AS age" ); - containsRows( result, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 0 ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( 0 ) ), @@ -81,10 +77,9 @@ public void testDefaultValuesWithCoalesceFunTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); - GraphResult result = execute( "MATCH (p) RETURN p.name, coalesce(p.age, 'unknown') AS age" ); + GraphResult result = execute( "MATCH (p) RETURN p.name, coalesce(p.age, 'unknown') AS age" ); assertNode( result, 0 ); - containsRows( result, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "unknown" ) ), Row.of( TestLiteral.from( "Hans" ), TestLiteral.from( "unknown" ) ), @@ -95,14 +90,16 @@ public void testDefaultValuesWithCoalesceFunTest() { /////////////////////////////// // Predicate Functions ///////////////////////////// + + @Test public void ExistFunTest() { execute( SINGLE_NODE_PERSON_1 ); + GraphResult res = execute( """ MATCH (p:Person { name: 'Max' }) RETURN EXISTS(p.age) """ ); - containsRows( res, true, true, Row.of( TestLiteral.from( false ) ) ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); @@ -113,5 +110,4 @@ RETURN EXISTS(p.age) containsRows( res, true, true, Row.of( TestLiteral.from( true ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/SpatialFunTest.java similarity index 98% rename from dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/functions/SpatialFunTest.java index 14fb958507..42abee4e79 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/SpatialFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/SpatialFunTest.java @@ -14,8 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Functions; - +package org.polypheny.db.cypher.functions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class SpatialFunTest extends CypherTestTemplate { @BeforeEach @@ -34,7 +34,6 @@ public void reset() { @Test public void cartesian2DPointFunTest() { - GraphResult res = execute( """ WITH point({x: 3, y: 4}) AS p RETURN diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/StringFunTest.java similarity index 99% rename from dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/functions/StringFunTest.java index c2470a67d9..6331e559fc 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/StringFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/StringFunTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Functions; +package org.polypheny.db.cypher.functions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class StringFunTest extends CypherTestTemplate { @BeforeEach @@ -37,8 +38,6 @@ public void upperFunTest() { containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); res = execute( "RETURN UPPER('hElLo')" ); containsRows( res, true, true, Row.of( TestLiteral.from( "HELLO" ) ) ); - - } @@ -124,7 +123,6 @@ public void emptyTrimFunTest() { public void normalReplaceFunTest() { GraphResult res = execute( "RETURN REPLACE('Hello, world!', 'world', 'Cypher') " ); containsRows( res, true, true, Row.of( TestLiteral.from( "Hello, Cypher!" ) ) ); - } @@ -155,6 +153,4 @@ public void stringLengthFunTest() { containsRows( res, true, true, Row.of( TestLiteral.from( 13 ) ) ); } - } - diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/TemporalFunTest.java similarity index 99% rename from dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/functions/TemporalFunTest.java index 333dab11dc..d763bd9672 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Functions/TemporalFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/TemporalFunTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Functions; +package org.polypheny.db.cypher.functions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class TemporalFunTest extends CypherTestTemplate { @BeforeEach @@ -33,7 +34,6 @@ public void reset() { @Test public void stringIntoDateFunTest() { - GraphResult res = execute( "RETURN date('2015-07-21')\n" ); containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21" ) ) ); @@ -54,7 +54,6 @@ public void stringIntoDateFunTest() { @Test public void yearMonthDayDateFunTest() { GraphResult res = execute( "RETURN date({year: 1984, month: 10, day: 11})" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11" ) ) ); @@ -83,7 +82,6 @@ public void yearQuarterDayDateFunTest() { @Test public void yearMonthDayZonedTimeDateFunTest() { - GraphResult res = execute( "RETURN datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 123, microsecond: 456, nanosecond: 789}) AS theDate" ); containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14.123456789Z" ) ) ); @@ -92,8 +90,6 @@ public void yearMonthDayZonedTimeDateFunTest() { res = execute( "RETURN datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14})" ); containsRows( res, true, false, Row.of( TestLiteral.from( "1984-10-11T12:31:14Z" ) ) ); - - } @@ -108,37 +104,30 @@ public void yearWeekDayTimeDateFunTest() { public void yearQuarterDayTimeDateFunTest() { GraphResult res = execute( "RETURN datetime({year: 1984, quarter: 3, dayOfQuarter: 45, hour: 12, minute: 31, second: 14, microsecond: 645876})" ); containsRows( res, true, false, Row.of( TestLiteral.from( "1984-08-14T12:31:14.645876Z" ) ) ); - } @Test public void stringIntoTimeDateFunTest() { GraphResult res = execute( "RETURN datetime('2015-07-21T21:40:32.142+0100')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142+01:00" ) ) ); - res = execute( "RETURN datetime('2015-W30-2T214032.142Z')" ); + res = execute( "RETURN datetime('2015-W30-2T214032.142Z')" ); containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40:32.142Z" ) ) ); res = execute( "RETURN datetime('2015T214032-0100')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-01-01T21:40:32-01:00" ) ) ); res = execute( "RETURN datetime('20150721T21:40-01:30')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "2015-07-21T21:40-01:30" ) ) ); res = execute( "RETURN datetime('2015-07-21T21:40:32.142[Europe/London]')" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "datetime('2015-07-21T21:40:32.142[Europe/London]')" ) ) ); - } @Test public void timeFunTest() { - GraphResult res = execute( "RETURN time({hour: 12, minute: 31, second: 14, millisecond: 123, microsecond: 456, nanosecond: 789})" ); containsRows( res, true, false, Row.of( TestLiteral.from( "12:31:14.123456789Z" ) ) ); @@ -153,7 +142,6 @@ public void timeFunTest() { res = execute( "RETURN time({hour: 12, timezone: '+01:00'})" ); containsRows( res, true, false, Row.of( TestLiteral.from( "12:00:00+01:00" ) ) ); - } @@ -171,13 +159,11 @@ public void stringIntoTimeFunTest() { res = execute( "RETURN time('214032-0100')" ); containsRows( res, true, false, Row.of( TestLiteral.from( "21:40:32-01:00" ) ) ); - } @Test public void durationFunTest() { - GraphResult res = execute( "RETURN duration({days: 14, hours:16, minutes: 12})" ); containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); @@ -195,8 +181,6 @@ public void durationFunTest() { res = execute( "RETURN duration({minutes: 1.5, seconds: 1, nanoseconds: 123456789})" ); containsRows( res, true, false, Row.of( TestLiteral.from( "PT1M31.123456789S" ) ) ); - - } @@ -204,6 +188,7 @@ public void durationFunTest() { public void stringIntoDurationFunTest() { GraphResult res = execute( "RETURN duration(\"P14DT16H12M\") " ); containsRows( res, true, false, Row.of( TestLiteral.from( "P14DT16H12M" ) ) ); + res = execute( "RETURN duration(\"P5M1.5D\")" ); containsRows( res, true, false, Row.of( TestLiteral.from( "P5M1DT12H" ) ) ); @@ -215,8 +200,6 @@ public void stringIntoDurationFunTest() { res = execute( "RETURN duration(\"P2012-02-02T14:37:21.545\")" ); containsRows( res, true, false, Row.of( TestLiteral.from( "P2012Y2M2DT14H37M21.545S" ) ) ); - - } @@ -226,5 +209,4 @@ public void durationBetweenFunTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "P30Y8M13D" ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestEdge.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestEdge.java index 34e40f55b9..f9492714dd 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestEdge.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestEdge.java @@ -23,6 +23,7 @@ import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.util.Pair; + public class TestEdge extends TestGraphObject { @Nullable diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestGraphObject.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestGraphObject.java index 9dae0e0508..6c8d956fce 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestGraphObject.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestGraphObject.java @@ -33,6 +33,7 @@ import org.polypheny.db.type.entity.graph.GraphPropertyHolder; import org.polypheny.db.util.Pair; + public class TestGraphObject implements TestObject { public static double EPSILON = 0.2; @@ -98,15 +99,12 @@ public boolean matches( GraphPropertyHolder other, boolean exclusive, boolean ig if ( entry.getValue().isList() ) { int i = 0; PolyList list = entry.getValue().asList(); - for ( PolyValue o : list ) { matches &= o.equals( ((List) properties.get( entry.getKey() )).get( i ) ); i++; } } else if ( entry.getValue().isNumber() || other.properties.get( entry.getKey() ).isNumber() ) { - matches &= - toBigDecimal( other.properties.get( entry.getKey() ).toString() ).doubleValue() - - toBigDecimal( entry.getValue().toString() ).doubleValue() < EPSILON; + matches &= toBigDecimal( other.properties.get( entry.getKey() ).toString() ).doubleValue() - toBigDecimal( entry.getValue().toString() ).doubleValue() < EPSILON; } else { matches &= other.properties.get( entry.getKey() ).equals( entry.getValue() ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestLiteral.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestLiteral.java index fdfe8a9dce..d18040e3fa 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestLiteral.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestLiteral.java @@ -19,6 +19,7 @@ import javax.annotation.Nullable; import org.polypheny.db.type.entity.PolyValue; + public class TestLiteral implements TestObject { public final String value; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestNode.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestNode.java index 1da891528f..cd8e556e6e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestNode.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestNode.java @@ -42,5 +42,4 @@ public static TestNode from( @NotNull List labels, Pair. return new TestNode( null, getProps( properties ), getLabels( labels ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestObject.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestObject.java index 5273056301..4e07da1123 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestObject.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestObject.java @@ -18,6 +18,7 @@ import org.polypheny.db.type.entity.PolyValue; + public interface TestObject { boolean matches( PolyValue other, boolean exclusive ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestPath.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestPath.java index 6f4a5ffcf8..85830ecc00 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestPath.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestPath.java @@ -16,7 +16,6 @@ package org.polypheny.db.cypher.helper; - import java.util.List; import lombok.SneakyThrows; import org.polypheny.db.cypher.CypherTestTemplate; @@ -25,6 +24,7 @@ import org.polypheny.db.type.entity.graph.GraphPropertyHolder; import org.polypheny.db.type.entity.graph.PolyPath; + public class TestPath implements TestObject { private final List objects; diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperatorsTest.java b/dbms/src/test/java/org/polypheny/db/cypher/operators/BooleanOperatorsTest.java similarity index 98% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperatorsTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/operators/BooleanOperatorsTest.java index 91df7332bf..ddf077e559 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/BooleanOperatorsTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/operators/BooleanOperatorsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Operators; +package org.polypheny.db.cypher.operators; import org.junit.jupiter.api.BeforeEach; @@ -36,9 +36,9 @@ public void setUp() { public void conjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a AND b " ); containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + res = execute( "WITH true as a , true as b RETURN a AND b " ); containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); - } @@ -46,9 +46,9 @@ public void conjunctionOperatorTest() { public void disjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a OR b " ); containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + res = execute( "WITH false as a , false as b RETURN a OR b " ); containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); - } @@ -56,11 +56,12 @@ public void disjunctionOperatorTest() { public void exclusiveDisjunctionOperatorTest() { GraphResult res = execute( "WITH true as a , false as b RETURN a XOR b " ); containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); + res = execute( "WITH true as a , true as b RETURN a XOR b " ); containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); + res = execute( "WITH false as a , false as b RETURN a XOR b " ); containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); - } @@ -71,7 +72,6 @@ public void negationOperatorTest() { res = execute( "WITH false as a RETURN NOT a " ); containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); - } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperationsTest.java b/dbms/src/test/java/org/polypheny/db/cypher/operators/ComparisonOperationsTest.java similarity index 98% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperationsTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/operators/ComparisonOperationsTest.java index ac3d9a2a79..d68c070391 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ComparisonOperationsTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/operators/ComparisonOperationsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Operators; +package org.polypheny.db.cypher.operators; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class ComparisonOperationsTest extends CypherTestTemplate { @BeforeEach @@ -42,7 +43,6 @@ public void IsNullOperatorTest() { public void IsNotNullFunction() { GraphResult res = execute( "Return null is null as Result" ); containsRows( res, true, false, Row.of( TestLiteral.from( true ) ) ); - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperatorsTest.java b/dbms/src/test/java/org/polypheny/db/cypher/operators/ListOperatorsTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperatorsTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/operators/ListOperatorsTest.java index 29a30bb4f3..baa8c08495 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/ListOperatorsTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/operators/ListOperatorsTest.java @@ -14,8 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Operators; - +package org.polypheny.db.cypher.operators; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class ListOperatorsTest extends CypherTestTemplate { @BeforeEach @@ -51,5 +51,4 @@ public void checkIfListInListOperatorTest() { containsRows( res, true, false, Row.of( TestLiteral.from( false ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperatorsTest.java b/dbms/src/test/java/org/polypheny/db/cypher/operators/MathematicalOperatorsTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperatorsTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/operators/MathematicalOperatorsTest.java index e6f3c8b0bc..0f735a8f3a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/MathematicalOperatorsTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/operators/MathematicalOperatorsTest.java @@ -14,8 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Operators; - +package org.polypheny.db.cypher.operators; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class MathematicalOperatorsTest extends CypherTestTemplate { @BeforeEach @@ -42,16 +42,13 @@ public void additionOperator() { @Test public void minisOperatorTest() { GraphResult res = execute( "RETURN 3 - 2" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); - } @Test public void multiplicationOperatorTest() { GraphResult res = execute( "RETURN 2 * 3" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 6 ) ) ); } @@ -59,7 +56,6 @@ public void multiplicationOperatorTest() { @Test public void divisionOperatorTest() { GraphResult res = execute( "RETURN 6 / 3 " ); - containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @@ -68,16 +64,13 @@ public void divisionOperatorTest() { public void moduleOperatorTest() { GraphResult res = execute( "RETURN 3 % 2 " ); containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); - } @Test public void exponentiationOperator() { GraphResult res = execute( "RETURN 2 ^ 3" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 8.0 ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperatorsTest.java b/dbms/src/test/java/org/polypheny/db/cypher/operators/StringOperatorsTest.java similarity index 96% rename from dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperatorsTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/operators/StringOperatorsTest.java index b5ddfc5bc2..f76bf6ca9b 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Operators/StringOperatorsTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/operators/StringOperatorsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Operators; +package org.polypheny.db.cypher.operators; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class StringOperatorsTest extends CypherTestTemplate { @@ -38,5 +39,4 @@ public void concatenateWithPlusOperatorTest() { containsRows( res, true, true, Row.of( TestLiteral.from( "neo4j" ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java similarity index 99% rename from dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java index 1aa0687eac..5796e0aefe 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CallSubqueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java @@ -14,9 +14,11 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Subqueries; +package org.polypheny.db.cypher.subqueries; +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; @@ -24,9 +26,7 @@ import org.polypheny.db.cypher.helper.TestNode; import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; public class CallSubqueriesTest extends CypherTestTemplate { @@ -40,7 +40,6 @@ public void reset() { @Test public void simpleCallTest() { - GraphResult res = execute( " CALL { RETURN 'hello' AS innerReturn} \n" + "RETURN innerReturn" ); @@ -82,7 +81,6 @@ public void returnMatchNodesCallTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( "CALL { MATCH (p:Person) RETURN p} RETURN p " ); containsRows( res, true, true, Row.of( MAX ) ); - } @@ -99,7 +97,6 @@ RETURN count(p) AS totalPeople} """ ); containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); - } @@ -107,14 +104,15 @@ RETURN count(p) AS totalPeople} public void countRelationshipsCallTest() { execute( SINGLE_EDGE_1 ); execute( SINGLE_EDGE_2 ); + GraphResult res = execute( """ CALL { MATCH ()-[r]->() RETURN count(r) AS totalRelationships } RETURN totalRelationships """ ); - containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); + containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } @@ -141,6 +139,7 @@ public void FilterMatchedNodesByOutputOfCallTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); + GraphResult res = execute( """ CALL { MATCH (p:Person { name: 'Bob' }) @@ -154,7 +153,6 @@ public void FilterMatchedNodesByOutputOfCallTest() { containsNodes( res, true, TestNode.from( List.of( "Person" ), Pair.of( "name", "Ann" ) ), TestNode.from( List.of( "Person" ), Pair.of( "name", "Alex" ) ) ); - } @@ -163,6 +161,7 @@ public void UnionCallTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); + GraphResult res = execute( """ CALL { MATCH (p:Person) RETURN p @@ -188,9 +187,9 @@ public void unitSubQueryCallTest() { WITH p CREATE (:Person {name: p.name})\s } RETURN count(*)""" ); + //the number of rows present after the subquery is the same as was going into the subquery containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CollectSubQueriesTest.java similarity index 98% rename from dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/subqueries/CollectSubQueriesTest.java index 1f4a7442b0..c102cc61c9 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CollectSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CollectSubQueriesTest.java @@ -14,17 +14,20 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Subqueries; +package org.polypheny.db.cypher.subqueries; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; -import java.util.List; + public class CollectSubQueriesTest extends CypherTestTemplate { + public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10})"; + @BeforeEach public void reset() { @@ -33,9 +36,6 @@ public void reset() { } - public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10})"; - - @Test public void simpleCollectSubQueryTest() { execute( SINGLE_EDGE_1 ); @@ -46,7 +46,6 @@ public void simpleCollectSubQueryTest() { RETURN person.name AS name""" ); containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ) ) ); - } @@ -54,6 +53,7 @@ public void simpleCollectSubQueryTest() { public void useCollectSubQueryInReturnTest() { execute( SINGLE_NODE_PERSON_1 ); execute( EDGE_3 ); + GraphResult res = execute( """ MATCH (person:Person) RETURN person.name, @@ -64,15 +64,15 @@ public void useCollectSubQueryInReturnTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); - } @Test public void whereWithCollectSubQueryTest() { execute( EDGE_3 ); - GraphResult res = execute( """ + GraphResult res = execute( """ + MATCH (person:Person) RETURN person.name as name, COLLECT { MATCH (person)-[r:OWNER_OF]->(a:Dog) @@ -83,13 +83,13 @@ public void whereWithCollectSubQueryTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); - } @Test public void unionWithCollectSubQueryTest() { execute( EDGE_3 ); + GraphResult res = execute( """ MATCH (person:Person) RETURN @@ -104,14 +104,13 @@ public void unionWithCollectSubQueryTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( List.of( "Andy", "Mittens" ) ) ) ); - - } @Test public void withClauseWithCollectSubQueryTest() { execute( EDGE_3 ); + GraphResult res = execute( """ MATCH (person:Person) RETURN person.name AS name, COLLECT { @@ -130,6 +129,7 @@ public void withClauseWithCollectSubQueryTest() { public void caseWithCollectSubQueryTest() { execute( EDGE_3 ); execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( """ MATCH (person:Person) RETURN @@ -141,7 +141,6 @@ public void caseWithCollectSubQueryTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "No Dogs" ) ), Row.of( TestLiteral.from( "Max" ) ) ); - } @@ -149,6 +148,7 @@ public void caseWithCollectSubQueryTest() { public void updateWithCollectSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); execute( EDGE_3 ); + GraphResult res = execute( """ MATCH (person:Person) WHERE person.name = "Hans" SET person.dogNames = COLLECT { MATCH (person)-[:OWNER_OF]->(d:Dog) RETURN d.name } @@ -158,5 +158,4 @@ public void updateWithCollectSubQueryTest() { Row.of( TestLiteral.from( List.of( "Andy" ) ) ) ); } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CountSubQueriesTest.java similarity index 99% rename from dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/subqueries/CountSubQueriesTest.java index a6c6bf800f..881c86c665 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/CountSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CountSubQueriesTest.java @@ -14,8 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Subqueries; - +package org.polypheny.db.cypher.subqueries; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,8 +22,12 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class CountSubQueriesTest extends CypherTestTemplate { + public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10})"; + + @BeforeEach public void reset() { tearDown(); @@ -32,9 +35,6 @@ public void reset() { } - public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10})"; - - @Test public void simpleCountSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); @@ -53,12 +53,12 @@ public void simpleCountSubQueryTest() { @Test public void useCountSubQueryInReturnTest() { execute( EDGE_3 ); + GraphResult res = execute( "MATCH (person:Person)\n" + "RETURN person.name, COUNT { (person)-[:OWNER_OF]->(:Dog) } as howManyDogs" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 1 ) ) ); - } @@ -66,6 +66,7 @@ public void useCountSubQueryInReturnTest() { public void whereWithCountSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); execute( EDGE_3 ); + GraphResult res = execute( """ MATCH (person:Person) WHERE COUNT { @@ -102,6 +103,7 @@ public void unionWithCountSubQueryTest() { @Test public void withClauseWithCountSubQueryTest() { execute( EDGE_3 ); + GraphResult res = execute( """ MATCH (person:Person) WHERE COUNT { @@ -113,7 +115,6 @@ public void withClauseWithCountSubQueryTest() { containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); - } @@ -128,8 +129,6 @@ public void updateWithCountSubQueryTest() { containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); - - } @@ -137,6 +136,7 @@ public void updateWithCountSubQueryTest() { public void caseWithCountSubQueryTest() { execute( EDGE_3 ); execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( """ MATCH (person:Person) RETURN @@ -144,12 +144,10 @@ public void caseWithCountSubQueryTest() { WHEN COUNT { (person)-[:OWNER_OF]->(:Dog) } >= 1 THEN "DogLover " + person.name ELSE person.name END AS result""" ); + containsRows( res, true, false, Row.of( TestLiteral.from( "DogLover" ) ), Row.of( TestLiteral.from( "Hans" ) ) ); - - } - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/ExistsSubQueriesTest.java similarity index 98% rename from dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java rename to dbms/src/test/java/org/polypheny/db/cypher/subqueries/ExistsSubQueriesTest.java index 1e700ff44f..d4db4e050a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/Subqueries/ExistsSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/ExistsSubQueriesTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.cypher.Subqueries; +package org.polypheny.db.cypher.subqueries; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,8 +22,12 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class ExistsSubQueriesTest extends CypherTestTemplate { + public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10}),(d)-[:HAS_TOY]->(:Toy{name:'Banana'})"; + + @BeforeEach public void reset() { tearDown(); @@ -31,20 +35,18 @@ public void reset() { } - public static final String EDGE_3 = "CREATE (p:Person {name :'Max'}),(p)-[rel:OWNER_OF{ since : 2002}] -> (c:Cat : Animal {name :'Mittens' , age : 3}), (p)-[rel2:OWNER_OF { since : 1999}] -> (d:Dog :Animal { name : 'Andy' , age :10}),(d)-[:HAS_TOY]->(:Toy{name:'Banana'})"; - - @Test public void simpleExistsSubQueryTest() { execute( SINGLE_NODE_PERSON_2 ); + GraphResult res = execute( """ MATCH (person:Person) WHERE EXISTS { (person)-[:OWNER_OF]->(:Dog) } RETURN person.name AS name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( null ) ) ); + execute( EDGE_3 ); execute( """ MATCH (person:Person) @@ -52,7 +54,6 @@ public void simpleExistsSubQueryTest() { (person)-[:OWNER_OF]->(:Dog) } RETURN person.name AS name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); } @@ -67,15 +68,12 @@ public void whereWithExistsSubQueryTest() { WHERE person.name = "Max"\s } RETURN dog.name AS name""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Andy" ) ) ); - } @Test public void nestedExistsSubQueryTest() { - execute( EDGE_3 ); GraphResult res = execute( """ MATCH (person:Person) @@ -89,8 +87,6 @@ public void nestedExistsSubQueryTest() { RETURN person.name AS name""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ) ) ); - - } @@ -102,7 +98,6 @@ public void returnExistsSubQueryTest() { RETURN person.name AS name, EXISTS { MATCH (person)-[:OWNER_OF]->(:Dog) } AS hasDog""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( true ) ) ); } @@ -112,7 +107,6 @@ public void returnExistsSubQueryTest() { public void unionWithExistsSubQueryTest() { execute( EDGE_3 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( """ MATCH (person:Person) RETURN @@ -143,5 +137,4 @@ public void withClauseWithExistsSubQueryTest() { Row.of( TestLiteral.from( "Max" ) ) ); } - } From 06a13f0d50e5691c7735d1970a4d83d0ca2f90eb Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Sun, 25 Aug 2024 14:58:49 +0200 Subject: [PATCH 52/55] Minor improvements --- .../org/polypheny/db/cypher/clause/general/CallTest.java | 6 +----- .../org/polypheny/db/cypher/functions/AggregateTest.java | 5 ++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java index bd1802ede2..851e14696a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CallTest.java @@ -39,8 +39,8 @@ public void simpleCallProcedureTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); - res = execute( "CALL db.labels()" ); + res = execute( "CALL db.labels()" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ) ), Row.of( TestLiteral.from( "Animal" ) ) ); @@ -105,7 +105,6 @@ public void returnFilterCallLabelsYieldTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "CALL db.labels() YIELD label WHERE label = 'Person' RETURN count(label) AS numLabels" ); - containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ) ); } @@ -117,7 +116,6 @@ public void callLabelsYieldWithOrderingTest() { execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_ANIMAL ); GraphResult res = execute( "CALL db.labels() YIELD label RETURN label ORDER BY label" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Animal" ) ), Row.of( TestLiteral.from( "Person" ) ), @@ -131,7 +129,6 @@ public void callLabelsYieldWithAggregationTest() { execute( SINGLE_NODE_ANIMAL ); execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "CALL db.labels() YIELD label RETURN label, count(*) AS labelCount" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Person" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Animal" ), TestLiteral.from( 1 ) ) ); @@ -164,7 +161,6 @@ public void renameCallPropertyKeysYieldTest() { @Test public void callPropertyKeysYieldWithMatchTest() { - execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_ANIMAL ); execute( SINGLE_NODE_PERSON_2 ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java index db4ababd1b..77041b0d59 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -150,8 +149,8 @@ public void singleAvgAggregateTest() { GraphResult res = execute( "MATCH (n) RETURN AVG(n.age)" ); // Printing the data using Arrays.deepToString - String[][] data = res.getData(); - System.out.println( Arrays.deepToString( data ) ); + //String[][] data = res.getData(); + //System.out.println( Arrays.deepToString( data ) ); containsRows( res, true, false, Row.of( TestLiteral.from( 26.33333333333333 ) ) ); } From 90706521c38311977a0cb0218984360eae4baa15 Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Sun, 25 Aug 2024 14:59:07 +0200 Subject: [PATCH 53/55] Improve cypher error messages --- .../db/algebra/enumerable/RexToLixTranslator.java | 2 +- .../db/cypher/cypher2alg/CypherToAlgConverter.java | 7 ++----- .../polypheny/db/cypher/expression/CypherExpression.java | 2 +- .../db/cypher/expression/CypherFunctionInvocation.java | 2 +- .../org/polypheny/db/cypher/expression/CypherGate.java | 2 +- .../org/polypheny/db/cypher/expression/CypherVariable.java | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/RexToLixTranslator.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/RexToLixTranslator.java index ba5c40be3c..d6a5d1599a 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/RexToLixTranslator.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/RexToLixTranslator.java @@ -522,7 +522,7 @@ private Expression translateCall( RexCall call, RexImpTable.NullAs nullAs ) { final Operator operator = call.getOperator(); CallImplementor implementor = RexImpTable.INSTANCE.get( operator ); if ( implementor == null ) { - throw new GenericRuntimeException( "cannot translate call " + call ); + throw new GenericRuntimeException( "Cannot translate call " + call ); } return implementor.implement( this, call, nullAs ); } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/cypher2alg/CypherToAlgConverter.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/cypher2alg/CypherToAlgConverter.java index 9998a9f7b3..59fe2a38d3 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/cypher2alg/CypherToAlgConverter.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/cypher2alg/CypherToAlgConverter.java @@ -159,15 +159,13 @@ private void convertQuery( CypherNode node, CypherContext context ) { switch ( node.getCypherKind() ) { case SINGLE: CypherSingleQuery query = (CypherSingleQuery) node; - for ( CypherClause clause : query.getClauses() ) { convertClauses( clause, context ); } - break; case PERIODIC_COMMIT: case UNION: - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException( "Unsupported cypher operation: " + node.getCypherKind() ); } } @@ -201,9 +199,8 @@ private void convertClauses( CypherClause clause, CypherContext context ) { convertRemove( (CypherRemove) clause, context ); break; default: - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException( "Unsupported cypher clause: " + clause.getCypherKind() ); } - } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherExpression.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherExpression.java index 63223cc2b8..bbe52323f2 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherExpression.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherExpression.java @@ -83,7 +83,7 @@ public Pair getRex( CypherContext context, RexType type ) { case ANY -> OperatorName.CYPHER_ANY_MATCH; case NONE -> OperatorName.CYPHER_NONE_MATCH; case SINGLE -> OperatorName.CYPHER_SINGLE_MATCH; - default -> throw new UnsupportedOperationException(); + default -> throw new UnsupportedOperationException( "Unsupported cypher expression: " + this.type ); }; // ANY ( Variable IN Expression(list) Where? ) diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherFunctionInvocation.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherFunctionInvocation.java index 0b2d227292..124deceb7e 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherFunctionInvocation.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherFunctionInvocation.java @@ -43,7 +43,7 @@ public CypherFunctionInvocation( ParserPos beforePos, ParserPos namePos, List getRex( CypherContext context, RexType type ) { operatorName = OperatorName.AND; break; case XOR: - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException( "Unsupported cypher operator: " + gate ); case NOT: return handleSingular( context, type, OperatorName.NOT ); } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java index 3dbb9ec047..7aba2e9154 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java @@ -81,7 +81,7 @@ public Pair getRex( CypherContext context, RexType type ) { } } - throw new GenericRuntimeException( "The used variable is not known." ); + throw new GenericRuntimeException( "Unknown variable: " + name ); } From 61d6f1a64b0202965a1f5a00743964d3c7446a5b Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Sun, 25 Aug 2024 15:21:59 +0200 Subject: [PATCH 54/55] Improve method names --- .../polypheny/db/cypher/clause/general/CaseTest.java | 2 +- .../db/cypher/clause/general/FilterTest.java | 2 +- .../db/cypher/clause/general/LimitTest.java | 2 +- .../db/cypher/clause/general/OrderByTest.java | 4 ++-- .../db/cypher/clause/general/UnionTest.java | 12 ++++++------ .../db/cypher/clause/general/UnwindTest.java | 6 +++--- .../polypheny/db/cypher/clause/general/WithTest.java | 12 ++++++------ .../polypheny/db/cypher/clause/read/MatchTest.java | 4 ++-- .../db/cypher/clause/write/DmlDeleteTest.java | 2 +- .../polypheny/db/cypher/functions/AggregateTest.java | 8 ++++---- .../polypheny/db/cypher/functions/OtherFunTest.java | 4 ++-- .../polypheny/db/cypher/functions/StringFunTest.java | 4 ++-- .../db/cypher/subqueries/CallSubqueriesTest.java | 4 ++-- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java index 7fe68ba82b..75b35bab58 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java @@ -56,7 +56,7 @@ public void simpleCaseTest() { @Test - public void GenericCaseTest() { + public void genericCaseTest() { execute( PERSON_NODE_ALICE ); execute( PERSON_NODE_BOB ); execute( PERSON_NODE_CHARLIE ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index 1229499937..e79c30f4af 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -80,7 +80,7 @@ public void relationPropertyFilterTest() { @Test - public void NodePatternFilterTest() { + public void nodePatternFilterTest() { execute( SINGLE_EDGE_2 ); GraphResult res = execute( "MATCH (a:Person WHERE a.name = 'Max')-[:KNOWS]->(b:Person WHERE b.name = 'Hans')\n" + "RETURN b.name" ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java index 31837b8f9e..8c1c91883c 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java @@ -52,7 +52,7 @@ public void simpleLimitTest() { @Test - public void InsertNodeLimitTest() { + public void insertNodeLimitTest() { GraphResult res = execute( """ CREATE (n:person) RETURN n diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java index b4c3d1ca86..5e4e450089 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/OrderByTest.java @@ -184,7 +184,7 @@ public void renameWithClauseDoubleOrderByWithLimitTest() { @Test - public void UnwindSortTest() { + public void unwindSortTest() { GraphResult res = execute( "UNWIND [1, true,3.14] AS i RETURN i ORDER BY i" ); containsRows( res, true, true, Row.of( TestLiteral.from( true ) ), @@ -214,7 +214,7 @@ public void renameWithMixedTypesWithUnwindSortTest() { @Test - public void AvgAggregateFieldSortTest() { + public void avgAggregateFieldSortTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java index 5b30eae878..08026a124d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnionTest.java @@ -54,7 +54,7 @@ public void simpleUnionTest() { @Test - public void DifferentStructureUnionTest() { + public void differentStructureUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_MOVIE ); @@ -74,7 +74,7 @@ public void DifferentStructureUnionTest() { @Test - public void NullPropertiesUnionTest() { + public void nullPropertiesUnionTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_MOVIE ); @@ -116,7 +116,7 @@ public void allUnionTest() { @Test - public void DifferentStructureAllUnionTest() { + public void differentStructureAllUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_MOVIE ); execute( SINGLE_NODE_PERSON_1 ); @@ -139,7 +139,7 @@ public void DifferentStructureAllUnionTest() { @Test - public void NullPropertiesAllUnionTest() { + public void nullPropertiesAllUnionTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_MOVIE ); @@ -182,7 +182,7 @@ public void distinctUnionTest() { @Test - public void DifferentStructureDistinctUnionTest() { + public void differentStructureDistinctUnionTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_MOVIE ); @@ -202,7 +202,7 @@ public void DifferentStructureDistinctUnionTest() { @Test - public void NullPropertiesDistinctUnionTest() { + public void nullPropertiesDistinctUnionTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_MOVIE ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java index df83bfdcfa..5e8a318035 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java @@ -106,7 +106,7 @@ public void sumAggregateNodePropertyUnWind() { @Test - public void AvgAggregateNodePropertyUnWind() { + public void avgAggregateNodePropertyUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); @@ -115,7 +115,7 @@ public void AvgAggregateNodePropertyUnWind() { @Test - public void CollectAggregateUnWind() { + public void collectAggregateUnWind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); @@ -142,7 +142,7 @@ public void distinctUnWind() { @Test - public void ConditionalLogicUnWind() { + public void conditionalLogicUnWind() { GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); containsRows( res, true, true, Row.of( TestLiteral.from( 1 ), TestLiteral.from( "odd" ) ), diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java index d9a865423c..8b06c7a900 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java @@ -166,7 +166,7 @@ public void countAggregationWithTest() { @Test - public void stDevAggregationWithTest() { + public void stdevAggregationWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); @@ -229,7 +229,7 @@ public void listWithTest() { @Test - public void unWindListWithTest() { + public void unwindListWithTest() { GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number RETURN number" ); containsRows( res, true, false, Row.of( TestLiteral.from( 1 ) ), @@ -241,7 +241,7 @@ public void unWindListWithTest() { @Test - public void unWindAndFilterListWithTest() { + public void unwindAndFilterListWithTest() { GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number WITH number WHERE number > 3 RETURN number" ); containsRows( res, true, false, Row.of( TestLiteral.from( 4 ) ), @@ -250,14 +250,14 @@ public void unWindAndFilterListWithTest() { @Test - public void unWindAndStartListWithTest() { + public void unwindAndStartListWithTest() { GraphResult res = execute( "WITH ['John', 'Mark', 'Jonathan', 'Bill'] AS somenames UNWIND somenames AS names WITH names AS candidate WHERE candidate STARTS WITH 'Jo' RETURN candidate" ); containsRows( res, true, false, Row.of( TestLiteral.from( "John" ) ), Row.of( TestLiteral.from( "Jonathan" ) ) ); } @Test - public void unWindAndLogicalOperatorsListWithTest() { + public void unwindAndLogicalOperatorsListWithTest() { GraphResult res = execute( "WITH [2, 4, 7, 9, 12] AS numberlist UNWIND numberlist AS number WITH number WHERE number = 4 OR (number > 6 AND number < 10) RETURN number" ); assertTrue( containsRows( res, false, false, Row.of( TestLiteral.from( 4 ) ), @@ -267,7 +267,7 @@ public void unWindAndLogicalOperatorsListWithTest() { @Test - public void unWindAndWhereInListWithTest() { + public void unwindAndWhereInListWithTest() { GraphResult res = execute( "WITH [2, 3, 4, 5] AS numberlist UNWIND numberlist AS number WITH number WHERE number IN [2, 3, 8] RETURN number" ); containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 3 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java index 835d4aedf8..f5cb276fa9 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java @@ -82,7 +82,7 @@ public void simpleMatchSinglePropertyTest() { GraphResult res = execute( "MATCH (n {name: 'Max'}) RETURN n" ); assertNode( res, 0 ); - containsNodes( res, true, HANS ); + assertEmpty( res ); res = execute( "MATCH (n {name: 'Hans'}) RETURN n" ); assertNode( res, 0 ); @@ -114,7 +114,7 @@ public void simpleMatchMultiplePropertyTest() { /////////////////////////////////////////////// @Test - public void NoLabelPropertyTest() { + public void noLabelPropertyTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); GraphResult res = execute( "MATCH (n) RETURN n.age" ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java index ed10b96588..24eeb77063 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java @@ -133,7 +133,7 @@ public void pathDeleteTest() { @Test - public void NodeWithAllRelationshipsDeleteTest() { + public void nodeWithAllRelationshipsDeleteTest() { execute( SINGLE_EDGE_2 ); execute( "MATCH (n:Person {name: 'MAX'})\n" + "DETACH DELETE n" ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java index 77041b0d59..659b76e56a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/AggregateTest.java @@ -350,7 +350,7 @@ public void sumRenameFieldAggregationTest() { @Test - public void singleStDevAggregateTest() { + public void singleStdevAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); @@ -361,7 +361,7 @@ public void singleStDevAggregateTest() { @Test - public void stDevNullAggregateTest() { + public void stdevNullAggregateTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); @@ -372,7 +372,7 @@ public void stDevNullAggregateTest() { @Test - public void stDevRenameAggregateTest() { + public void stdevRenameAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); @@ -383,7 +383,7 @@ public void stDevRenameAggregateTest() { @Test - public void stDevRenameFieldAggregateTest() { + public void stdevRenameFieldAggregateTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/functions/OtherFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/OtherFunTest.java index 9cc0990f55..218176a141 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/functions/OtherFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/OtherFunTest.java @@ -73,7 +73,7 @@ public void testCoalesceFunTest() { @Test - public void testDefaultValuesWithCoalesceFunTest() { + public void defaultValuesWithCoalesceFunTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); @@ -93,7 +93,7 @@ public void testDefaultValuesWithCoalesceFunTest() { @Test - public void ExistFunTest() { + public void existFunTest() { execute( SINGLE_NODE_PERSON_1 ); GraphResult res = execute( """ diff --git a/dbms/src/test/java/org/polypheny/db/cypher/functions/StringFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/StringFunTest.java index 6331e559fc..3d559e4599 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/functions/StringFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/StringFunTest.java @@ -42,7 +42,7 @@ public void upperFunTest() { @Test - public void EmptyUpperFunTest() { + public void emptyUpperFunTest() { GraphResult res = execute( "RETURN UPPER('')" ); containsRows( res, true, true, Row.of( TestLiteral.from( "" ) ) ); } @@ -56,7 +56,7 @@ public void nullUpperFunTest() { @Test - public void LowerFunTest() { + public void lowerFunTest() { GraphResult res = execute( "RETURN LOWER('WORLD')" ); containsRows( res, true, true, Row.of( TestLiteral.from( "world" ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java index 5796e0aefe..84994b4cb8 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java @@ -135,7 +135,7 @@ public void useMatchedNodesAsInputsIntoCallTest() { @Test - public void FilterMatchedNodesByOutputOfCallTest() { + public void filterMatchedNodesByOutputOfCallTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); @@ -157,7 +157,7 @@ public void FilterMatchedNodesByOutputOfCallTest() { @Test - public void UnionCallTest() { + public void unionCallTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); From dcd50e03df9e6eee7b56a82301499bd9a7eb986d Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Sun, 25 Aug 2024 15:47:48 +0200 Subject: [PATCH 55/55] Small improvements --- .../java/org/polypheny/db/cypher/DdlTest.java | 3 - .../db/cypher/clause/general/CaseTest.java | 5 +- .../db/cypher/clause/general/FilterTest.java | 3 +- .../db/cypher/clause/general/LimitTest.java | 1 - .../db/cypher/clause/general/UnwindTest.java | 35 ++++++++--- .../db/cypher/clause/general/WithTest.java | 62 ++++++++++++++----- .../db/cypher/clause/read/MatchTest.java | 14 +++-- .../db/cypher/clause/write/DmlDeleteTest.java | 25 +++----- .../db/cypher/clause/write/ForeachTest.java | 1 + .../db/cypher/clause/write/MergeTest.java | 1 + .../db/cypher/functions/NumericFunTest.java | 1 + .../polypheny/db/cypher/helper/TestNode.java | 1 + .../operators/BooleanOperatorsTest.java | 2 +- .../cypher/subqueries/CallSubqueriesTest.java | 11 ++-- .../subqueries/CollectSubQueriesTest.java | 4 +- .../subqueries/CountSubQueriesTest.java | 3 +- 16 files changed, 104 insertions(+), 68 deletions(-) diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java b/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java index dbec2903ed..528f0c12ad 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java @@ -96,7 +96,6 @@ public void addPlacementTest() throws SQLException { execute( "DROP DATABASE " + graphName ); } finally { - removeStore( "store1" ); } } @@ -203,9 +202,7 @@ private void removeStore( String name ) throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); try ( Statement statement = connection.createStatement() ) { - statement.executeUpdate( String.format( "ALTER ADAPTERS DROP \"%s\"", name ) ); - } } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java index 75b35bab58..075c2a8137 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/CaseTest.java @@ -51,7 +51,10 @@ public void simpleCaseTest() { ELSE 3 END AS result, n.eyes""" ); - containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); + containsRows( res, true, false, + Row.of( TestLiteral.from( "Alice" ), TestLiteral.from( 2 ) ), + Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( 1 ) ), + Row.of( TestLiteral.from( "Charlie" ), TestLiteral.from( 3 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java index e79c30f4af..9146c9aa08 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/FilterTest.java @@ -315,11 +315,10 @@ public void missingPropertyFilterTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( """ MATCH (n:Person) - WHERE n.age >= 40\s + WHERE n.age >= 40 RETURN n.name, n.age""" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); - } } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java index 8c1c91883c..4c3753acf2 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/LimitTest.java @@ -107,7 +107,6 @@ public void orderByLimitTest() { Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Max" ) ), Row.of( TestLiteral.from( "Kira" ) ) ); - } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java index 5e8a318035..8a04f4a22f 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/UnwindTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.polypheny.db.cypher.clause.general; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,6 +25,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class UnwindTest extends CypherTestTemplate { @BeforeEach @@ -64,7 +81,7 @@ public void nodePropertyUnwind() { @Test - public void minMaxAggregateSimpleUnWind() { + public void minMaxAggregateSimpleUnwind() { GraphResult res = execute( "UNWIND [1, 'a', NULL, 0.2, 'b', '1', '99'] AS val RETURN min(val)" ); containsRows( res, true, false, Row.of( TestLiteral.from( '1' ) ) ); @@ -84,7 +101,7 @@ public void minMaxAggregateListOfListUnwind() { @Test - public void maxMinAggregateNodePropertyUnWind() { + public void maxMinAggregateNodePropertyUnwind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); @@ -97,7 +114,7 @@ public void maxMinAggregateNodePropertyUnWind() { @Test - public void sumAggregateNodePropertyUnWind() { + public void sumAggregateNodePropertyUnwind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN sum(age)" ); @@ -106,7 +123,7 @@ public void sumAggregateNodePropertyUnWind() { @Test - public void avgAggregateNodePropertyUnWind() { + public void avgAggregateNodePropertyUnwind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN avg(age)" ); @@ -115,7 +132,7 @@ public void avgAggregateNodePropertyUnWind() { @Test - public void collectAggregateUnWind() { + public void collectAggregateUnwind() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_COMPLEX_2 ); GraphResult res = execute( "MATCH (n) UNWIND n.age AS age RETURN Collect(age)" ); @@ -124,7 +141,7 @@ public void collectAggregateUnWind() { @Test - public void countUnWind() { + public void countUnwind() { GraphResult res = execute( "UNWIND [2, 1 , 1] AS i RETURN count( i)" ); containsRows( res, true, false, Row.of( TestLiteral.from( 3 ) ) ); @@ -132,7 +149,7 @@ public void countUnWind() { @Test - public void distinctUnWind() { + public void distinctUnwind() { GraphResult res = execute( "UNWIND [3, 3 ,2 ,1 ] AS i RETURN DISTINCT i" ); assertEquals( 3, res.getData().length ); containsRows( res, true, false, @@ -142,7 +159,7 @@ public void distinctUnWind() { @Test - public void conditionalLogicUnWind() { + public void conditionalLogicUnwind() { GraphResult res = execute( "UNWIND [1, 2, 3] AS number RETURN number, CASE WHEN number % 2 = 0 THEN 'even' ELSE 'odd' END AS type" ); containsRows( res, true, true, Row.of( TestLiteral.from( 1 ), TestLiteral.from( "odd" ) ), @@ -152,7 +169,7 @@ public void conditionalLogicUnWind() { @Test - public void mapStructureUnWind() { + public void mapStructureUnwind() { GraphResult res = execute( "UNWIND [{name: 'Alice', age: 30}] AS person RETURN person.name , person.age" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Alice" ) ), Row.of( TestLiteral.from( 30 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java index 8b06c7a900..d3b498d801 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/general/WithTest.java @@ -66,7 +66,7 @@ public void renameWithTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person) WITH n.name AS name, n RETURN name, n" ); - containsRows( res, true, true, + containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), MAX ), Row.of( TestLiteral.from( "Hans" ), HANS ) ); } @@ -78,8 +78,7 @@ public void startWithTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( "MATCH (n:Person) WITH n.name, n WHERE n.name STARTS WITH 'H' RETURN n" ); - containsRows( res, true, true, - Row.of( HANS ) ); + containsRows( res, true, true, Row.of( HANS ) ); } @@ -90,8 +89,7 @@ public void startRenameWithTest() { GraphResult res = execute( "MATCH (n:Person) WITH n.name as name , n WHERE name STARTS WITH 'H' RETURN n" ); assertNode( res, 0 ); - containsRows( res, true, true, - Row.of( HANS ) ); + containsRows( res, true, true, Row.of( HANS ) ); } @@ -100,7 +98,10 @@ public void endWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n:Person) WITH n.name , n WHERE n.name ENDS WITH 'x' RETURN name, n" ); + GraphResult res = execute( "MATCH (n:Person) " + + "WITH n.name, n " + + "WHERE n.name ENDS WITH 'x' " + + "RETURN n.name, n" ); assertNode( res, 1 ); containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); } @@ -111,7 +112,10 @@ public void endRenameWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (n:Person) WITH n.name AS name, n WHERE name ENDS WITH 'x' RETURN name, n" ); + GraphResult res = execute( "MATCH (n:Person) " + + "WITH n.name AS name, n " + + "WHERE name ENDS WITH 'x' " + + "RETURN name, n" ); assertNode( res, 1 ); containsRows( res, true, true, Row.of( TestLiteral.from( "Max" ), MAX ) ); } @@ -172,7 +176,6 @@ public void stdevAggregationWithTest() { GraphResult res = execute( "MATCH (p:Person) WITH STDEV(p.age) as ageStdev RETURN ageStdev " ); containsRows( res, true, true, Row.of( TestLiteral.from( 9.8994949 ) ) ); - } @@ -183,7 +186,6 @@ public void collectAggregationWithTest() { GraphResult res = execute( "MATCH (p:Person) WITH COLLECT(p.age) as ageList RETURN ageList " ); containsRows( res, true, true, Row.of( TestLiteral.from( 45 ), TestLiteral.from( 31 ) ) ); - } @@ -242,7 +244,11 @@ public void unwindListWithTest() { @Test public void unwindAndFilterListWithTest() { - GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers UNWIND numbers AS number WITH number WHERE number > 3 RETURN number" ); + GraphResult res = execute( "WITH [1, 2, 3, 4, 5] AS numbers " + + "UNWIND numbers AS number " + + "WITH number " + + "WHERE number > 3 " + + "RETURN number" ); containsRows( res, true, false, Row.of( TestLiteral.from( 4 ) ), Row.of( TestLiteral.from( 5 ) ) ); @@ -251,14 +257,22 @@ public void unwindAndFilterListWithTest() { @Test public void unwindAndStartListWithTest() { - GraphResult res = execute( "WITH ['John', 'Mark', 'Jonathan', 'Bill'] AS somenames UNWIND somenames AS names WITH names AS candidate WHERE candidate STARTS WITH 'Jo' RETURN candidate" ); + GraphResult res = execute( "WITH ['John', 'Mark', 'Jonathan', 'Bill'] AS somenames " + + "UNWIND somenames AS names " + + "WITH names AS candidate " + + "WHERE candidate STARTS WITH 'Jo' " + + "RETURN candidate" ); containsRows( res, true, false, Row.of( TestLiteral.from( "John" ) ), Row.of( TestLiteral.from( "Jonathan" ) ) ); } @Test public void unwindAndLogicalOperatorsListWithTest() { - GraphResult res = execute( "WITH [2, 4, 7, 9, 12] AS numberlist UNWIND numberlist AS number WITH number WHERE number = 4 OR (number > 6 AND number < 10) RETURN number" ); + GraphResult res = execute( "WITH [2, 4, 7, 9, 12] AS numberlist " + + "UNWIND numberlist AS number " + + "WITH number " + + "WHERE number = 4 OR (number > 6 AND number < 10) " + + "RETURN number" ); assertTrue( containsRows( res, false, false, Row.of( TestLiteral.from( 4 ) ), Row.of( TestLiteral.from( 7 ) ), @@ -268,7 +282,11 @@ public void unwindAndLogicalOperatorsListWithTest() { @Test public void unwindAndWhereInListWithTest() { - GraphResult res = execute( "WITH [2, 3, 4, 5] AS numberlist UNWIND numberlist AS number WITH number WHERE number IN [2, 3, 8] RETURN number" ); + GraphResult res = execute( "WITH [2, 3, 4, 5] AS numberlist " + + "UNWIND numberlist AS number " + + "WITH number " + + "WHERE number IN [2, 3, 8] " + + "RETURN number" ); containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ), Row.of( TestLiteral.from( 3 ) ) ); } @@ -287,7 +305,7 @@ public void distinctWithTest() { execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (p:Person) WITH Distinct(p) Return p " ); + GraphResult res = execute( "MATCH (p:Person) WITH Distinct(p) Return p " ); assertEquals( 2, res.getData().length ); } @@ -297,7 +315,7 @@ public void existsWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_1 ); execute( SINGLE_NODE_PERSON_1 ); - GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age;" ); + GraphResult res = execute( "MATCH (n) WITH n as person WHERE EXISTS(person.age) RETURN person.name, person.age" ); containsRows( res, true, true, Row.of( TestLiteral.from( "Ann" ), TestLiteral.from( 45 ) ) ); } @@ -308,7 +326,14 @@ public void conditionalLogicWithTest() { execute( SINGLE_NODE_PERSON_COMPLEX_2 ); execute( SINGLE_NODE_PERSON_COMPLEX_3 ); - GraphResult res = execute( "MATCH (p:Person) WITH p, CASE WHEN p.age < 30 THEN 'Young' THEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' ELSE 'Elderly END AS ageGroup RETURN p.name, ageGroup;" ); + GraphResult res = execute( "MATCH (p:Person) " + + "WITH p, " + + " CASE " + + " WHEN p.age < 30 THEN 'Young'" + + " WHEN p.age >= 30 AND p.age < 60 THEN 'Middle-aged' " + + " ELSE 'Elderly' " + + " END AS ageGroup " + + "RETURN p.name, ageGroup" ); containsRows( res, true, true, Row.of( TestLiteral.from( "Ana" ), TestLiteral.from( "Middle-aged" ) ), Row.of( TestLiteral.from( "Bob" ), TestLiteral.from( "Middle-aged" ) ), @@ -321,7 +346,10 @@ public void orderByWithTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - GraphResult res = execute( "MATCH (p:Person) WITH p ORDER BY p.name ASC RETURN p.name" ); + GraphResult res = execute( "MATCH (p:Person) " + + "WITH p " + + "ORDER BY p.name ASC " + + "RETURN p.name" ); containsRows( res, true, true, Row.of( TestLiteral.from( "Hans" ) ), Row.of( TestLiteral.from( "Max" ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java index f5cb276fa9..e45fb797f7 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/read/MatchTest.java @@ -82,7 +82,7 @@ public void simpleMatchSinglePropertyTest() { GraphResult res = execute( "MATCH (n {name: 'Max'}) RETURN n" ); assertNode( res, 0 ); - assertEmpty( res ); + containsNodes( res, true, MAX ); res = execute( "MATCH (n {name: 'Hans'}) RETURN n" ); assertNode( res, 0 ); @@ -402,8 +402,10 @@ public void returnAllElementsByAsteriskMatchTest() { execute( SINGLE_EDGE_1 ); GraphResult res = execute( "MATCH Path = (p) -[r] ->(m) RETURN *" ); containsRows( res, true, false, - Row.of( TestPath.of( MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) - , MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ); + Row.of( + TestPath.of( MAX, TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ), + MAX, + TestEdge.from( List.of( "OWNER_OF" ) ), KIRA ) ); } @@ -418,9 +420,9 @@ public void returnEdgesByAsteriskMatchTest() { @Test public void shortestPathMatchTest() { execute( SINGLE_EDGE_1 ); - GraphResult res = execute( "MATCH (b:Person {name: 'Max'}), (a:Animal {name: 'Kira'})\n" - + "MATCH p = shortestPath((b)-[*]-(a))\n" - + "RETURN p\n" ); + GraphResult res = execute( "MATCH (b:Person {name: 'Max'}), (a:Animal {name: 'Kira'}) " + + "MATCH p = shortestPath((b)-[*]-(a)) " + + "RETURN p" ); containsRows( res, true, true, Row.of( TestPath.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Max" ) ), diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java index 24eeb77063..32afe474fd 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/DmlDeleteTest.java @@ -39,8 +39,7 @@ public void reset() { @Test public void simpleEmptyNodeDeleteTest() { execute( SINGLE_NODE_PERSON_1 ); - execute( "MATCH (p:Person)\n" - + "DELETE p" ); + execute( "MATCH (p:Person) DELETE p" ); GraphResult res = matchAndReturnAllNodes(); assertEmpty( res ); } @@ -49,8 +48,7 @@ public void simpleEmptyNodeDeleteTest() { @Test public void simpleNodeDeleteTest() { execute( SINGLE_NODE_PERSON_1 ); - execute( "MATCH (p:Person {name: 'Max'})\n" - + "DELETE p" ); + execute( "MATCH (p:Person {name: 'Max'}) DELETE p" ); GraphResult res = matchAndReturnAllNodes(); assertEmpty( res ); } @@ -60,8 +58,7 @@ public void simpleNodeDeleteTest() { public void simpleFilteredNodeDeleteTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); - execute( "MATCH (p:Person {name: 'Max'})\n" - + "DELETE p" ); + execute( "MATCH (p:Person {name: 'Max'}) DELETE p" ); GraphResult res = matchAndReturnAllNodes(); containsRows( res, true, false, Row.of( TestNode.from( List.of( "Person" ), Pair.of( "name", "Hans" ) ) ) ); @@ -84,8 +81,7 @@ public void simpleRelationshipDeleteTest() { execute( "MATCH (:Person {name: 'Max'})-[rel:OWNER_OF]->(:Animal {name: 'Kira'}) \n" + "DELETE rel" ); - GraphResult res = execute( "MATCH (n)-[rel:OWNER_OF]->(a) \n" - + "RETURN rel" ); + GraphResult res = execute( "MATCH (n)-[rel:OWNER_OF]->(a) RETURN rel" ); assertEmpty( res ); res = matchAndReturnAllNodes(); @@ -102,7 +98,7 @@ public void simpleRelationshipDeleteTest() { @Test public void relationshipWithPropertiesDeleteTest() { execute( SINGLE_EDGE_2 ); - execute( "MATCH (:Person {name: 'Max'})-[rel:KNOWS {since: 1994}]->(:Person {name:'Hans'}) \n" + execute( "MATCH (:Person {name: 'Max'})-[rel:KNOWS {since: 1994}]->(:Person {name:'Hans'})\n" + "DELETE rel" ); GraphResult res = execute( "MATCH (p1)-[rel:KNOWS ]->(p2) RETURN rel " ); @@ -121,10 +117,7 @@ public void relationshipWithPropertiesDeleteTest() { @Test public void pathDeleteTest() { execute( SINGLE_EDGE_1 ); - execute( """ - MATCH p = (person:Person {name: 'Max'})-[rel:OWNER_OF]->( animal :Animal {name: 'Kira'}) - DELETE p - """ ); + execute( "MATCH p = (person:Person {name: 'Max'})-[rel:OWNER_OF]->( animal :Animal {name: 'Kira'}) DELETE p" ); GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) RETURN rel " ); @@ -135,8 +128,7 @@ public void pathDeleteTest() { @Test public void nodeWithAllRelationshipsDeleteTest() { execute( SINGLE_EDGE_2 ); - execute( "MATCH (n:Person {name: 'MAX'})\n" - + "DETACH DELETE n" ); + execute( "MATCH (n:Person {name: 'MAX'}) DETACH DELETE n" ); GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) Return rel" ); @@ -149,8 +141,7 @@ public void allNodesAndRelationshipsDeleteTest() { execute( SINGLE_NODE_PERSON_1 ); execute( SINGLE_NODE_PERSON_2 ); execute( SINGLE_EDGE_1 ); - execute( "MATCH (n)\n" - + "DETACH DELETE n" ); + execute( "MATCH (n) DETACH DELETE n" ); GraphResult res = matchAndReturnAllNodes(); GraphResult relations = execute( "MATCH (p:Person) -[rel:OWNER_OF]->(A:Animal) Return rel" ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java index 980b4f35b6..11e95a38e1 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/ForeachTest.java @@ -27,6 +27,7 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; + public class ForeachTest extends CypherTestTemplate { @BeforeEach diff --git a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java index 46b3f50fa1..1261e4462a 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/clause/write/MergeTest.java @@ -30,6 +30,7 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.webui.models.results.GraphResult; + @Slf4j public class MergeTest extends CypherTestTemplate { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/functions/NumericFunTest.java b/dbms/src/test/java/org/polypheny/db/cypher/functions/NumericFunTest.java index 801703a73f..c7c133420e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/functions/NumericFunTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/functions/NumericFunTest.java @@ -22,6 +22,7 @@ import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class NumericFunTest extends CypherTestTemplate { @BeforeEach diff --git a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestNode.java b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestNode.java index cd8e556e6e..092dc878f8 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/helper/TestNode.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/helper/TestNode.java @@ -24,6 +24,7 @@ import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.util.Pair; + public class TestNode extends TestGraphObject { public TestNode( @Nullable String id, @Nullable Map properties, @Nullable List labels ) { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/operators/BooleanOperatorsTest.java b/dbms/src/test/java/org/polypheny/db/cypher/operators/BooleanOperatorsTest.java index ddf077e559..95aa2d70db 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/operators/BooleanOperatorsTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/operators/BooleanOperatorsTest.java @@ -16,13 +16,13 @@ package org.polypheny.db.cypher.operators; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.polypheny.db.cypher.CypherTestTemplate; import org.polypheny.db.cypher.helper.TestLiteral; import org.polypheny.db.webui.models.results.GraphResult; + public class BooleanOperatorsTest extends CypherTestTemplate { @BeforeEach diff --git a/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java index 84994b4cb8..9a0131fb60 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CallSubqueriesTest.java @@ -40,8 +40,7 @@ public void reset() { @Test public void simpleCallTest() { - GraphResult res = execute( " CALL { RETURN 'hello' AS innerReturn} \n" - + "RETURN innerReturn" ); + GraphResult res = execute( " CALL { RETURN 'hello' AS innerReturn} RETURN innerReturn" ); containsRows( res, true, false, Row.of( TestLiteral.from( "hello" ) ) ); @@ -183,12 +182,12 @@ public void unitSubQueryCallTest() { execute( SINGLE_NODE_PERSON_2 ); GraphResult res = execute( """ - MATCH (p:Person) CALL { \s - WITH p - CREATE (:Person {name: p.name})\s + MATCH (p:Person) CALL { + WITH p + CREATE (:Person {name: p.name}) } RETURN count(*)""" ); - //the number of rows present after the subquery is the same as was going into the subquery + // The number of rows present after the subquery is the same as was going into the subquery containsRows( res, true, false, Row.of( TestLiteral.from( 2 ) ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CollectSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CollectSubQueriesTest.java index c102cc61c9..640739c5c0 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CollectSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CollectSubQueriesTest.java @@ -72,14 +72,12 @@ public void whereWithCollectSubQueryTest() { execute( EDGE_3 ); GraphResult res = execute( """ - MATCH (person:Person) RETURN person.name as name, COLLECT { MATCH (person)-[r:OWNER_OF]->(a:Dog) WHERE a.age <= 3 RETURN a.name - } as youngDog\s - """ ); + } as youngDog """ ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( "Andy" ) ) ); diff --git a/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CountSubQueriesTest.java b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CountSubQueriesTest.java index 881c86c665..8902b55f8d 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CountSubQueriesTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/subqueries/CountSubQueriesTest.java @@ -54,8 +54,7 @@ public void simpleCountSubQueryTest() { public void useCountSubQueryInReturnTest() { execute( EDGE_3 ); - GraphResult res = execute( "MATCH (person:Person)\n" - + "RETURN person.name, COUNT { (person)-[:OWNER_OF]->(:Dog) } as howManyDogs" ); + GraphResult res = execute( "MATCH (person:Person) RETURN person.name, COUNT { (person)-[:OWNER_OF]->(:Dog) } as howManyDogs" ); containsRows( res, true, false, Row.of( TestLiteral.from( "Max" ), TestLiteral.from( 1 ) ) );