Skip to content

Commit 31ce634

Browse files
committed
update DataType
1 parent a77d9e5 commit 31ce634

File tree

1 file changed

+16
-35
lines changed
  • x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type

1 file changed

+16
-35
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -437,41 +437,22 @@ public static DataType fromEs(String name) {
437437
}
438438

439439
public static DataType fromJava(Object value) {
440-
if (value == null) {
441-
return NULL;
442-
}
443-
if (value instanceof Integer) {
444-
return INTEGER;
445-
}
446-
if (value instanceof Long) {
447-
return LONG;
448-
}
449-
if (value instanceof BigInteger) {
450-
return UNSIGNED_LONG;
451-
}
452-
if (value instanceof Boolean) {
453-
return BOOLEAN;
454-
}
455-
if (value instanceof Double) {
456-
return DOUBLE;
457-
}
458-
if (value instanceof Float) {
459-
return FLOAT;
460-
}
461-
if (value instanceof Byte) {
462-
return BYTE;
463-
}
464-
if (value instanceof Short) {
465-
return SHORT;
466-
}
467-
if (value instanceof ZonedDateTime) {
468-
return DATETIME;
469-
}
470-
if (value instanceof String || value instanceof Character || value instanceof BytesRef) {
471-
return KEYWORD;
472-
}
473-
474-
return null;
440+
return switch (value) {
441+
case null -> NULL;
442+
case Integer i -> INTEGER;
443+
case Long l -> LONG;
444+
case BigInteger bigInteger -> UNSIGNED_LONG;
445+
case Boolean b -> BOOLEAN;
446+
case Double v -> DOUBLE;
447+
case Float v -> FLOAT;
448+
case Byte b -> BYTE;
449+
case Short i -> SHORT;
450+
case ZonedDateTime zonedDateTime -> DATETIME;
451+
case String s -> KEYWORD;
452+
case Character c -> KEYWORD;
453+
case BytesRef bytesRef -> KEYWORD;
454+
default -> null;
455+
};
475456
}
476457

477458
public static boolean isUnsupported(DataType from) {

0 commit comments

Comments
 (0)