Skip to content

Commit 6bf5d89

Browse files
authored
ESQL: Use DEFAULT_UNSORTABLE topN encoder for the TSID_DATA_TYPE (#137706)
1 parent 557aeaa commit 6bf5d89

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

docs/changelog/137706.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 137706
2+
summary: Use DEFAULT_UNSORTABLE topN encoder for the TSID_DATA_TYPE
3+
area: ES|QL
4+
type: bug
5+
issues: []

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,20 @@ FROM employees
168168
avg_worked_seconds:long | birth_date:date | emp_no:i | gender:k | height:d | height.float:d | height.half_float:d | height.scaled_float:d | hire_date:date | is_rehired:bool | job_positions:k | languages:i | languages.byte:i | languages.long:l | languages.short:short | salary:i | salary_change:d | salary_change.int:i | salary_change.keyword:k | salary_change.long:l | still_hired:bool | name:k | first_name:k | last_name:k
169169
349086555 | 1961-09-01T00:00:00Z | 10056 | F | 1.57 | 1.5700000524520874 | 1.5703125 | 1.57 | 1990-02-01T00:00:00Z | [false, false, true] | [Senior Team Lead] | 2 | 2 | 2 | 2 | 33370 | [-5.17, 10.99] | [-5, 10] | [-5.17, 10.99] | [-5, 10] | true | Brendon | Bernini | Brendon
170170
;
171+
172+
sortingByTsidMetadataField
173+
required_capability: metadata_tsid_field
174+
175+
FROM k8s METADATA _tsid
176+
| SORT network.bytes_in DESC NULLS LAST
177+
| LIMIT 5
178+
| KEEP network.bytes_in, @timestamp, cluster, pod
179+
;
180+
181+
network.bytes_in:long | @timestamp:datetime | cluster:keyword | pod:keyword
182+
1021 | 2024-05-10T00:15:21.000Z | qa | two
183+
1018 | 2024-05-10T00:18:33.000Z | prod | three
184+
1009 | 2024-05-10T00:20:03.000Z | staging | two
185+
1007 | 2024-05-10T00:19:48.000Z | prod | two
186+
1006 | 2024-05-10T00:13:50.000Z | qa | one
187+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ private PhysicalOperation planTopN(TopNExec topNExec, LocalExecutionPlannerConte
485485
case VERSION -> TopNEncoder.VERSION;
486486
case DOC_DATA_TYPE -> new DocVectorEncoder(context.shardContexts);
487487
case BOOLEAN, NULL, BYTE, SHORT, INTEGER, LONG, DOUBLE, FLOAT, HALF_FLOAT, DATETIME, DATE_NANOS, DATE_PERIOD, TIME_DURATION,
488-
OBJECT, SCALED_FLOAT, UNSIGNED_LONG, TSID_DATA_TYPE -> TopNEncoder.DEFAULT_SORTABLE;
488+
OBJECT, SCALED_FLOAT, UNSIGNED_LONG -> TopNEncoder.DEFAULT_SORTABLE;
489489
case GEO_POINT, CARTESIAN_POINT, GEO_SHAPE, CARTESIAN_SHAPE, COUNTER_LONG, COUNTER_INTEGER, COUNTER_DOUBLE, SOURCE,
490-
AGGREGATE_METRIC_DOUBLE, DENSE_VECTOR, GEOHASH, GEOTILE, GEOHEX, EXPONENTIAL_HISTOGRAM ->
490+
AGGREGATE_METRIC_DOUBLE, DENSE_VECTOR, GEOHASH, GEOTILE, GEOHEX, EXPONENTIAL_HISTOGRAM, TSID_DATA_TYPE ->
491491
TopNEncoder.DEFAULT_UNSORTABLE;
492492
// unsupported fields are encoded as BytesRef, we'll use the same encoder; all values should be null at this point
493493
case PARTIAL_AGG, UNSUPPORTED -> TopNEncoder.UNSUPPORTED;

0 commit comments

Comments
 (0)