-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Fixed a leak if the breaker breaks on `ValuesBytesRefGroupingAggregator` - Improved aggregators Cranky test to show a better error with the failing stacktrace
- Loading branch information
Showing
5 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
16 changes: 14 additions & 2 deletions
16
...rc/main/generated-src/org/elasticsearch/compute/aggregation/ValuesBytesRefAggregator.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...est/java/org/elasticsearch/compute/aggregation/ValuesBytesRefAggregatorFunctionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.compute.aggregation; | ||
|
||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.compute.data.Block; | ||
import org.elasticsearch.compute.data.BlockFactory; | ||
import org.elasticsearch.compute.data.BlockUtils; | ||
import org.elasticsearch.compute.operator.SequenceBytesRefBlockSourceOperator; | ||
import org.elasticsearch.compute.operator.SourceOperator; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.TreeSet; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
|
||
public class ValuesBytesRefAggregatorFunctionTests extends AggregatorFunctionTestCase { | ||
@Override | ||
protected SourceOperator simpleInput(BlockFactory blockFactory, int size) { | ||
return new SequenceBytesRefBlockSourceOperator( | ||
blockFactory, | ||
IntStream.range(0, size).mapToObj(l -> new BytesRef(randomAlphaOfLengthBetween(0, 100))) | ||
); | ||
} | ||
|
||
@Override | ||
protected AggregatorFunctionSupplier aggregatorFunction(List<Integer> inputChannels) { | ||
return new ValuesBytesRefAggregatorFunctionSupplier(inputChannels); | ||
} | ||
|
||
@Override | ||
protected String expectedDescriptionOfAggregator() { | ||
return "values of bytes"; | ||
} | ||
|
||
@Override | ||
public void assertSimpleOutput(List<Block> input, Block result) { | ||
TreeSet<?> set = new TreeSet<>((List<?>) BlockUtils.toJavaObject(result, 0)); | ||
Object[] values = input.stream() | ||
.flatMap(AggregatorFunctionTestCase::allBytesRefs) | ||
.collect(Collectors.toSet()) | ||
.toArray(Object[]::new); | ||
if (false == set.containsAll(Arrays.asList(values))) { | ||
assertThat(set, containsInAnyOrder(values)); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
.../org/elasticsearch/compute/aggregation/ValuesBytesRefGroupingAggregatorFunctionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.compute.aggregation; | ||
|
||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.compute.data.Block; | ||
import org.elasticsearch.compute.data.BlockFactory; | ||
import org.elasticsearch.compute.data.BlockUtils; | ||
import org.elasticsearch.compute.data.Page; | ||
import org.elasticsearch.compute.operator.LongBytesRefTupleBlockSourceOperator; | ||
import org.elasticsearch.compute.operator.SourceOperator; | ||
import org.elasticsearch.core.Tuple; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.TreeSet; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
public class ValuesBytesRefGroupingAggregatorFunctionTests extends GroupingAggregatorFunctionTestCase { | ||
@Override | ||
protected AggregatorFunctionSupplier aggregatorFunction(List<Integer> inputChannels) { | ||
return new ValuesBytesRefAggregatorFunctionSupplier(inputChannels); | ||
} | ||
|
||
@Override | ||
protected String expectedDescriptionOfAggregator() { | ||
return "values of bytes"; | ||
} | ||
|
||
@Override | ||
protected SourceOperator simpleInput(BlockFactory blockFactory, int size) { | ||
return new LongBytesRefTupleBlockSourceOperator( | ||
blockFactory, | ||
IntStream.range(0, size).mapToObj(l -> Tuple.tuple(randomLongBetween(0, 4), new BytesRef(randomAlphaOfLengthBetween(0, 100)))) | ||
); | ||
} | ||
|
||
@Override | ||
public void assertSimpleGroup(List<Page> input, Block result, int position, Long group) { | ||
Object[] values = input.stream().flatMap(p -> allBytesRefs(p, group)).collect(Collectors.toSet()).toArray(Object[]::new); | ||
Object resultValue = BlockUtils.toJavaObject(result, position); | ||
switch (values.length) { | ||
case 0 -> assertThat(resultValue, nullValue()); | ||
case 1 -> assertThat(resultValue, equalTo(values[0])); | ||
default -> { | ||
TreeSet<?> set = new TreeSet<>((List<?>) resultValue); | ||
if (false == set.containsAll(Arrays.asList(values))) { | ||
assertThat(set, containsInAnyOrder(values)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters