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.
[ES|QL] Support some stats on aggregate_metric_double (elastic#120343)
Adds non-grouping support for min, max, sum, and count, using CompositeBlock as the underlying block type and an internal FromAggregateMetricDouble function to handle converting from CompositeBlock to the correct metric subfields. Closes elastic#110649
- Loading branch information
Showing
36 changed files
with
1,019 additions
and
102 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 120343 | ||
summary: Support some stats on aggregate_metric_double | ||
area: "ES|QL" | ||
type: enhancement | ||
issues: | ||
- 110649 |
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
165 changes: 165 additions & 0 deletions
165
...mpute/src/main/java/org/elasticsearch/compute/data/AggregateMetricDoubleBlockBuilder.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,165 @@ | ||
/* | ||
* 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.data; | ||
|
||
import org.elasticsearch.core.Releasables; | ||
import org.elasticsearch.index.mapper.BlockLoader; | ||
|
||
public class AggregateMetricDoubleBlockBuilder extends AbstractBlockBuilder implements BlockLoader.AggregateMetricDoubleBuilder { | ||
|
||
private DoubleBlockBuilder minBuilder; | ||
private DoubleBlockBuilder maxBuilder; | ||
private DoubleBlockBuilder sumBuilder; | ||
private IntBlockBuilder countBuilder; | ||
|
||
public AggregateMetricDoubleBlockBuilder(int estimatedSize, BlockFactory blockFactory) { | ||
super(blockFactory); | ||
minBuilder = null; | ||
maxBuilder = null; | ||
sumBuilder = null; | ||
countBuilder = null; | ||
try { | ||
minBuilder = new DoubleBlockBuilder(estimatedSize, blockFactory); | ||
maxBuilder = new DoubleBlockBuilder(estimatedSize, blockFactory); | ||
sumBuilder = new DoubleBlockBuilder(estimatedSize, blockFactory); | ||
countBuilder = new IntBlockBuilder(estimatedSize, blockFactory); | ||
} finally { | ||
if (countBuilder == null) { | ||
Releasables.closeWhileHandlingException(minBuilder, maxBuilder, sumBuilder, countBuilder); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected int valuesLength() { | ||
throw new UnsupportedOperationException("Not available on aggregate_metric_double"); | ||
} | ||
|
||
@Override | ||
protected void growValuesArray(int newSize) { | ||
throw new UnsupportedOperationException("Not available on aggregate_metric_double"); | ||
} | ||
|
||
@Override | ||
protected int elementSize() { | ||
throw new UnsupportedOperationException("Not available on aggregate_metric_double"); | ||
} | ||
|
||
@Override | ||
public Block.Builder copyFrom(Block block, int beginInclusive, int endExclusive) { | ||
Block minBlock; | ||
Block maxBlock; | ||
Block sumBlock; | ||
Block countBlock; | ||
if (block.areAllValuesNull()) { | ||
minBlock = block; | ||
maxBlock = block; | ||
sumBlock = block; | ||
countBlock = block; | ||
} else { | ||
CompositeBlock composite = (CompositeBlock) block; | ||
minBlock = composite.getBlock(Metric.MIN.getIndex()); | ||
maxBlock = composite.getBlock(Metric.MAX.getIndex()); | ||
sumBlock = composite.getBlock(Metric.SUM.getIndex()); | ||
countBlock = composite.getBlock(Metric.COUNT.getIndex()); | ||
} | ||
minBuilder.copyFrom(minBlock, beginInclusive, endExclusive); | ||
maxBuilder.copyFrom(maxBlock, beginInclusive, endExclusive); | ||
sumBuilder.copyFrom(sumBlock, beginInclusive, endExclusive); | ||
countBuilder.copyFrom(countBlock, beginInclusive, endExclusive); | ||
return this; | ||
} | ||
|
||
@Override | ||
public AbstractBlockBuilder appendNull() { | ||
minBuilder.appendNull(); | ||
maxBuilder.appendNull(); | ||
sumBuilder.appendNull(); | ||
countBuilder.appendNull(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Block.Builder mvOrdering(Block.MvOrdering mvOrdering) { | ||
minBuilder.mvOrdering(mvOrdering); | ||
maxBuilder.mvOrdering(mvOrdering); | ||
sumBuilder.mvOrdering(mvOrdering); | ||
countBuilder.mvOrdering(mvOrdering); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Block build() { | ||
Block[] blocks = new Block[4]; | ||
boolean success = false; | ||
try { | ||
finish(); | ||
blocks[Metric.MIN.getIndex()] = minBuilder.build(); | ||
blocks[Metric.MAX.getIndex()] = maxBuilder.build(); | ||
blocks[Metric.SUM.getIndex()] = sumBuilder.build(); | ||
blocks[Metric.COUNT.getIndex()] = countBuilder.build(); | ||
CompositeBlock block = new CompositeBlock(blocks); | ||
success = true; | ||
return block; | ||
} finally { | ||
if (success == false) { | ||
Releasables.closeExpectNoException(blocks); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void extraClose() { | ||
Releasables.closeExpectNoException(minBuilder, maxBuilder, sumBuilder, countBuilder); | ||
} | ||
|
||
@Override | ||
public BlockLoader.DoubleBuilder min() { | ||
return minBuilder; | ||
} | ||
|
||
@Override | ||
public BlockLoader.DoubleBuilder max() { | ||
return maxBuilder; | ||
} | ||
|
||
@Override | ||
public BlockLoader.DoubleBuilder sum() { | ||
return sumBuilder; | ||
} | ||
|
||
@Override | ||
public BlockLoader.IntBuilder count() { | ||
return countBuilder; | ||
} | ||
|
||
public enum Metric { | ||
MIN(0), | ||
MAX(1), | ||
SUM(2), | ||
COUNT(3); | ||
|
||
private final int index; | ||
|
||
Metric(int index) { | ||
this.index = index; | ||
} | ||
|
||
public int getIndex() { | ||
return index; | ||
} | ||
} | ||
|
||
public record AggregateMetricDoubleLiteral(Double min, Double max, Double sum, Integer count) { | ||
public AggregateMetricDoubleLiteral { | ||
min = min.isNaN() ? null : min; | ||
max = max.isNaN() ? null : max; | ||
sum = sum.isNaN() ? null : sum; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.