Skip to content

Commit

Permalink
Decouple QueryEstimator from Task
Browse files Browse the repository at this point in the history
Co-authored-by: Ioannis Panagiotas <[email protected]>
  • Loading branch information
vnickolov and IoannisPanagiotas committed Nov 18, 2024
1 parent a8e1743 commit 3aafb2f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
package org.neo4j.gds.projection;

public final class Constants {
public static final int UNKNOWN_ROW_COUNT = -1;

private Constants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
*/
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) {
return new TxQueryEstimator(transaction);
}

static QueryEstimator empty() {
return __ -> Task.UNKNOWN_VOLUME;
return __ -> UNKNOWN_ROW_COUNT;
}
}

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

Expand Down

0 comments on commit 3aafb2f

Please sign in to comment.