Skip to content

Commit fe14e17

Browse files
authored
Use TDigest fast mode in ESQL (ESQL-1361)
Ideally, we should allow users to select the T-digest mode: fast or accuracy; but the default should be the fast mode.
1 parent 9b737ed commit fe14e17

File tree

8 files changed

+23
-23
lines changed

8 files changed

+23
-23
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/QuantileStates.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int serializeDigest(TDigestState digest, byte[] ba, int offset) {
4949

5050
static TDigestState deserializeDigest(byte[] ba, int offset) {
5151
final double compression = (double) doubleHandle.get(ba, offset);
52-
final TDigestState digest = TDigestState.createOptimizedForAccuracy(compression);
52+
final TDigestState digest = TDigestState.create(compression);
5353
final int positions = (int) intHandle.get(ba, offset + 8);
5454
offset += 12;
5555
for (int i = 0; i < positions; i++) {
@@ -72,7 +72,7 @@ static class SingleState implements AggregatorState<SingleState> {
7272
private final Double percentile;
7373

7474
SingleState(double percentile) {
75-
this.digest = TDigestState.createOptimizedForAccuracy(DEFAULT_COMPRESSION);
75+
this.digest = TDigestState.create(DEFAULT_COMPRESSION);
7676
this.percentile = percentileParam(percentile);
7777
}
7878

@@ -160,7 +160,7 @@ private TDigestState getOrAddGroup(int groupId) {
160160
}
161161
TDigestState qs = digests.get(groupId);
162162
if (qs == null) {
163-
qs = TDigestState.createOptimizedForAccuracy(DEFAULT_COMPRESSION);
163+
qs = TDigestState.create(DEFAULT_COMPRESSION);
164164
digests.set(groupId, qs);
165165
}
166166
return qs;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected SourceOperator simpleInput(int size) {
4747

4848
@Override
4949
protected void assertSimpleOutput(List<Block> input, Block result) {
50-
TDigestState td = TDigestState.createOptimizedForAccuracy(QuantileStates.DEFAULT_COMPRESSION);
50+
TDigestState td = TDigestState.create(QuantileStates.DEFAULT_COMPRESSION);
5151
input.stream().flatMapToDouble(b -> allDoubles(b)).forEach(td::add);
5252
double expected = td.quantile(percentile / 100);
5353
double value = ((DoubleBlock) result).getDouble(0);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected SourceOperator simpleInput(int end) {
5050

5151
@Override
5252
protected void assertSimpleGroup(List<Page> input, Block result, int position, long group) {
53-
TDigestState td = TDigestState.createOptimizedForAccuracy(QuantileStates.DEFAULT_COMPRESSION);
53+
TDigestState td = TDigestState.create(QuantileStates.DEFAULT_COMPRESSION);
5454
input.stream().flatMapToDouble(p -> allDoubles(p, group)).forEach(td::add);
5555
if (td.size() > 0) {
5656
double expected = td.quantile(percentile / 100);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected SourceOperator simpleInput(int size) {
4747

4848
@Override
4949
protected void assertSimpleOutput(List<Block> input, Block result) {
50-
TDigestState td = TDigestState.createOptimizedForAccuracy(QuantileStates.DEFAULT_COMPRESSION);
50+
TDigestState td = TDigestState.create(QuantileStates.DEFAULT_COMPRESSION);
5151
input.stream().flatMapToInt(b -> allInts(b)).forEach(td::add);
5252
double expected = td.quantile(percentile / 100);
5353
double value = ((DoubleBlock) result).getDouble(0);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected SourceOperator simpleInput(int size) {
5151

5252
@Override
5353
protected void assertSimpleGroup(List<Page> input, Block result, int position, long group) {
54-
TDigestState td = TDigestState.createOptimizedForAccuracy(QuantileStates.DEFAULT_COMPRESSION);
54+
TDigestState td = TDigestState.create(QuantileStates.DEFAULT_COMPRESSION);
5555
input.stream().flatMapToInt(p -> allInts(p, group)).forEach(td::add);
5656
if (td.size() > 0) {
5757
double expected = td.quantile(percentile / 100);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected SourceOperator simpleInput(int size) {
4747

4848
@Override
4949
protected void assertSimpleOutput(List<Block> input, Block result) {
50-
TDigestState td = TDigestState.createOptimizedForAccuracy(QuantileStates.DEFAULT_COMPRESSION);
50+
TDigestState td = TDigestState.create(QuantileStates.DEFAULT_COMPRESSION);
5151
input.stream().flatMapToLong(p -> allLongs(p)).forEach(td::add);
5252
double expected = td.quantile(percentile / 100);
5353
double value = ((DoubleBlock) result).getDouble(0);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected SourceOperator simpleInput(int size) {
5151

5252
@Override
5353
protected void assertSimpleGroup(List<Page> input, Block result, int position, long group) {
54-
TDigestState td = TDigestState.createOptimizedForAccuracy(QuantileStates.DEFAULT_COMPRESSION);
54+
TDigestState td = TDigestState.create(QuantileStates.DEFAULT_COMPRESSION);
5555
input.stream().flatMapToLong(p -> allLongs(p, group)).forEach(td::add);
5656
if (td.size() > 0) {
5757
double expected = td.quantile(percentile / 100);

x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats_percentile.csv-spec

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ FROM employees
1717

1818
// tag::percentile-result[]
1919
p0:double | p50:double | p99:double
20-
25324 | 47003 | 74984.5
20+
25324 | 47003 | 74970.29
2121
// end::percentile-result[]
2222
;
2323

@@ -26,7 +26,7 @@ percentileOfDouble
2626
from employees | stats p0 = percentile(salary_change, 0), p50 = percentile(salary_change, 50), p99 = percentile(salary_change, 99);
2727

2828
p0:double | p50:double | p99:double
29-
-9.81 | 0.75 | 14.663499999999999
29+
-9.81 | 0.75 | 14.639000000000001
3030
;
3131

3232

@@ -35,30 +35,30 @@ from employees | stats p90 = percentile(salary_change.long, 90) by job_positions
3535

3636
p90:double | job_positions:keyword
3737
7 | "Python Developer"
38-
10.399999999999999 | "Business Analyst"
39-
11 | "Accountant"
40-
11 | "Tech Lead"
38+
9.600000000000001 | "Business Analyst"
39+
10.200000000000006 | "Data Scientist"
40+
10.399999999999999 | "Senior Python Developer"
4141
;
4242

4343
percentileOfIntegerByKeyword
4444
from employees | stats p90 = percentile(salary, 90) by job_positions | sort p90 | limit 4;
4545

46-
p90:double | job_positions:keyword
47-
53397.8 | "Business Analyst"
48-
56840.4 | "Support Engineer"
49-
57565 | "Head Human Resources"
50-
61358 | "Reporting Analyst"
46+
p90:double | job_positions:keyword
47+
50249.0 | "Business Analyst"
48+
54462.0 | "Support Engineer"
49+
56308.799999999996 | "Reporting Analyst"
50+
56645.0 | "Head Human Resources"
5151
;
5252

5353

5454
percentileOfDoubleByKeyword
5555
from employees | stats p90 = percentile(salary_change, 90) by job_positions | sort p90 | limit 4;
5656

5757
p90:double | job_positions:keyword
58-
7.652 | "Python Developer"
59-
10.994999999999997 | "Business Analyst"
60-
11.301000000000002 | "Senior Team Lead"
61-
11.514000000000001 | "Data Scientist"
58+
7.5760000000000005 | "Python Developer"
59+
10.095000000000002 | "Business Analyst"
60+
10.362000000000007 | "Data Scientist"
61+
10.964999999999998 | "Senior Python Developer"
6262
;
6363

6464

0 commit comments

Comments
 (0)