|
@@ -22,6 +22,7 @@ import static org.elasticsearch.xpack.ql.expression.function.scalar.FunctionTest
|
|
|
import static org.elasticsearch.xpack.ql.expression.function.scalar.FunctionTestUtils.randomStringLiteral;
|
|
|
import static org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeTestUtils.dateTime;
|
|
|
import static org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeTestUtils.time;
|
|
|
+import static org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeTestUtils.date;
|
|
|
|
|
|
public class DateTimeParseProcessorTests extends AbstractSqlWireSerializingTestCase<DateTimeParseProcessor> {
|
|
|
|
|
@@ -87,7 +88,7 @@ public class DateTimeParseProcessorTests extends AbstractSqlWireSerializingTestC
|
|
|
() -> new DateTimeParse(Source.EMPTY, l("2020-04-07"), l("MM/dd"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
);
|
|
|
assertEquals(
|
|
|
- "Invalid datetime string [2020-04-07] or pattern [MM/dd] is received; Text '2020-04-07' could not be parsed at index 2",
|
|
|
+ "Invalid datetime string [2020-04-07] or pattern [MM/dd] is received; Text '2020-04-07' could not be parsed at index 2",
|
|
|
siae.getMessage()
|
|
|
);
|
|
|
|
|
@@ -113,44 +114,98 @@ public class DateTimeParseProcessorTests extends AbstractSqlWireSerializingTestC
|
|
|
|
|
|
public void testTimeInvalidInputs() {
|
|
|
SqlIllegalArgumentException siae = expectThrows(
|
|
|
- SqlIllegalArgumentException.class,
|
|
|
- () -> new TimeParse(Source.EMPTY, l(10), randomStringLiteral(), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new TimeParse(Source.EMPTY, l(10), randomStringLiteral(), randomZone()).makePipe().asProcessor().process(null)
|
|
|
);
|
|
|
assertEquals("A string is required; received [10]", siae.getMessage());
|
|
|
|
|
|
siae = expectThrows(
|
|
|
- SqlIllegalArgumentException.class,
|
|
|
- () -> new TimeParse(Source.EMPTY, randomStringLiteral(), l(20), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new TimeParse(Source.EMPTY, randomStringLiteral(), l(20), randomZone()).makePipe().asProcessor().process(null)
|
|
|
);
|
|
|
assertEquals("A string is required; received [20]", siae.getMessage());
|
|
|
|
|
|
siae = expectThrows(
|
|
|
- SqlIllegalArgumentException.class,
|
|
|
- () -> new TimeParse(Source.EMPTY, l("11:04:07"), l("invalid"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new TimeParse(Source.EMPTY, l("11:04:07"), l("invalid"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
);
|
|
|
assertEquals(
|
|
|
- "Invalid time string [11:04:07] or pattern [invalid] is received; Unknown pattern letter: i",
|
|
|
- siae.getMessage()
|
|
|
+ "Invalid time string [11:04:07] or pattern [invalid] is received; Unknown pattern letter: i",
|
|
|
+ siae.getMessage()
|
|
|
);
|
|
|
|
|
|
siae = expectThrows(
|
|
|
- SqlIllegalArgumentException.class,
|
|
|
- () -> new TimeParse(Source.EMPTY, l("11:04:07"), l("HH:mm"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new TimeParse(Source.EMPTY, l("11:04:07"), l("HH:mm"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
);
|
|
|
assertEquals(
|
|
|
- "Invalid time string [11:04:07] or pattern [HH:mm] is received; " +
|
|
|
- "Text '11:04:07' could not be parsed, unparsed text found at index 5",
|
|
|
- siae.getMessage()
|
|
|
+ "Invalid time string [11:04:07] or pattern [HH:mm] is received; " +
|
|
|
+ "Text '11:04:07' could not be parsed, unparsed text found at index 5",
|
|
|
+ siae.getMessage()
|
|
|
);
|
|
|
|
|
|
siae = expectThrows(
|
|
|
- SqlIllegalArgumentException.class,
|
|
|
- () -> new TimeParse(Source.EMPTY, l("07/05/2020"), l("dd/MM/uuuu"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new TimeParse(Source.EMPTY, l("07/05/2020"), l("dd/MM/uuuu"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
);
|
|
|
assertEquals(
|
|
|
- "Invalid time string [07/05/2020] or pattern [dd/MM/uuuu] is received; Unable to convert parsed text into [time]",
|
|
|
+ "Invalid time string [07/05/2020] or pattern [dd/MM/uuuu] is received; Unable to convert parsed text into [time]",
|
|
|
+ siae.getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testDateInvalidInputs() {
|
|
|
+ SqlIllegalArgumentException siae = expectThrows(
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new DateParse(Source.EMPTY, l(10), randomStringLiteral(), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ );
|
|
|
+ assertEquals("A string is required; received [10]", siae.getMessage());
|
|
|
+
|
|
|
+ siae = expectThrows(
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new DateParse(Source.EMPTY, randomStringLiteral(), l(20), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ );
|
|
|
+ assertEquals("A string is required; received [20]", siae.getMessage());
|
|
|
+
|
|
|
+ siae = expectThrows(
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new DateParse(Source.EMPTY, l("07/05/2020"), l("invalid"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ );
|
|
|
+ assertEquals(
|
|
|
+ "Invalid date string [07/05/2020] or pattern [invalid] is received; Unknown pattern letter: i",
|
|
|
siae.getMessage()
|
|
|
);
|
|
|
+
|
|
|
+ siae = expectThrows(
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new DateParse(Source.EMPTY, l("07/05/2020"), l("dd/MM"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ );
|
|
|
+ assertEquals(
|
|
|
+ "Invalid date string [07/05/2020] or pattern [dd/MM] is received; " +
|
|
|
+ "Text '07/05/2020' could not be parsed, unparsed text found at index 5",
|
|
|
+ siae.getMessage()
|
|
|
+ );
|
|
|
+
|
|
|
+ siae = expectThrows(
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new DateParse(Source.EMPTY, l("11:04:07"), l("HH:mm:ss"), randomZone()).makePipe().asProcessor().process(null)
|
|
|
+ );
|
|
|
+ assertEquals(
|
|
|
+ "Invalid date string [11:04:07] or pattern [HH:mm:ss] is received; Unable to convert parsed text into [date]",
|
|
|
+ siae.getMessage()
|
|
|
+ );
|
|
|
+
|
|
|
+ siae = expectThrows(
|
|
|
+ SqlIllegalArgumentException.class,
|
|
|
+ () -> new DateParse(Source.EMPTY, l("05/2020 11:04:07"), l("MM/uuuu HH:mm:ss"), randomZone())
|
|
|
+ .makePipe()
|
|
|
+ .asProcessor()
|
|
|
+ .process(null)
|
|
|
+ );
|
|
|
+ assertEquals(
|
|
|
+ "Invalid date string [05/2020 11:04:07] or pattern [MM/uuuu HH:mm:ss] is received; Unable to convert parsed text into [date]",
|
|
|
+ siae.getMessage()
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public void testWithNulls() {
|
|
@@ -164,6 +219,11 @@ public class DateTimeParseProcessorTests extends AbstractSqlWireSerializingTestC
|
|
|
assertNull(new TimeParse(Source.EMPTY, randomStringLiteral(), l(""), randomZone()).makePipe().asProcessor().process(null));
|
|
|
assertNull(new TimeParse(Source.EMPTY, NULL, randomStringLiteral(), randomZone()).makePipe().asProcessor().process(null));
|
|
|
assertNull(new TimeParse(Source.EMPTY, l(""), randomStringLiteral(), randomZone()).makePipe().asProcessor().process(null));
|
|
|
+ // DateParse
|
|
|
+ assertNull(new DateParse(Source.EMPTY, randomStringLiteral(), NULL, randomZone()).makePipe().asProcessor().process(null));
|
|
|
+ assertNull(new DateParse(Source.EMPTY, randomStringLiteral(), l(""), randomZone()).makePipe().asProcessor().process(null));
|
|
|
+ assertNull(new DateParse(Source.EMPTY, NULL, randomStringLiteral(), randomZone()).makePipe().asProcessor().process(null));
|
|
|
+ assertNull(new DateParse(Source.EMPTY, l(""), randomStringLiteral(), randomZone()).makePipe().asProcessor().process(null));
|
|
|
}
|
|
|
|
|
|
public void testParsing() {
|
|
@@ -203,6 +263,19 @@ public class DateTimeParseProcessorTests extends AbstractSqlWireSerializingTestC
|
|
|
.asProcessor()
|
|
|
.process(null)
|
|
|
);
|
|
|
+ // DateParse
|
|
|
+ assertEquals(
|
|
|
+ date(2020, 4, 7, zoneId),
|
|
|
+ new DateParse(Source.EMPTY, l("07/04/2020"), l("dd/MM/uuuu"), zoneId).makePipe()
|
|
|
+ .asProcessor()
|
|
|
+ .process(null)
|
|
|
+ );
|
|
|
+ assertEquals(
|
|
|
+ date(2020, 4, 7, zoneId),
|
|
|
+ new DateParse(Source.EMPTY, l("07/04/2020 12:12:00"), l("dd/MM/uuuu HH:mm:ss"), zoneId).makePipe()
|
|
|
+ .asProcessor()
|
|
|
+ .process(null)
|
|
|
+ );
|
|
|
assertEquals(
|
|
|
time(10, 20, 30, 123456789, ZoneOffset.of("+05:30"), zoneId),
|
|
|
new TimeParse(Source.EMPTY, l("16/06/2020 10:20:30.123456789 +05:30"), l("dd/MM/uuuu HH:mm:ss.SSSSSSSSS zz"), zoneId).makePipe()
|