Skip to content

Commit e110baa

Browse files
committed
Support using a fake node count for unit tests
Allowing the LocalQueryRunner to estimate costs using a fake node count allows unit tests to consider network costs and different cluster configurations.
1 parent 926f6f9 commit e110baa

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

presto-main/src/main/java/com/facebook/presto/testing/LocalQueryRunner.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,16 @@ public LocalQueryRunner(Session defaultSession)
251251
new FeaturesConfig()
252252
.setOptimizeMixedDistinctAggregations(true)
253253
.setIterativeOptimizerEnabled(true),
254-
false);
254+
false,
255+
1);
255256
}
256257

257258
public LocalQueryRunner(Session defaultSession, FeaturesConfig featuresConfig)
258259
{
259-
this(defaultSession, featuresConfig, false);
260+
this(defaultSession, featuresConfig, false, 1);
260261
}
261262

262-
private LocalQueryRunner(Session defaultSession, FeaturesConfig featuresConfig, boolean withInitialTransaction)
263+
private LocalQueryRunner(Session defaultSession, FeaturesConfig featuresConfig, boolean withInitialTransaction, int nodeCountForStats)
263264
{
264265
requireNonNull(defaultSession, "defaultSession is null");
265266
checkArgument(!defaultSession.getTransactionId().isPresent() || !withInitialTransaction, "Already in transaction");
@@ -379,14 +380,19 @@ private LocalQueryRunner(Session defaultSession, FeaturesConfig featuresConfig,
379380
new CoefficientBasedStatsCalculator(metadata),
380381
ServerMainModule.createNewStatsCalculator(metadata, new FilterStatsCalculator(metadata), new ScalarStatsCalculator(metadata)));
381382
this.costCalculator = new CostCalculatorUsingExchanges(getNodeCount());
382-
this.estimatedExchangesCostCalculator = new CostCalculatorWithEstimatedExchanges(costCalculator, getNodeCount());
383+
this.estimatedExchangesCostCalculator = new CostCalculatorWithEstimatedExchanges(costCalculator, nodeCountForStats);
383384
this.lookup = new StatelessLookup(statsCalculator, costCalculator);
384385
}
385386

386387
public static LocalQueryRunner queryRunnerWithInitialTransaction(Session defaultSession)
387388
{
388389
checkArgument(!defaultSession.getTransactionId().isPresent(), "Already in transaction!");
389-
return new LocalQueryRunner(defaultSession, new FeaturesConfig(), true);
390+
return new LocalQueryRunner(defaultSession, new FeaturesConfig(), true, 1);
391+
}
392+
393+
public static LocalQueryRunner queryRunnerWithFakeNodeCountForStats(Session defaultSession, int nodeCount)
394+
{
395+
return new LocalQueryRunner(defaultSession, new FeaturesConfig(), false, nodeCount);
390396
}
391397

392398
@Override

0 commit comments

Comments
 (0)