|
52 | 52 | import java.util.function.Function; |
53 | 53 | import java.util.regex.Matcher; |
54 | 54 | import java.util.regex.Pattern; |
| 55 | +import java.util.stream.Stream; |
55 | 56 |
|
56 | 57 | import static org.elasticsearch.common.Strings.delimitedListToStringArray; |
57 | 58 | import static org.elasticsearch.common.logging.LoggerMessageFormat.format; |
@@ -147,7 +148,11 @@ void append(String stringValue) { |
147 | 148 | for (String value : arrayOfValues) { |
148 | 149 | convertedValues.add(type.convert(value)); |
149 | 150 | } |
150 | | - convertedValues.stream().sorted().forEach(v -> builderWrapper().append().accept(v)); |
| 151 | + Stream<Object> convertedValuesStream = convertedValues.stream(); |
| 152 | + if (type.sortMultiValues()) { |
| 153 | + convertedValuesStream = convertedValuesStream.sorted(); |
| 154 | + } |
| 155 | + convertedValuesStream.forEach(v -> builderWrapper().append().accept(v)); |
151 | 156 | builderWrapper().builder().endPositionEntry(); |
152 | 157 |
|
153 | 158 | return; |
@@ -486,7 +491,7 @@ public enum Type { |
486 | 491 | x -> x == null ? null : stringToAggregateMetricDoubleLiteral(x), |
487 | 492 | AggregateMetricDoubleBlockBuilder.AggregateMetricDoubleLiteral.class |
488 | 493 | ), |
489 | | - DENSE_VECTOR(Float::parseFloat, Float.class), |
| 494 | + DENSE_VECTOR(Float::parseFloat, Float.class, false), |
490 | 495 | UNSUPPORTED(Type::convertUnsupported, Void.class); |
491 | 496 |
|
492 | 497 | private static Void convertUnsupported(String s) { |
@@ -536,20 +541,35 @@ private static Void convertUnsupported(String s) { |
536 | 541 | private final Function<String, Object> converter; |
537 | 542 | private final Class<?> clazz; |
538 | 543 | private final Comparator<Object> comparator; |
| 544 | + private final boolean sortMultiValues; |
539 | 545 |
|
540 | | - @SuppressWarnings("unchecked") |
541 | 546 | Type(Function<String, Object> converter, Class<?> clazz) { |
| 547 | + this( |
| 548 | + converter, |
| 549 | + clazz, |
| 550 | + true |
| 551 | + ); |
| 552 | + } |
| 553 | + |
| 554 | + @SuppressWarnings("unchecked") |
| 555 | + Type(Function<String, Object> converter, Class<?> clazz, boolean sortMultiValues) { |
542 | 556 | this( |
543 | 557 | converter, |
544 | 558 | Comparable.class.isAssignableFrom(clazz) ? (a, b) -> ((Comparable) a).compareTo(b) : Comparator.comparing(Object::toString), |
545 | | - clazz |
| 559 | + clazz, |
| 560 | + sortMultiValues |
546 | 561 | ); |
547 | 562 | } |
548 | 563 |
|
549 | 564 | Type(Function<String, Object> converter, Comparator<Object> comparator, Class<?> clazz) { |
| 565 | + this(converter, comparator, clazz, true); |
| 566 | + } |
| 567 | + |
| 568 | + Type(Function<String, Object> converter, Comparator<Object> comparator, Class<?> clazz, boolean sortMultiValues) { |
550 | 569 | this.converter = converter; |
551 | 570 | this.comparator = comparator; |
552 | 571 | this.clazz = clazz; |
| 572 | + this.sortMultiValues = sortMultiValues; |
553 | 573 | } |
554 | 574 |
|
555 | 575 | public static Type asType(String name) { |
@@ -603,6 +623,10 @@ Class<?> clazz() { |
603 | 623 | public Comparator<Object> comparator() { |
604 | 624 | return comparator; |
605 | 625 | } |
| 626 | + |
| 627 | + public boolean sortMultiValues() { |
| 628 | + return sortMultiValues; |
| 629 | + } |
606 | 630 | } |
607 | 631 |
|
608 | 632 | record ActualResults( |
|
0 commit comments