Skip to content

Commit e64757a

Browse files
committed
move code
1 parent 8ee236e commit e64757a

File tree

1 file changed

+12
-15
lines changed
  • x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql

1 file changed

+12
-15
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,13 @@ public static ExpectedResults loadCsvSpecValues(String csv) {
407407
// split on commas but ignoring escaped commas
408408
String[] multiValues = value.substring(1, value.length() - 1).split(COMMA_ESCAPING_REGEX);
409409
if (multiValues.length == 1) {
410-
rowValues.add(convert(multiValues[0].replace(ESCAPED_COMMA_SEQUENCE, ","), columnTypes.get(i)));
410+
rowValues.add(columnTypes.get(i).convert(multiValues[0].replace(ESCAPED_COMMA_SEQUENCE, ",")));
411411
continue;
412412
}
413413
List<Object> listOfMvValues = new ArrayList<>();
414414
for (String mvValue : multiValues) {
415415
try {
416-
listOfMvValues.add(convert(mvValue.trim().replace(ESCAPED_COMMA_SEQUENCE, ","), columnTypes.get(i)));
416+
listOfMvValues.add(columnTypes.get(i).convert(mvValue.trim().replace(ESCAPED_COMMA_SEQUENCE, ",")));
417417
} catch (IllegalArgumentException e) {
418418
throw new IllegalArgumentException(
419419
"Error parsing multi-value field ["
@@ -431,7 +431,7 @@ public static ExpectedResults loadCsvSpecValues(String csv) {
431431
} else {
432432
// The value considered here is the one where any potential escaped comma is kept as is (with the escape char)
433433
// TODO if we'd want escaped commas outside multi-values fields, we'd have to adjust this value here as well
434-
rowValues.add(convert(value, columnTypes.get(i)));
434+
rowValues.add(columnTypes.get(i).convert(value));
435435
}
436436
}
437437
values.add(rowValues);
@@ -443,17 +443,6 @@ public static ExpectedResults loadCsvSpecValues(String csv) {
443443
}
444444
}
445445

446-
private static Object convert(String value, Type type) {
447-
if (Number.class.isAssignableFrom(type.clazz()) && value.startsWith("<") && value.endsWith(">") && value.contains("-")) {
448-
// Numbers of the form "<lower-upper>" are parsed to a Range.
449-
int separator = value.indexOf('-');
450-
Object lowerBound = type.converter.apply(value.substring(1, separator).trim());
451-
Object upperBound = type.converter.apply(value.substring(separator + 1, value.length() - 1).trim());
452-
return new Range(lowerBound, upperBound);
453-
}
454-
return type.converter.apply(value);
455-
}
456-
457446
private static final String TYPECAST_SPACER = "__TYPECAST__";
458447

459448
private static String escapeTypecast(String typecast) {
@@ -635,7 +624,15 @@ Object convert(String value) {
635624
if (value == null) {
636625
return null;
637626
}
638-
return converter.apply(value);
627+
if (Number.class.isAssignableFrom(clazz) && value.startsWith("<") && value.endsWith(">") && value.contains("-")) {
628+
// Numbers of the form "<lower-upper>" are parsed to a Range.
629+
int separator = value.indexOf('-');
630+
Object lowerBound = converter.apply(value.substring(1, separator).trim());
631+
Object upperBound = converter.apply(value.substring(separator + 1, value.length() - 1).trim());
632+
return new Range(lowerBound, upperBound);
633+
} else {
634+
return converter.apply(value);
635+
}
639636
}
640637

641638
Class<?> clazz() {

0 commit comments

Comments
 (0)