forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement native
int
aggregations (ESQL-701)
This implements "native" `int` flavored aggregations for all existing aggregations. A few of them are just "promoted" to another type before being passed along to the aggregation infrastructure for another type. But that seems fine. Here are the types: ``` `avg(int)` -> `sum(long) / count` -> `double` `count(int)` -> `long` `max(int)` -> `int` `median(int)` -> `median(double)` -> `double` `median_absolute_deviation(int)` -> `mad(double)` -> double `min(int)` -> `int` `sum(int)` -> `sum(long)` -> `long` ``` This also removes the "funny" cast in the CSV tests which promotes `int`s to `long`s because it was confusing and got in the way of testing the `int` flavored versions of these methods.
- Loading branch information
Showing
65 changed files
with
3,010 additions
and
230 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -68,3 +68,4 @@ testfixtures_shared/ | |
|
||
# Generated | ||
checkstyle_ide.xml | ||
x-pack/plugin/esql/gen/ |
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
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
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
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
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
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
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
104 changes: 104 additions & 0 deletions
104
...te/src/main/generated/org/elasticsearch/compute/aggregation/AvgIntAggregatorFunction.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,104 @@ | ||
// 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 java.lang.Override; | ||
import java.lang.String; | ||
import java.lang.StringBuilder; | ||
import org.elasticsearch.compute.data.AggregatorStateVector; | ||
import org.elasticsearch.compute.data.Block; | ||
import org.elasticsearch.compute.data.ElementType; | ||
import org.elasticsearch.compute.data.IntBlock; | ||
import org.elasticsearch.compute.data.IntVector; | ||
import org.elasticsearch.compute.data.Page; | ||
import org.elasticsearch.compute.data.Vector; | ||
|
||
/** | ||
* {@link AggregatorFunction} implementation for {@link AvgIntAggregator}. | ||
* This class is generated. Do not edit it. | ||
*/ | ||
public final class AvgIntAggregatorFunction implements AggregatorFunction { | ||
private final AvgLongAggregator.AvgState state; | ||
|
||
private final int channel; | ||
|
||
public AvgIntAggregatorFunction(int channel, AvgLongAggregator.AvgState state) { | ||
this.channel = channel; | ||
this.state = state; | ||
} | ||
|
||
public static AvgIntAggregatorFunction create(int channel) { | ||
return new AvgIntAggregatorFunction(channel, AvgIntAggregator.initSingle()); | ||
} | ||
|
||
@Override | ||
public void addRawInput(Page page) { | ||
assert channel >= 0; | ||
ElementType type = page.getBlock(channel).elementType(); | ||
if (type == ElementType.NULL) { | ||
return; | ||
} | ||
IntBlock block = page.getBlock(channel); | ||
IntVector vector = block.asVector(); | ||
if (vector != null) { | ||
addRawVector(vector); | ||
} else { | ||
addRawBlock(block); | ||
} | ||
} | ||
|
||
private void addRawVector(IntVector vector) { | ||
for (int i = 0; i < vector.getPositionCount(); i++) { | ||
AvgIntAggregator.combine(state, vector.getInt(i)); | ||
} | ||
AvgIntAggregator.combineValueCount(state, vector.getPositionCount()); | ||
} | ||
|
||
private void addRawBlock(IntBlock block) { | ||
for (int i = 0; i < block.getTotalValueCount(); i++) { | ||
if (block.isNull(i) == false) { | ||
AvgIntAggregator.combine(state, block.getInt(i)); | ||
} | ||
} | ||
AvgIntAggregator.combineValueCount(state, block.validPositionCount()); | ||
} | ||
|
||
@Override | ||
public void addIntermediateInput(Block block) { | ||
assert channel == -1; | ||
Vector vector = block.asVector(); | ||
if (vector == null || vector instanceof AggregatorStateVector == false) { | ||
throw new RuntimeException("expected AggregatorStateBlock, got:" + block); | ||
} | ||
@SuppressWarnings("unchecked") AggregatorStateVector<AvgLongAggregator.AvgState> blobVector = (AggregatorStateVector<AvgLongAggregator.AvgState>) vector; | ||
AvgLongAggregator.AvgState tmpState = new AvgLongAggregator.AvgState(); | ||
for (int i = 0; i < block.getPositionCount(); i++) { | ||
blobVector.get(i, tmpState); | ||
AvgIntAggregator.combineStates(state, tmpState); | ||
} | ||
} | ||
|
||
@Override | ||
public Block evaluateIntermediate() { | ||
AggregatorStateVector.Builder<AggregatorStateVector<AvgLongAggregator.AvgState>, AvgLongAggregator.AvgState> builder = | ||
AggregatorStateVector.builderOfAggregatorState(AvgLongAggregator.AvgState.class, state.getEstimatedSize()); | ||
builder.add(state); | ||
return builder.build().asBlock(); | ||
} | ||
|
||
@Override | ||
public Block evaluateFinal() { | ||
return AvgIntAggregator.evaluateFinal(state); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(getClass().getSimpleName()).append("["); | ||
sb.append("channel=").append(channel); | ||
sb.append("]"); | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.