/** * @see DATAGRAPH-629 */ @Test public void testFindByNestedPropertyOutgoing() { Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam), 1).getStatement()).isEqualTo( "MATCH (n:`Asteroid`) MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name_0` } MATCH (n)-[:`COLLIDES`]->(m0) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @see DATAGRAPH-629 */ @Test public void testFindByNestedPropertyIncoming() { Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("INCOMING"); assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam), 1).getStatement()).isEqualTo( "MATCH (n:`Asteroid`) MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name_0` } MATCH (n)<-[:`COLLIDES`]-(m0) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @see DATAGRAPH-904 */ @Test public void testFindByNestedPropertySameEntityType() { Filter filter = new Filter("name", ComparisonOperator.EQUALS, "Vesta"); filter.setNestedPropertyName("collidesWith"); filter.setNestedEntityTypeLabel("Asteroid"); filter.setRelationshipType("COLLIDES"); filter.setRelationshipDirection("OUTGOING"); assertThat(queryStatements.findByType("Asteroid", new Filters().add(filter), 1).getStatement()).isEqualTo( "MATCH (n:`Asteroid`) MATCH (m0:`Asteroid`) WHERE m0.`name` = { `collidesWith_name_0` } MATCH (n)-[:`COLLIDES`]->(m0) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @see DATAGRAPH-629 */ @Test public void testFindByNestedPropertyUndirected() { Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("UNDIRECTED"); assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam), 1).getStatement()).isEqualTo( "MATCH (n:`Asteroid`) MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name_0` } MATCH (n)-[:`COLLIDES`]-(m0) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @throws Exception * @see DATAGRAPH-632 */ @Test public void testFindByNestedPropertyOutgoing() throws Exception { Filter planetFilter = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetFilter.setNestedPropertyName("world"); planetFilter.setNestedEntityTypeLabel("Planet"); planetFilter.setRelationshipType("ORBITS"); planetFilter.setRelationshipDirection("OUTGOING"); assertThat(query.findByType("ORBITS", new Filters().add(planetFilter), 4).getStatement()) .isEqualTo("MATCH (n:`Planet`) WHERE n.`name` = { `world_name_0` } " + "MATCH (n)-[r0:`ORBITS`]->(m) WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m " + "MATCH p1 = (n)-[*0..4]-() WITH r0, COLLECT(DISTINCT p1) AS startPaths, m " + "MATCH p2 = (m)-[*0..4]-() WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths AS paths " + "UNWIND paths AS p RETURN DISTINCT p, ID(r0)"); }
/** * @throws Exception * @see DATAGRAPH-632 */ @Test public void testFindByNestedPropertyIncoming() throws Exception { Filter planetFilter = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetFilter.setNestedPropertyName("world"); planetFilter.setNestedEntityTypeLabel("Planet"); planetFilter.setRelationshipType("ORBITS"); planetFilter.setRelationshipDirection("INCOMING"); assertThat(query.findByType("ORBITS", new Filters().add(planetFilter), 4).getStatement()) .isEqualTo("MATCH (m:`Planet`) WHERE m.`name` = { `world_name_0` } MATCH (n)-[r0:`ORBITS`]->(m) " + "WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m MATCH p1 = (n)-[*0..4]-() " + "WITH r0, COLLECT(DISTINCT p1) AS startPaths, m " + "MATCH p2 = (m)-[*0..4]-() WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths AS paths UNWIND paths AS p RETURN DISTINCT p, ID(r0)"); }
/** * @see DATAGRAPH-445 */ @Test public void testFindByChainedAndedProperties() { Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); Filter moonParam = new Filter("name", ComparisonOperator.EQUALS, "Moon"); moonParam.setNestedPropertyName("moon"); moonParam.setNestedEntityTypeLabel("Moon"); moonParam.setRelationshipType("ORBITS"); moonParam.setRelationshipDirection("INCOMING"); assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam).and(moonParam), 1).getStatement()) .isEqualTo("MATCH (n:`Asteroid`) MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name_0` } " + "MATCH (m1:`Moon`) WHERE m1.`name` = { `moon_name_1` } MATCH (n)-[:`COLLIDES`]->(m0) " + "MATCH (n)<-[:`ORBITS`]-(m1) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @throws Exception * @see DATAGRAPH-632 */ @Test public void testFindByMultipleNestedPropertiesOnBothEnds() throws Exception { Filter moonFilter = new Filter("name", ComparisonOperator.EQUALS, "Earth"); moonFilter.setNestedPropertyName("world"); moonFilter.setNestedEntityTypeLabel("Moon"); moonFilter.setRelationshipType("ORBITS"); moonFilter.setRelationshipDirection("OUTGOING"); Filter planetFilter = new Filter("colour", ComparisonOperator.EQUALS, "Red"); planetFilter.setNestedPropertyName("colour"); planetFilter.setNestedEntityTypeLabel("Planet"); planetFilter.setRelationshipType("ORBITS"); planetFilter.setRelationshipDirection("INCOMING"); assertThat(query.findByType("ORBITS", new Filters().add(moonFilter, planetFilter), 4).getStatement()).isEqualTo( "MATCH (n:`Moon`) WHERE n.`name` = { `world_name_0` } MATCH (m:`Planet`) WHERE m.`colour` = { `colour_colour_1` } " + "MATCH (n)-[r0:`ORBITS`]->(m) WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m " + "MATCH p1 = (n)-[*0..4]-() WITH r0, COLLECT(DISTINCT p1) AS startPaths, m " + "MATCH p2 = (m)-[*0..4]-() WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths AS paths UNWIND paths AS p RETURN DISTINCT p, ID(r0)"); }
/** * @see DATAGRAPH-629 */ @Test public void testFindByMultipleNestedPropertiesAnded() { Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); Filter moonParam = new Filter("size", ComparisonOperator.EQUALS, "5"); moonParam.setNestedPropertyName("collidesWith"); moonParam.setNestedEntityTypeLabel("Planet"); moonParam.setRelationshipType("COLLIDES"); moonParam.setRelationshipDirection("OUTGOING"); moonParam.setBooleanOperator(BooleanOperator.AND); assertThat( queryStatements.findByType("Asteroid", new Filters().add(planetParam).add(moonParam), 1).getStatement()) .isEqualTo( "MATCH (n:`Asteroid`) MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name_0` } AND m0.`size` = { `collidesWith_size_1` } MATCH (n)-[:`COLLIDES`]->(m0) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @throws Exception * @see DATAGRAPH-632 */ @Test public void testFindByBaseAndNestedPropertyIncoming() throws Exception { Filter planetFilter = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetFilter.setNestedPropertyName("world"); planetFilter.setNestedEntityTypeLabel("Planet"); planetFilter.setRelationshipType("ORBITS"); planetFilter.setRelationshipDirection("INCOMING"); Filter time = new Filter("time", ComparisonOperator.EQUALS, 3600); assertThat(query.findByType("ORBITS", new Filters().add(planetFilter, time), 4).getStatement()) .isEqualTo("MATCH (m:`Planet`) WHERE m.`name` = { `world_name_0` } " + "MATCH (n)-[r0:`ORBITS`]->(m) WHERE r0.`time` = { `time_1` } " + "WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m MATCH p1 = (n)-[*0..4]-() " + "WITH r0, COLLECT(DISTINCT p1) AS startPaths, m MATCH p2 = (m)-[*0..4]-() " + "WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths AS paths UNWIND paths AS p RETURN DISTINCT p, ID(r0)"); }
/** * @see DATAGRAPH-629 */ @Test public void testFindByDifferentNestedPropertiesAnded() { Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); Filter moonParam = new Filter("name", ComparisonOperator.EQUALS, "Moon"); moonParam.setNestedPropertyName("moon"); moonParam.setNestedEntityTypeLabel("Moon"); moonParam.setRelationshipType("ORBITS"); moonParam.setRelationshipDirection("INCOMING"); moonParam.setBooleanOperator(BooleanOperator.AND); assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam).add(moonParam), 1).getStatement()) .isEqualTo("MATCH (n:`Asteroid`) MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name_0` } " + "MATCH (m1:`Moon`) WHERE m1.`name` = { `moon_name_1` } MATCH (n)-[:`COLLIDES`]->(m0) " + "MATCH (n)<-[:`ORBITS`]-(m1) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @see DATAGRAPH-632 */ @Test public void testFindByNestedREProperty() { Filter planetParam = new Filter("totalDestructionProbability", ComparisonOperator.EQUALS, "20"); planetParam.setNestedPropertyName("collision"); planetParam.setNestedEntityTypeLabel("Collision"); //Collision is an RE planetParam.setNestedRelationshipEntity(true); planetParam.setRelationshipType("COLLIDES"); //assume COLLIDES is the RE type planetParam.setRelationshipDirection("OUTGOING"); planetParam.setNestedRelationshipEntity(true); assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam), 1).getStatement()) .isEqualTo("MATCH (n:`Asteroid`) MATCH (n)-[r0:`COLLIDES`]->(m0) " + "WHERE r0.`totalDestructionProbability` = { `collision_totalDestructionProbability_0` } " + "WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @see DATAGRAPH-662 * //TODO FIXME */ @Test(expected = UnsupportedOperationException.class) public void testFindByDifferentNestedPropertiesOred() { Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); Filter moonParam = new Filter("name", ComparisonOperator.EQUALS, "Moon"); moonParam.setNestedPropertyName("moon"); moonParam.setNestedEntityTypeLabel("Moon"); moonParam.setRelationshipType("ORBITS"); moonParam.setRelationshipDirection("INCOMING"); moonParam.setBooleanOperator(BooleanOperator.OR); assertThat( queryStatements.findByType("Asteroid", new Filters().add(planetParam).add(moonParam), 1).getStatement()) .isEqualTo( "MATCH (n:`Asteroid`) MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name` } OPTIONAL MATCH (m1:`Moon`) WHERE m1.`name` = { `moon_name` } OPTIONAL MATCH (n)-[:`COLLIDES`]->(m0) OPTIONAL MATCH (n)<-[:`ORBITS`]-(m1) WITH n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @see DATAGRAPH-629 */ @Test public void testFindByMultipleNestedPropertiesInfiniteDepth() { Filter diameterParam = new Filter("diameter", ComparisonOperator.GREATER_THAN, 60); Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setBooleanOperator(BooleanOperator.AND); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); assertThat(queryStatements.findByType("Asteroid", new Filters().add(diameterParam).add(planetParam), -1) .getStatement()).isEqualTo( "MATCH (n:`Asteroid`) WHERE n.`diameter` > { `diameter_0` } MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name_1` } MATCH (n)-[:`COLLIDES`]->(m0) WITH DISTINCT n MATCH p=(n)-[*0..]-(m) RETURN p, ID(n)"); }
/** * @throws Exception * @see DATAGRAPH-632 */ @Test public void testFindByBaseAndNestedPropertyOutgoing() throws Exception { Filter planetFilter = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetFilter.setNestedPropertyName("world"); planetFilter.setNestedEntityTypeLabel("Planet"); planetFilter.setRelationshipType("ORBITS"); planetFilter.setRelationshipDirection("OUTGOING"); Filter time = new Filter("time", ComparisonOperator.EQUALS, 3600); time.setBooleanOperator(BooleanOperator.AND); assertThat(query.findByType("ORBITS", new Filters().add(planetFilter, time), 4).getStatement()) .isEqualTo("MATCH (n:`Planet`) WHERE n.`name` = { `world_name_0` } " + "MATCH (n)-[r0:`ORBITS`]->(m) WHERE r0.`time` = { `time_1` } " + "WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m MATCH p1 = (n)-[*0..4]-() " + "WITH r0, COLLECT(DISTINCT p1) AS startPaths, m MATCH p2 = (m)-[*0..4]-() " + "WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths AS paths UNWIND paths AS p RETURN DISTINCT p, ID(r0)"); }
/** * @see DATAGRAPH-632 */ @Test public void testFindByNestedBaseAndREProperty() { Filter planetParam = new Filter("totalDestructionProbability", ComparisonOperator.EQUALS, "20"); planetParam.setNestedPropertyName("collision"); planetParam.setNestedEntityTypeLabel("Collision"); //Collision is an RE planetParam.setNestedRelationshipEntity(true); planetParam.setRelationshipType("COLLIDES"); //assume COLLIDES is the RE type planetParam.setRelationshipDirection("OUTGOING"); planetParam.setNestedRelationshipEntity(true); Filter moonParam = new Filter("name", ComparisonOperator.EQUALS, "Moon"); moonParam.setNestedPropertyName("moon"); moonParam.setNestedEntityTypeLabel("Moon"); moonParam.setRelationshipType("ORBITS"); moonParam.setRelationshipDirection("INCOMING"); moonParam.setBooleanOperator(BooleanOperator.AND); assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam, moonParam), 1).getStatement()) .isEqualTo("MATCH (n:`Asteroid`) MATCH (n)-[r0:`COLLIDES`]->(m0) " + "WHERE r0.`totalDestructionProbability` = { `collision_totalDestructionProbability_0` } " + "MATCH (m1:`Moon`) WHERE m1.`name` = { `moon_name_1` } MATCH (n)<-[:`ORBITS`]-(m1) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @see DATAGRAPH-629 */ @Test public void testFindByMultipleNestedProperties() { Filter diameterParam = new Filter("diameter", ComparisonOperator.GREATER_THAN, 60); Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setBooleanOperator(BooleanOperator.AND); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); assertThat( queryStatements.findByType("Asteroid", new Filters().add(diameterParam).add(planetParam), 1).getStatement()) .isEqualTo( "MATCH (n:`Asteroid`) WHERE n.`diameter` > { `diameter_0` } MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name_1` } MATCH (n)-[:`COLLIDES`]->(m0) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @see DATAGRAPH-662 * //TODO FIXME */ @Test(expected = UnsupportedOperationException.class) public void testFindByMultipleNestedPropertiesOredDepth0() { Filter diameterParam = new Filter("diameter", ComparisonOperator.GREATER_THAN, 60); Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setBooleanOperator(BooleanOperator.OR); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); assertThat( queryStatements.findByType("Asteroid", new Filters().add(diameterParam).add(planetParam), 0).getStatement()) .isEqualTo( "MATCH (n:`Asteroid`) WHERE n.`diameter` > { `diameter` } OPTIONAL MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name` } OPTIONAL MATCH (n)-[:`COLLIDES`]->(m0) RETURN n"); }
/** * @see DATAGRAPH-662 * //TODO FIXME */ @Test(expected = UnsupportedOperationException.class) public void testFindByMultipleNestedPropertiesOred() { Filter diameterParam = new Filter("diameter", ComparisonOperator.GREATER_THAN, 60); Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetParam.setBooleanOperator(BooleanOperator.OR); planetParam.setNestedPropertyName("collidesWith"); planetParam.setNestedEntityTypeLabel("Planet"); planetParam.setRelationshipType("COLLIDES"); planetParam.setRelationshipDirection("OUTGOING"); assertThat( queryStatements.findByType("Asteroid", new Filters().add(diameterParam).add(planetParam), 1).getStatement()) .isEqualTo( "MATCH (n:`Asteroid`) WHERE n.`diameter` > { `diameter` } OPTIONAL MATCH (m0:`Planet`) WHERE m0.`name` = { `collidesWith_name` } OPTIONAL MATCH (n)-[:`COLLIDES`]->(m0) WITH n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"); }
/** * @throws Exception * @see Issue #73 */ @Test(expected = MissingOperatorException.class) public void testFindByMultipleNestedPropertiesMissingBooleanOperator() throws Exception { Filter planetNameFilter = new Filter("name", ComparisonOperator.EQUALS, "Earth"); planetNameFilter.setNestedPropertyName("world"); planetNameFilter.setNestedEntityTypeLabel("Planet"); planetNameFilter.setRelationshipType("ORBITS"); planetNameFilter.setRelationshipDirection("OUTGOING"); Filter planetMoonsFilter = new Filter("moons", ComparisonOperator.EQUALS, "Earth"); planetMoonsFilter.setNestedPropertyName("moons"); planetMoonsFilter.setNestedEntityTypeLabel("Planet"); planetMoonsFilter.setRelationshipType("ORBITS"); planetMoonsFilter.setRelationshipDirection("OUTGOING"); query.findByType("ORBITS", new Filters().add(planetNameFilter, planetMoonsFilter), 4).getStatement(); } }