Skip to content

Commit bdece4f

Browse files
update according to review comments
1 parent edbd545 commit bdece4f

File tree

1 file changed

+20
-12
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math

1 file changed

+20
-12
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundTo.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1919
import org.elasticsearch.xpack.esql.core.tree.Source;
2020
import org.elasticsearch.xpack.esql.core.type.DataType;
21+
import org.elasticsearch.xpack.esql.core.type.DataTypeConverter;
2122
import org.elasticsearch.xpack.esql.expression.Foldables;
2223
import org.elasticsearch.xpack.esql.expression.function.Example;
2324
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo;
@@ -40,7 +41,6 @@
4041
import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER;
4142
import static org.elasticsearch.xpack.esql.core.type.DataType.LONG;
4243
import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG;
43-
import static org.elasticsearch.xpack.esql.core.type.DataTypeConverter.safeToLong;
4444
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.commonType;
4545

4646
/**
@@ -200,17 +200,25 @@ interface Build {
200200
);
201201

202202
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());
207221
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+
};
215223
}
216224
}

0 commit comments

Comments
 (0)