Skip to content

Commit 4b2126e

Browse files
committed
Add CSV tests with unordered data, and fix CSV data retrieval for that case
1 parent f5889b2 commit 4b2126e

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestUtils.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.function.Function;
5353
import java.util.regex.Matcher;
5454
import java.util.regex.Pattern;
55+
import java.util.stream.Stream;
5556

5657
import static org.elasticsearch.common.Strings.delimitedListToStringArray;
5758
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
@@ -147,7 +148,11 @@ void append(String stringValue) {
147148
for (String value : arrayOfValues) {
148149
convertedValues.add(type.convert(value));
149150
}
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));
151156
builderWrapper().builder().endPositionEntry();
152157

153158
return;
@@ -486,7 +491,7 @@ public enum Type {
486491
x -> x == null ? null : stringToAggregateMetricDoubleLiteral(x),
487492
AggregateMetricDoubleBlockBuilder.AggregateMetricDoubleLiteral.class
488493
),
489-
DENSE_VECTOR(Float::parseFloat, Float.class),
494+
DENSE_VECTOR(Float::parseFloat, Float.class, false),
490495
UNSUPPORTED(Type::convertUnsupported, Void.class);
491496

492497
private static Void convertUnsupported(String s) {
@@ -536,20 +541,35 @@ private static Void convertUnsupported(String s) {
536541
private final Function<String, Object> converter;
537542
private final Class<?> clazz;
538543
private final Comparator<Object> comparator;
544+
private final boolean sortMultiValues;
539545

540-
@SuppressWarnings("unchecked")
541546
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) {
542556
this(
543557
converter,
544558
Comparable.class.isAssignableFrom(clazz) ? (a, b) -> ((Comparable) a).compareTo(b) : Comparator.comparing(Object::toString),
545-
clazz
559+
clazz,
560+
sortMultiValues
546561
);
547562
}
548563

549564
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) {
550569
this.converter = converter;
551570
this.comparator = comparator;
552571
this.clazz = clazz;
572+
this.sortMultiValues = sortMultiValues;
553573
}
554574

555575
public static Type asType(String name) {
@@ -603,6 +623,10 @@ Class<?> clazz() {
603623
public Comparator<Object> comparator() {
604624
return comparator;
605625
}
626+
627+
public boolean sortMultiValues() {
628+
return sortMultiValues;
629+
}
606630
}
607631

608632
record ActualResults(
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
id:l, vector:dense_vector
22
0, [1.0, 2.0, 3.0]
33
1, [4.0, 5.0, 6.0]
4+
2, [9.0, 8.0, 7.0]
5+
3, [0.054, 0.032, 0.012]

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

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ FROM dense_vector
1010
id:l | vector:dense_vector
1111
0 | [1.0, 2.0, 3.0]
1212
1 | [4.0, 5.0, 6.0]
13+
2 | [9.0, 8.0, 7.0]
14+
3 | [0.054, 0.032, 0.012]
1315
;
1416

1517
denseVectorWithEval
@@ -24,6 +26,8 @@ FROM dense_vector
2426
id:l | v:dense_vector
2527
0 | [1.0, 2.0, 3.0]
2628
1 | [4.0, 5.0, 6.0]
29+
2 | [9.0, 8.0, 7.0]
30+
3 | [0.054, 0.032, 0.012]
2731
;
2832

2933
denseVectorWithRenameAndDrop
@@ -39,4 +43,6 @@ FROM dense_vector
3943
id:l | new_vector:dense_vector
4044
0 | [1.0, 2.0, 3.0]
4145
1 | [4.0, 5.0, 6.0]
46+
2 | [9.0, 8.0, 7.0]
47+
3 | [0.054, 0.032, 0.012]
4248
;

0 commit comments

Comments
 (0)