Skip to content

Commit 10bbe3b

Browse files
[CI] Auto commit changes from spotless
1 parent b11c805 commit 10bbe3b

File tree

5 files changed

+93
-82
lines changed

5 files changed

+93
-82
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/ChangePointOperator.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public class ChangePointOperator implements Operator {
3838

3939
public static final int INPUT_VALUE_COUNT_LIMIT = 1000;
4040

41-
public record Factory(int metricChannel, List<Integer> partitionChannel, String sourceText, int sourceLine, int sourceColumn) implements OperatorFactory {
41+
public record Factory(int metricChannel, List<Integer> partitionChannel, String sourceText, int sourceLine, int sourceColumn)
42+
implements
43+
OperatorFactory {
4244
@Override
4345
public Operator get(DriverContext driverContext) {
4446
return new ChangePointOperator(driverContext, metricChannel, partitionChannel, sourceText, sourceLine, sourceColumn);
@@ -64,7 +66,14 @@ public String describe() {
6466

6567
// TODO: make org.elasticsearch.xpack.esql.core.tree.Source available here
6668
// (by modularizing esql-core) and use that instead of the individual fields.
67-
public ChangePointOperator(DriverContext driverContext, int metricChannel, List<Integer> partitionChannel, String sourceText, int sourceLine, int sourceColumn) {
69+
public ChangePointOperator(
70+
DriverContext driverContext,
71+
int metricChannel,
72+
List<Integer> partitionChannel,
73+
String sourceText,
74+
int sourceLine,
75+
int sourceColumn
76+
) {
6877
this.driverContext = driverContext;
6978
this.metricChannel = metricChannel;
7079
this.partitionChannel = partitionChannel;
@@ -128,7 +137,6 @@ private void createOutputPages() {
128137
}
129138
boolean tooManyValues = maxValuesCount > INPUT_VALUE_COUNT_LIMIT;
130139

131-
132140
List<MlAggsHelper.DoubleBucketValues> bucketValuesPerPartition = new ArrayList<>();
133141
boolean hasNulls = false;
134142
boolean hasMultivalued = false;
@@ -168,14 +176,14 @@ private void createOutputPages() {
168176
}
169177
}
170178
// Handle last partition separately
171-
// if (lastPartitionFieldValue != null) {
179+
// if (lastPartitionFieldValue != null) {
172180
MlAggsHelper.DoubleBucketValues bucketValues = new MlAggsHelper.DoubleBucketValues(
173181
null,
174182
values.stream().mapToDouble(Double::doubleValue).toArray(),
175183
bucketIndexes.stream().mapToInt(Integer::intValue).toArray()
176184
);
177185
bucketValuesPerPartition.add(bucketValues);
178-
// }
186+
// }
179187
}
180188

181189
List<ChangeType> changeTypes = new ArrayList<>();
@@ -237,7 +245,9 @@ private void insertChangePoints(Iterable<ChangeType> changeTypes) {
237245

238246
try {
239247
// TODO: How to handle case when there are no change points
240-
if (changeType != null && pageStartIndex <= changeType.changePoint() && changeType.changePoint() < pageStartIndex + inputPage.getPositionCount()) {
248+
if (changeType != null
249+
&& pageStartIndex <= changeType.changePoint()
250+
&& changeType.changePoint() < pageStartIndex + inputPage.getPositionCount()) {
241251
try (
242252
BytesRefBlock.Builder changeTypeBlockBuilder = blockFactory.newBytesRefBlockBuilder(inputPage.getPositionCount());
243253
DoubleBlock.Builder pvalueBlockBuilder = blockFactory.newDoubleBlockBuilder(inputPage.getPositionCount())
@@ -258,7 +268,7 @@ private void insertChangePoints(Iterable<ChangeType> changeTypes) {
258268
changeTypeBlock = blockFactory.newConstantNullBlock(inputPage.getPositionCount());
259269
changePvalueBlock = blockFactory.newConstantNullBlock(inputPage.getPositionCount());
260270
}
261-
outputPage = inputPage.appendBlocks(new Block[]{changeTypeBlock, changePvalueBlock});
271+
outputPage = inputPage.appendBlocks(new Block[] { changeTypeBlock, changePvalueBlock });
262272
if (pageStartIndex + inputPage.getPositionCount() > INPUT_VALUE_COUNT_LIMIT) {
263273
outputPage = outputPage.subPage(0, INPUT_VALUE_COUNT_LIMIT - pageStartIndex);
264274
}
@@ -317,7 +327,7 @@ private static String describe(int metricChannel, List<Integer> partitionChannel
317327
+ metricChannel
318328
+ ", partitionChannels="
319329
+ partitionChannel.stream().map(c -> c.toString()).collect(Collectors.joining(",", "[", "]"))
320-
+ "]";
330+
+ "]";
321331
}
322332

323333
private Warnings warnings(boolean onlyWarnings) {

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/topn/TopNOperator.java

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -461,78 +461,78 @@ private Iterator<Page> toPages() {
461461
// TODO: optimize case where all the queues are empty
462462
try {
463463
for (var entry : inputQueues.entrySet()) {
464-
Queue inputQueue = entry.getValue();
464+
Queue inputQueue = entry.getValue();
465465

466-
list = new ArrayList<>(inputQueue.size());
467-
builders = null;
468-
while (inputQueue.size() > 0) {
469-
list.add(inputQueue.pop());
470-
}
471-
Collections.reverse(list);
472-
473-
int p = 0;
474-
int size = 0;
475-
for (int i = 0; i < list.size(); i++) {
476-
if (builders == null) {
477-
size = Math.min(maxPageSize, list.size() - i);
478-
builders = new ResultBuilder[elementTypes.size()];
479-
for (int b = 0; b < builders.length; b++) {
480-
builders[b] = ResultBuilder.resultBuilderFor(
481-
blockFactory,
482-
elementTypes.get(b),
483-
encoders.get(b).toUnsortable(),
484-
channelInKey(sortOrders, b),
485-
size
486-
);
487-
}
488-
p = 0;
466+
list = new ArrayList<>(inputQueue.size());
467+
builders = null;
468+
while (inputQueue.size() > 0) {
469+
list.add(inputQueue.pop());
489470
}
471+
Collections.reverse(list);
472+
473+
int p = 0;
474+
int size = 0;
475+
for (int i = 0; i < list.size(); i++) {
476+
if (builders == null) {
477+
size = Math.min(maxPageSize, list.size() - i);
478+
builders = new ResultBuilder[elementTypes.size()];
479+
for (int b = 0; b < builders.length; b++) {
480+
builders[b] = ResultBuilder.resultBuilderFor(
481+
blockFactory,
482+
elementTypes.get(b),
483+
encoders.get(b).toUnsortable(),
484+
channelInKey(sortOrders, b),
485+
size
486+
);
487+
}
488+
p = 0;
489+
}
490490

491-
Row row = list.get(i);
492-
BytesRef keys = row.keys.bytesRefView();
493-
for (SortOrder so : sortOrders) {
494-
if (keys.bytes[keys.offset] == so.nul()) {
491+
Row row = list.get(i);
492+
BytesRef keys = row.keys.bytesRefView();
493+
for (SortOrder so : sortOrders) {
494+
if (keys.bytes[keys.offset] == so.nul()) {
495+
keys.offset++;
496+
keys.length--;
497+
continue;
498+
}
495499
keys.offset++;
496500
keys.length--;
497-
continue;
501+
builders[so.channel].decodeKey(keys);
502+
}
503+
if (keys.length != 0) {
504+
throw new IllegalArgumentException("didn't read all keys");
498505
}
499-
keys.offset++;
500-
keys.length--;
501-
builders[so.channel].decodeKey(keys);
502-
}
503-
if (keys.length != 0) {
504-
throw new IllegalArgumentException("didn't read all keys");
505-
}
506-
507-
BytesRef values = row.values.bytesRefView();
508-
for (ResultBuilder builder : builders) {
509-
builder.decodeValue(values);
510-
}
511-
if (values.length != 0) {
512-
throw new IllegalArgumentException("didn't read all values");
513-
}
514506

515-
list.set(i, null);
516-
row.close();
507+
BytesRef values = row.values.bytesRefView();
508+
for (ResultBuilder builder : builders) {
509+
builder.decodeValue(values);
510+
}
511+
if (values.length != 0) {
512+
throw new IllegalArgumentException("didn't read all values");
513+
}
517514

518-
p++;
519-
if (p == size) {
520-
Block[] blocks = new Block[builders.length];
521-
try {
522-
for (int b = 0; b < blocks.length; b++) {
523-
blocks[b] = builders[b].build();
524-
}
525-
} finally {
526-
if (blocks[blocks.length - 1] == null) {
527-
Releasables.closeExpectNoException(blocks);
515+
list.set(i, null);
516+
row.close();
517+
518+
p++;
519+
if (p == size) {
520+
Block[] blocks = new Block[builders.length];
521+
try {
522+
for (int b = 0; b < blocks.length; b++) {
523+
blocks[b] = builders[b].build();
524+
}
525+
} finally {
526+
if (blocks[blocks.length - 1] == null) {
527+
Releasables.closeExpectNoException(blocks);
528+
}
528529
}
530+
result.add(new Page(blocks));
531+
Releasables.closeExpectNoException(builders);
532+
builders = null;
529533
}
530-
result.add(new Page(blocks));
531-
Releasables.closeExpectNoException(builders);
532-
builders = null;
533534
}
534-
}
535-
assert builders == null;
535+
assert builders == null;
536536
}
537537
success = true;
538538
return result.iterator();
@@ -586,9 +586,8 @@ public void close() {
586586
Releasables.closeExpectNoException(spare, Releasables.wrap(releasables));
587587
}
588588

589-
private static long SHALLOW_SIZE = RamUsageEstimator.shallowSizeOfInstance(TopNOperator.class)
590-
+ RamUsageEstimator.shallowSizeOfInstance(List.class) * 4
591-
+ RamUsageEstimator.shallowSizeOfInstance(Map.class);
589+
private static long SHALLOW_SIZE = RamUsageEstimator.shallowSizeOfInstance(TopNOperator.class) + RamUsageEstimator
590+
.shallowSizeOfInstance(List.class) * 4 + RamUsageEstimator.shallowSizeOfInstance(Map.class);
592591

593592
@Override
594593
public long ramBytesUsed() {
@@ -603,7 +602,8 @@ public long ramBytesUsed() {
603602
size += partitions.size() * Partition.SHALLOW_SIZE;
604603
size += RamUsageEstimator.alignObjectSize(arrHeader + ref * sortOrders.size());
605604
size += sortOrders.size() * SortOrder.SHALLOW_SIZE;
606-
long ramBytesUsedSum = inputQueues.entrySet().stream()
605+
long ramBytesUsedSum = inputQueues.entrySet()
606+
.stream()
607607
.mapToLong(e -> e.getKey().getBytes(Charset.defaultCharset()).length + e.getValue().ramBytesUsed())
608608
.sum();
609609
size += ramBytesUsedSum;
@@ -620,7 +620,9 @@ public Status status() {
620620
public String toString() {
621621
int queueSizeSum = inputQueues.values().stream().mapToInt(Queue::size).sum();
622622
return "TopNOperator[count="
623-
+ queueSizeSum + "/" + topCount
623+
+ queueSizeSum
624+
+ "/"
625+
+ topCount
624626
+ ", elementTypes="
625627
+ elementTypes
626628
+ ", encoders="

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.ArrayList;
2121
import java.util.List;
22-
import java.util.Optional;
2322

2423
import static org.hamcrest.Matchers.equalTo;
2524
import static org.hamcrest.Matchers.hasSize;
@@ -74,17 +73,19 @@ protected void assertSimpleOutput(List<Page> input, List<Page> output) {
7473
}
7574
assertThat(
7675
actualChangePoints,
77-
equalTo(List.of(
78-
Tuple.tuple(rowCount / 6, "step_change"),
79-
Tuple.tuple(rowCount / 2, "step_change"),
80-
Tuple.tuple(8 * rowCount / 9, "spike"))
76+
equalTo(
77+
List.of(
78+
Tuple.tuple(rowCount / 6, "step_change"),
79+
Tuple.tuple(rowCount / 2, "step_change"),
80+
Tuple.tuple(8 * rowCount / 9, "spike")
81+
)
8182
)
8283
);
8384
}
8485

8586
@Override
8687
protected Operator.OperatorFactory simple(SimpleOptions options) {
87-
return new ChangePointOperator.Factory(0, List.of(1), null,0, 0);
88+
return new ChangePointOperator.Factory(0, List.of(1), null, 0, 0);
8889
}
8990

9091
@Override

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.ArrayList;
2121
import java.util.List;
22-
import java.util.Optional;
2322

2423
import static org.hamcrest.Matchers.equalTo;
2524
import static org.hamcrest.Matchers.hasSize;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.elasticsearch.compute.data.BlockFactory;
1111
import org.elasticsearch.compute.data.Page;
1212
import org.elasticsearch.compute.operator.SourceOperator;
13-
import org.elasticsearch.test.ESTestCase;
1413

1514
/**
1615
* An abstract source operator. Implementations of this operator produce pages with a random

0 commit comments

Comments
 (0)