Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Aug 25, 2024
1 parent 61d6f1a commit dcd50e0
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 68 deletions.
3 changes: 0 additions & 3 deletions dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void addPlacementTest() throws SQLException {
execute( "DROP DATABASE " + graphName );

} finally {

removeStore( "store1" );
}
}
Expand Down Expand Up @@ -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 ) );

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public void orderByLimitTest() {
Row.of( TestLiteral.from( "Max" ) ),
Row.of( TestLiteral.from( "Max" ) ),
Row.of( TestLiteral.from( "Kira" ) ) );

}


Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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' ) ) );

Expand All @@ -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 );

Expand All @@ -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)" );
Expand All @@ -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)" );
Expand All @@ -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)" );
Expand All @@ -124,15 +141,15 @@ 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 ) ) );
}


@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,
Expand All @@ -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" ) ),
Expand All @@ -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 ) ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
Expand All @@ -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 ) );
}


Expand All @@ -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 ) );
}


Expand All @@ -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 ) );
}
Expand All @@ -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 ) );
}
Expand Down Expand Up @@ -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 ) ) );

}


Expand All @@ -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 ) ) );

}


Expand Down Expand Up @@ -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 ) ) );
Expand All @@ -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 ) ),
Expand All @@ -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 ) ) );
}

Expand All @@ -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 );
}

Expand All @@ -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 ) ) );
}

Expand All @@ -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" ) ),
Expand All @@ -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" ) ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) );
}


Expand All @@ -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" ) ),
Expand Down
Loading

0 comments on commit dcd50e0

Please sign in to comment.