|
18 | 18 | import org.elasticsearch.xpack.esql.core.tree.NodeInfo; |
19 | 19 | import org.elasticsearch.xpack.esql.core.tree.Source; |
20 | 20 | import org.elasticsearch.xpack.esql.core.type.DataType; |
| 21 | +import org.elasticsearch.xpack.esql.core.type.DataTypeConverter; |
21 | 22 | import org.elasticsearch.xpack.esql.expression.Foldables; |
22 | 23 | import org.elasticsearch.xpack.esql.expression.function.Example; |
23 | 24 | import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo; |
|
40 | 41 | import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER; |
41 | 42 | import static org.elasticsearch.xpack.esql.core.type.DataType.LONG; |
42 | 43 | import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG; |
43 | | -import static org.elasticsearch.xpack.esql.core.type.DataTypeConverter.safeToLong; |
44 | 44 | import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.commonType; |
45 | 45 |
|
46 | 46 | /** |
@@ -200,17 +200,25 @@ interface Build { |
200 | 200 | ); |
201 | 201 |
|
202 | 202 | public static List<Object> sortedRoundingPoints(List<Object> points, DataType dataType) { |
203 | | - return points.stream().filter(Objects::nonNull).map(p -> switch (dataType) { // the types are in sync with SIGNATURES |
204 | | - case INTEGER -> ((Number) p).intValue(); |
205 | | - case DOUBLE -> ((Number) p).doubleValue(); |
206 | | - case LONG, DATETIME, DATE_NANOS -> safeToLong((Number) p); |
| 203 | + List<Number> pointsTobeSorted = points.stream().filter(Objects::nonNull).map(p -> (Number) p).toList(); |
| 204 | + |
| 205 | + return switch (dataType) { |
| 206 | + case INTEGER -> pointsTobeSorted.stream() |
| 207 | + .mapToInt(Number::intValue) |
| 208 | + .sorted() |
| 209 | + .boxed() |
| 210 | + .collect(java.util.stream.Collectors.toList()); |
| 211 | + case DOUBLE -> pointsTobeSorted.stream() |
| 212 | + .mapToDouble(Number::doubleValue) |
| 213 | + .sorted() |
| 214 | + .boxed() |
| 215 | + .collect(java.util.stream.Collectors.toList()); |
| 216 | + case LONG, DATETIME, DATE_NANOS -> pointsTobeSorted.stream() |
| 217 | + .mapToLong(DataTypeConverter::safeToLong) |
| 218 | + .sorted() |
| 219 | + .boxed() |
| 220 | + .collect(java.util.stream.Collectors.toList()); |
207 | 221 | default -> throw new IllegalArgumentException("Unsupported data type: " + dataType); |
208 | | - }).sorted((a, b) -> { |
209 | | - if (a instanceof Double || b instanceof Double) { |
210 | | - return Double.compare(a.doubleValue(), b.doubleValue()); |
211 | | - } else { |
212 | | - return Long.compare(a.longValue(), b.longValue()); |
213 | | - } |
214 | | - }).collect(java.util.stream.Collectors.toList()); |
| 222 | + }; |
215 | 223 | } |
216 | 224 | } |
0 commit comments