Skip to content

Commit b05a107

Browse files
committed
ESQL: Use DEFAULT_UNSORTABLE topN encoder for the TSID_DATA_TYPE
1 parent afd3a42 commit b05a107

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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 events_received ASC
177+
| LIMIT 5
178+
| KEEP events_received, @timestamp, cluster, pod
179+
;
180+
181+
events_received:long | @timestamp:datetime | cluster:keyword | pod:keyword
182+
0 | 2024-05-10T00:04:49.000Z | qa | one
183+
0 | 2024-05-10T00:02:43.000Z | staging | two
184+
0 | 2024-05-10T00:03:13.000Z | staging | one
185+
0 | 2024-05-10T00:07:33.000Z | qa | two
186+
0 | 2024-05-10T00:05:16.000Z | prod | 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)