|
| 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