Skip to content

Commit 8a0965c

Browse files
committed
Added options to simpleWithMode() method
1 parent 4178547 commit 8a0965c

File tree

9 files changed

+27
-16
lines changed

9 files changed

+27
-16
lines changed

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/AggregatorFunctionTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected final int aggregatorIntermediateBlockCount() {
6161
protected abstract void assertSimpleOutput(List<Block> input, Block result);
6262

6363
@Override
64-
protected Operator.OperatorFactory simpleWithMode(AggregatorMode mode) {
64+
protected Operator.OperatorFactory simpleWithMode(SimpleOptions options, AggregatorMode mode) {
6565
return simpleWithMode(mode, Function.identity());
6666
}
6767

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/GroupingAggregatorFunctionTestCase.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ protected DataType acceptedDataType() {
9090
};
9191

9292
@Override
93-
protected final Operator.OperatorFactory simpleWithMode(AggregatorMode mode) {
94-
return simpleWithMode(mode, Function.identity());
93+
protected final Operator.OperatorFactory simpleWithMode(SimpleOptions options, AggregatorMode mode) {
94+
return simpleWithMode(options, mode, Function.identity());
9595
}
9696

9797
protected List<Integer> channels(AggregatorMode mode) {
9898
return mode.isInputPartial() ? range(1, 1 + aggregatorIntermediateBlockCount()).boxed().toList() : List.of(1);
9999
}
100100

101101
private Operator.OperatorFactory simpleWithMode(
102+
SimpleOptions options,
102103
AggregatorMode mode,
103104
Function<AggregatorFunctionSupplier, AggregatorFunctionSupplier> wrap
104105
) {
@@ -109,16 +110,16 @@ private Operator.OperatorFactory simpleWithMode(
109110
supplier = chunkGroups(emitChunkSize, supplier);
110111
}
111112

112-
if (shouldRandomizeBlocks()) {
113-
return new RandomizingHashAggregationOperatorFactory(
113+
if (options.requiresDeterministicFactory()) {
114+
return new HashAggregationOperator.HashAggregationOperatorFactory(
114115
List.of(new BlockHash.GroupSpec(0, ElementType.LONG)),
115116
mode,
116117
List.of(supplier.groupingAggregatorFactory(mode, channels(mode))),
117118
randomPageSize(),
118119
null
119120
);
120121
} else {
121-
return new HashAggregationOperator.HashAggregationOperatorFactory(
122+
return new RandomizingHashAggregationOperatorFactory(
122123
List.of(new BlockHash.GroupSpec(0, ElementType.LONG)),
123124
mode,
124125
List.of(supplier.groupingAggregatorFactory(mode, channels(mode))),
@@ -400,6 +401,7 @@ public final void testEmptyInput() {
400401

401402
public final void testAllFiltered() {
402403
Operator.OperatorFactory factory = simpleWithMode(
404+
SimpleOptions.DEFAULT,
403405
AggregatorMode.SINGLE,
404406
agg -> new FilteredAggregatorFunctionSupplier(agg, ConstantBooleanExpressionEvaluator.factory(false))
405407
);
@@ -412,6 +414,7 @@ public final void testAllFiltered() {
412414

413415
public final void testNoneFiltered() {
414416
Operator.OperatorFactory factory = simpleWithMode(
417+
SimpleOptions.DEFAULT,
415418
AggregatorMode.SINGLE,
416419
agg -> new FilteredAggregatorFunctionSupplier(agg, ConstantBooleanExpressionEvaluator.factory(true))
417420
);
@@ -425,6 +428,7 @@ public final void testNoneFiltered() {
425428

426429
public void testSomeFiltered() {
427430
Operator.OperatorFactory factory = simpleWithMode(
431+
SimpleOptions.DEFAULT,
428432
AggregatorMode.SINGLE,
429433
agg -> new FilteredAggregatorFunctionSupplier(agg, AddGarbageRowsSourceOperator.filterFactory())
430434
);

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/AggregationOperatorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected SourceOperator simpleInput(BlockFactory blockFactory, int size) {
3535
}
3636

3737
@Override
38-
protected Operator.OperatorFactory simpleWithMode(AggregatorMode mode) {
38+
protected Operator.OperatorFactory simpleWithMode(SimpleOptions options, AggregatorMode mode) {
3939
List<Integer> sumChannels, maxChannels;
4040
if (mode.isInputPartial()) {
4141
int sumInterChannelCount = SumLongAggregatorFunction.intermediateStateDesc().size();

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/ForkingOperatorTestCase.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ public abstract class ForkingOperatorTestCase extends OperatorTestCase {
5454

5555
private static final String ESQL_TEST_EXECUTOR = "esql_test_executor";
5656

57-
protected abstract Operator.OperatorFactory simpleWithMode(AggregatorMode mode);
57+
protected abstract Operator.OperatorFactory simpleWithMode(SimpleOptions options, AggregatorMode mode);
58+
59+
/**
60+
* Calls {@link #simpleWithMode(SimpleOptions, AggregatorMode)} with the default options.
61+
*/
62+
protected final Operator.OperatorFactory simpleWithMode(AggregatorMode mode) {
63+
return simpleWithMode(SimpleOptions.DEFAULT, mode);
64+
}
5865

5966
@Override
6067
protected final Operator.OperatorFactory simple(SimpleOptions options) {
61-
return simpleWithMode(AggregatorMode.SINGLE);
68+
return simpleWithMode(options, AggregatorMode.SINGLE);
6269
}
6370

6471
public final void testInitialFinal() {

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/HashAggregationOperatorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected SourceOperator simpleInput(BlockFactory blockFactory, int size) {
4141
}
4242

4343
@Override
44-
protected Operator.OperatorFactory simpleWithMode(AggregatorMode mode) {
44+
protected Operator.OperatorFactory simpleWithMode(SimpleOptions options, AggregatorMode mode) {
4545
List<Integer> sumChannels, maxChannels;
4646
if (mode.isInputPartial()) {
4747
int sumChannelCount = SumLongAggregatorFunction.intermediateStateDesc().size();

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/LimitOperatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected void assertSimpleOutput(List<Page> input, List<Page> results) {
5555

5656
public void testStatus() {
5757
BlockFactory blockFactory = driverContext().blockFactory();
58-
LimitOperator op = simple().get(driverContext());
58+
LimitOperator op = simple(SimpleOptions.DEFAULT).get(driverContext());
5959

6060
LimitOperator.Status status = op.status();
6161
assertThat(status.limit(), equalTo(100));
@@ -77,7 +77,7 @@ public void testStatus() {
7777

7878
public void testNeedInput() {
7979
BlockFactory blockFactory = driverContext().blockFactory();
80-
try (LimitOperator op = simple().get(driverContext())) {
80+
try (LimitOperator op = simple(SimpleOptions.DEFAULT).get(driverContext())) {
8181
assertTrue(op.needsInput());
8282
Page p = new Page(blockFactory.newConstantNullBlock(10));
8383
op.addInput(p);

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/SampleOperatorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void testAccuracy() {
5959
int totalPositionCount = 0;
6060

6161
for (int iter = 0; iter < 10000; iter++) {
62-
SampleOperator operator = simple().get(driverContext());
62+
SampleOperator operator = simple(SimpleOptions.DEFAULT).get(driverContext());
6363
operator.addInput(new Page(blockFactory.newConstantNullBlock(20000)));
6464
Page output = operator.getOutput();
6565
// 10000 expected rows, stddev=sqrt(10000)=100, so this is 10 stddevs.

x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearch/compute/test/AnyOperatorTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
public abstract class AnyOperatorTestCase extends ComputeTestCase {
3535
/**
3636
* @param requiresDeterministicFactory
37-
* True if the returned {@link Operator.OperatorFactory} should always return a deterministic operator.
38-
* That is, for two different calls, both operators should work in the same way.
37+
* True if the returned {@link Operator.OperatorFactory} should always generate an identical deterministic operator.
38+
* That is, for two different calls, both operators should do "exactly" the same.
3939
*/
4040
protected record SimpleOptions(boolean requiresDeterministicFactory) {
4141
public static final SimpleOptions DEFAULT = new SimpleOptions(false);

x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearch/compute/test/OperatorTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected ByteSizeValue enoughMemoryForSimple() {
9898
*/
9999
public final void testSimpleCircuitBreaking() {
100100
ByteSizeValue memoryLimitForSimple = enoughMemoryForSimple();
101-
Operator.OperatorFactory simple = simple();
101+
Operator.OperatorFactory simple = simple(new SimpleOptions(true));
102102
DriverContext inputFactoryContext = driverContext();
103103
List<Page> input = CannedSourceOperator.collectPages(simpleInput(inputFactoryContext.blockFactory(), between(1_000, 10_000)));
104104
try {

0 commit comments

Comments
 (0)