From 1bec5c331c8249826735aba908484cf28315d94e Mon Sep 17 00:00:00 2001 From: Nathaniel Bauernfeind Date: Fri, 7 Jun 2024 11:20:41 -0600 Subject: [PATCH] Add LocalDate, LocalTime, LocalDateTime, ZoneDateTime Converters --- .../engine/table/impl/select/MatchFilter.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/select/MatchFilter.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/select/MatchFilter.java index 5446022278e..c5a24c5bc5c 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/select/MatchFilter.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/select/MatchFilter.java @@ -28,6 +28,10 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; import java.util.*; import java.util.stream.Stream; @@ -459,6 +463,54 @@ Object convertStringLiteral(String str) { } }; } + if (cls == LocalDate.class) { + return new ColumnTypeConvertor() { + @Override + Object convertStringLiteral(String str) { + if (str.charAt(0) != '\'' || str.charAt(str.length() - 1) != '\'') { + throw new IllegalArgumentException( + "Instant literal not enclosed in single-quotes (\"" + str + "\")"); + } + return LocalDate.parse(str.substring(1, str.length() - 1)); + } + }; + } + if (cls == LocalTime.class) { + return new ColumnTypeConvertor() { + @Override + Object convertStringLiteral(String str) { + if (str.charAt(0) != '\'' || str.charAt(str.length() - 1) != '\'') { + throw new IllegalArgumentException( + "Instant literal not enclosed in single-quotes (\"" + str + "\")"); + } + return LocalTime.parse(str.substring(1, str.length() - 1)); + } + }; + } + if (cls == LocalDateTime.class) { + return new ColumnTypeConvertor() { + @Override + Object convertStringLiteral(String str) { + if (str.charAt(0) != '\'' || str.charAt(str.length() - 1) != '\'') { + throw new IllegalArgumentException( + "Instant literal not enclosed in single-quotes (\"" + str + "\")"); + } + return LocalDateTime.parse(str.substring(1, str.length() - 1)); + } + }; + } + if (cls == ZonedDateTime.class) { + return new ColumnTypeConvertor() { + @Override + Object convertStringLiteral(String str) { + if (str.charAt(0) != '\'' || str.charAt(str.length() - 1) != '\'') { + throw new IllegalArgumentException( + "Instant literal not enclosed in single-quotes (\"" + str + "\")"); + } + return ZonedDateTime.parse(str.substring(1, str.length() - 1)); + } + }; + } if (cls == Object.class) { return new ColumnTypeConvertor() { @Override