Skip to content

Commit 2423525

Browse files
FlorentinDDarthMax
andcommitted
Test CypherQueryEstimator
Co-authored-by: Max Kießling <max.kiessling@neotechnology.com>
1 parent 1abe53e commit 2423525

File tree

2 files changed

+68
-27
lines changed

2 files changed

+68
-27
lines changed

core/src/main/java/org/neo4j/gds/core/loading/CypherQueryEstimator.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,14 @@
1919
*/
2020
package org.neo4j.gds.core.loading;
2121

22-
import org.immutables.value.Value;
23-
import org.neo4j.gds.PropertyMapping;
2422
import org.neo4j.gds.annotation.ValueClass;
25-
import org.neo4j.gds.api.DefaultValue;
2623
import org.neo4j.gds.transaction.TransactionContext;
2724

2825
import java.util.ArrayList;
2926
import java.util.Collection;
30-
import java.util.Map;
31-
import java.util.stream.Collectors;
32-
import java.util.stream.LongStream;
3327

3428
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
3529
import static org.neo4j.internal.kernel.api.security.AccessMode.Static.READ;
36-
import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY;
3730

3831
public class CypherQueryEstimator {
3932

@@ -73,25 +66,5 @@ interface EstimationResult {
7366
long estimatedRows();
7467

7568
long propertyCount();
76-
77-
@Value.Derived
78-
default Map<String, Integer> propertyTokens() {
79-
return LongStream
80-
.range(0, propertyCount())
81-
.boxed()
82-
.collect(Collectors.toMap(
83-
Object::toString,
84-
property -> NO_SUCH_PROPERTY_KEY
85-
));
86-
}
87-
88-
@Value.Derived
89-
default Collection<PropertyMapping> propertyMappings() {
90-
return LongStream
91-
.range(0, propertyCount())
92-
.mapToObj(property -> PropertyMapping.of(Long.toString(property), DefaultValue.DEFAULT))
93-
.collect(Collectors.toList());
94-
}
95-
9669
}
9770
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.core.loading;
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.neo4j.gds.BaseTest;
24+
import org.neo4j.gds.compat.GraphDatabaseApiProxy;
25+
import org.neo4j.gds.extension.Neo4jGraph;
26+
import org.neo4j.gds.transaction.TransactionContext;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
class CypherQueryEstimatorTest extends BaseTest {
31+
32+
@Neo4jGraph
33+
private static final String DB_CYPHER =
34+
"CREATE" +
35+
" (a1:A {property: 33, a: 33})" +
36+
", (a2:A {property: 33, a: 33})" +
37+
", (b:B {property: 42, b: 42})" +
38+
", (a1)-[:T1 {property1: 42, property2: 1337}]->(b)" +
39+
", (a2)-[:T2 {property1: 43}]->(b)" +
40+
", (a2)-[:T2 {property1: 43}]->(a1)";
41+
42+
@Test
43+
void estimateNodes() {
44+
GraphDatabaseApiProxy.runInTransaction(db, tx -> {
45+
CypherQueryEstimator estimator = new CypherQueryEstimator(TransactionContext.of(db, tx));
46+
47+
var estimation = estimator.getNodeEstimation(
48+
"MATCH (n) RETURN id(n) AS id, labels(n) AS labels, n.property AS score");
49+
50+
// EXPLAIN seems to overestimate the nodeCount here
51+
assertThat(estimation).isEqualTo(ImmutableEstimationResult.of(10, 1));
52+
});
53+
}
54+
55+
@Test
56+
void estimateRelationships() {
57+
GraphDatabaseApiProxy.runInTransaction(db, tx -> {
58+
CypherQueryEstimator estimator = new CypherQueryEstimator(TransactionContext.of(db, tx));
59+
60+
var estimation = estimator.getRelationshipEstimation(
61+
"MATCH (n)-[r]-(m) RETURN id(n) AS source, m AS target, r.property1 AS score, type(r) AS type");
62+
63+
assertThat(estimation).isEqualTo(ImmutableEstimationResult.of(6, 1));
64+
});
65+
}
66+
67+
68+
}

0 commit comments

Comments
 (0)