From 3aafb2faf5aa9e775b951d039963f168f3bf1f46 Mon Sep 17 00:00:00 2001 From: Veselin Nikolov Date: Thu, 7 Nov 2024 07:18:20 +0000 Subject: [PATCH] Decouple QueryEstimator from Task Co-authored-by: Ioannis Panagiotas --- .../org/neo4j/gds/projection/Constants.java | 26 +++++++++++++++++++ .../neo4j/gds/projection/QueryEstimator.java | 6 +++-- .../projection/QueryRowEstimationUtil.java | 7 ++--- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 cypher-aggregation/src/main/java/org/neo4j/gds/projection/Constants.java diff --git a/cypher-aggregation/src/main/java/org/neo4j/gds/projection/Constants.java b/cypher-aggregation/src/main/java/org/neo4j/gds/projection/Constants.java new file mode 100644 index 0000000000..1c3a6acc08 --- /dev/null +++ b/cypher-aggregation/src/main/java/org/neo4j/gds/projection/Constants.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.gds.projection; + +public final class Constants { + public static final int UNKNOWN_ROW_COUNT = -1; + + private Constants() {} +} diff --git a/cypher-aggregation/src/main/java/org/neo4j/gds/projection/QueryEstimator.java b/cypher-aggregation/src/main/java/org/neo4j/gds/projection/QueryEstimator.java index 10ced6b4f3..1a66df6cb2 100644 --- a/cypher-aggregation/src/main/java/org/neo4j/gds/projection/QueryEstimator.java +++ b/cypher-aggregation/src/main/java/org/neo4j/gds/projection/QueryEstimator.java @@ -19,10 +19,12 @@ */ package org.neo4j.gds.projection; -import org.neo4j.gds.core.utils.progress.tasks.Task; import org.neo4j.gds.transaction.TransactionContext; +import static org.neo4j.gds.projection.Constants.UNKNOWN_ROW_COUNT; + public interface QueryEstimator { + int estimateRows(String query); static QueryEstimator fromTransaction(TransactionContext transaction) { @@ -30,7 +32,7 @@ static QueryEstimator fromTransaction(TransactionContext transaction) { } static QueryEstimator empty() { - return __ -> Task.UNKNOWN_VOLUME; + return __ -> UNKNOWN_ROW_COUNT; } } diff --git a/cypher-aggregation/src/main/java/org/neo4j/gds/projection/QueryRowEstimationUtil.java b/cypher-aggregation/src/main/java/org/neo4j/gds/projection/QueryRowEstimationUtil.java index 4bb3298fe2..dba048bfb6 100644 --- a/cypher-aggregation/src/main/java/org/neo4j/gds/projection/QueryRowEstimationUtil.java +++ b/cypher-aggregation/src/main/java/org/neo4j/gds/projection/QueryRowEstimationUtil.java @@ -19,12 +19,13 @@ */ package org.neo4j.gds.projection; -import org.neo4j.gds.core.utils.progress.tasks.Task; import org.neo4j.gds.transaction.TransactionContext; import org.neo4j.graphdb.ExecutionPlanDescription; import java.util.Optional; +import static org.neo4j.gds.projection.Constants.UNKNOWN_ROW_COUNT; + final class QueryRowEstimationUtil { private QueryRowEstimationUtil() {} @@ -42,9 +43,9 @@ static int estimatedRows(TransactionContext transactionContext, String query) { var aggregationChild = findChildOfRemoteAggregation(executionPlan); return aggregationChild .map(child -> ((Number) child.getArguments().get("EstimatedRows")).intValue()) - .orElse(Task.UNKNOWN_VOLUME); + .orElse(UNKNOWN_ROW_COUNT); } catch (Exception e) { - return Task.UNKNOWN_VOLUME; + return UNKNOWN_ROW_COUNT; } }