From a5ddfce7c4e225f5c6bb68f30d8c88bde337f45f Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Sun, 24 Mar 2024 19:37:27 +0100 Subject: [PATCH 1/3] Test time date_diff, date_add, date_trunc with invalid units Test `date_diff`, `date_add` and `date_trunc` functions on TIME and TIME WITH TIME ZONE types with units that are invalid. Also make error reporting consistent. --- .../operator/scalar/timetz/DateDiff.java | 2 +- .../trino/operator/scalar/time/TestTime.java | 39 +++++++++++++++++++ .../scalar/timetz/TestTimeWithTimeZone.java | 39 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/core/trino-main/src/main/java/io/trino/operator/scalar/timetz/DateDiff.java b/core/trino-main/src/main/java/io/trino/operator/scalar/timetz/DateDiff.java index ac9152feaa05..5de59916c9ed 100644 --- a/core/trino-main/src/main/java/io/trino/operator/scalar/timetz/DateDiff.java +++ b/core/trino-main/src/main/java/io/trino/operator/scalar/timetz/DateDiff.java @@ -82,7 +82,7 @@ public static long diff( case "hour": return picos / PICOSECONDS_PER_HOUR; default: - throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "'" + unitString + "' is not a TIME field"); + throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "'" + unitString + "' is not a valid TIME field"); } } } diff --git a/core/trino-main/src/test/java/io/trino/operator/scalar/time/TestTime.java b/core/trino-main/src/test/java/io/trino/operator/scalar/time/TestTime.java index 78b89efe2c8d..a3d83ee13933 100644 --- a/core/trino-main/src/test/java/io/trino/operator/scalar/time/TestTime.java +++ b/core/trino-main/src/test/java/io/trino/operator/scalar/time/TestTime.java @@ -26,10 +26,13 @@ import java.time.ZoneId; import java.time.ZonedDateTime; +import java.util.List; import java.util.function.BiFunction; import static io.trino.server.testing.TestingTrinoServer.SESSION_START_TIME_PROPERTY; +import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT; import static io.trino.spi.type.TimeType.createTimeType; +import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy; import static io.trino.type.DateTimes.PICOSECONDS_PER_SECOND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -1805,6 +1808,18 @@ public void testDateDiff() assertThat(assertions.expression("date_diff('hour', TIME '11:34:55.1111111111', TIME '12:34:56.9999999999')")).matches("BIGINT '1'"); assertThat(assertions.expression("date_diff('hour', TIME '11:34:55.11111111111', TIME '12:34:56.99999999999')")).matches("BIGINT '1'"); assertThat(assertions.expression("date_diff('hour', TIME '11:34:55.111111111111', TIME '12:34:56.999999999999')")).matches("BIGINT '1'"); + + // Units not supported on TIME, but supported on some other types + for (String unit : List.of("day", "week", "month", "quarter", "year")) { + // Short TIME + assertTrinoExceptionThrownBy(assertions.expression("date_diff('%s', TIME '00:00:00', TIME '01:00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + // Long TIME + assertTrinoExceptionThrownBy(assertions.expression("date_diff('%s', TIME '00:00:00.123456789012', TIME '01:00:00.123456789012')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + } } @Test @@ -1841,6 +1856,18 @@ public void testDateAdd() assertThat(assertions.expression("date_add('millisecond', BIGINT '365' * 24 * 60 * 60 * 1000, TIME '12:34:56.000')")).matches("TIME '12:34:56.000'"); assertThat(assertions.expression("date_add('millisecond', BIGINT '365' * 24 * 60 * 60 * 1000 + 1, TIME '12:34:56.000')")).matches("TIME '12:34:56.001'"); + + // Units not supported on TIME, but supported on some other types + for (String unit : List.of("day", "week", "month", "quarter", "year")) { + // Short TIME + assertTrinoExceptionThrownBy(assertions.expression("date_add('%s', 1, TIME '00:00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + // Long TIME + assertTrinoExceptionThrownBy(assertions.expression("date_add('%s', 1, TIME '00:00:00.123456789012')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + } } @Test @@ -1957,6 +1984,18 @@ public void testDateTrunc() assertThat(assertions.expression("date_trunc('hour', TIME '12:34:56.5555555555')")).matches("TIME '12:00:00.0000000000'"); assertThat(assertions.expression("date_trunc('hour', TIME '12:34:56.55555555555')")).matches("TIME '12:00:00.00000000000'"); assertThat(assertions.expression("date_trunc('hour', TIME '12:34:56.555555555555')")).matches("TIME '12:00:00.000000000000'"); + + // Units not supported on TIME, but supported on some other types + for (String unit : List.of("day", "week", "month", "quarter", "year")) { + // Short TIME + assertTrinoExceptionThrownBy(assertions.expression("date_trunc('%s', TIME '00:00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + // Long TIME + assertTrinoExceptionThrownBy(assertions.expression("date_trunc('%s', TIME '00:00:00.123456789012')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + } } @Test diff --git a/core/trino-main/src/test/java/io/trino/operator/scalar/timetz/TestTimeWithTimeZone.java b/core/trino-main/src/test/java/io/trino/operator/scalar/timetz/TestTimeWithTimeZone.java index 9ae784e22ae4..f86994ae2312 100644 --- a/core/trino-main/src/test/java/io/trino/operator/scalar/timetz/TestTimeWithTimeZone.java +++ b/core/trino-main/src/test/java/io/trino/operator/scalar/timetz/TestTimeWithTimeZone.java @@ -25,10 +25,13 @@ import org.junit.jupiter.api.parallel.Execution; import java.time.ZonedDateTime; +import java.util.List; import java.util.function.BiFunction; import static io.trino.server.testing.TestingTrinoServer.SESSION_START_TIME_PROPERTY; +import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT; import static io.trino.spi.type.TimeWithTimeZoneType.createTimeWithTimeZoneType; +import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy; import static io.trino.type.DateTimes.PICOSECONDS_PER_SECOND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -2099,6 +2102,18 @@ public void testDateDiff() assertThat(assertions.expression("date_diff('second', TIME '00:00:00.1234567891+14:00', TIME '00:00:00.1234567891-10:00')")).matches("BIGINT '0'"); assertThat(assertions.expression("date_diff('second', TIME '00:00:00.12345678912+14:00', TIME '00:00:00.12345678912-10:00')")).matches("BIGINT '0'"); assertThat(assertions.expression("date_diff('second', TIME '00:00:00.123456789123+14:00', TIME '00:00:00.123456789123-10:00')")).matches("BIGINT '0'"); + + // Units not supported on TIME WITH TIME ZONE, but supported on some other types + for (String unit : List.of("day", "week", "month", "quarter", "year")) { + // Short TIME WITH TIME ZONE + assertTrinoExceptionThrownBy(assertions.expression("date_diff('%s', TIME '00:00:00+00:00', TIME '01:00:00+00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + // Long TIME WITH TIME ZONE + assertTrinoExceptionThrownBy(assertions.expression("date_diff('%s', TIME '00:00:00.123456789012+00:00', TIME '01:00:00.123456789012+00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + } } @Test @@ -2156,6 +2171,18 @@ public void testDateAdd() assertThat(assertions.expression("date_add('millisecond', 900, TIME '23:59:59.1+08:35')")).matches("TIME '00:00:00.0+08:35'"); assertThat(assertions.expression("date_add('millisecond', 890, TIME '23:59:59.11+08:35')")).matches("TIME '00:00:00.00+08:35'"); assertThat(assertions.expression("date_add('millisecond', 889, TIME '23:59:59.111+08:35')")).matches("TIME '00:00:00.000+08:35'"); + + // Units not supported on TIME WITH TIME ZONE, but supported on some other types + for (String unit : List.of("day", "week", "month", "quarter", "year")) { + // Short TIME WITH TIME ZONE + assertTrinoExceptionThrownBy(assertions.expression("date_add('%s', 1, TIME '00:00:00+00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + // Long TIME WITH TIME ZONE + assertTrinoExceptionThrownBy(assertions.expression("date_add('%s', 1, TIME '00:00:00.123456789012+00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + } } @Test @@ -2272,6 +2299,18 @@ public void testDateTrunc() assertThat(assertions.expression("date_trunc('hour', TIME '12:34:56.5555555555+08:35')")).matches("TIME '12:00:00.0000000000+08:35'"); assertThat(assertions.expression("date_trunc('hour', TIME '12:34:56.55555555555+08:35')")).matches("TIME '12:00:00.00000000000+08:35'"); assertThat(assertions.expression("date_trunc('hour', TIME '12:34:56.555555555555+08:35')")).matches("TIME '12:00:00.000000000000+08:35'"); + + // Units not supported on TIME WITH TIME ZONE, but supported on some other types + for (String unit : List.of("day", "week", "month", "quarter", "year")) { + // Short TIME WITH TIME ZONE + assertTrinoExceptionThrownBy(assertions.expression("date_trunc('%s', TIME '00:00:00+00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + // Long TIME WITH TIME ZONE + assertTrinoExceptionThrownBy(assertions.expression("date_trunc('%s', TIME '00:00:00.123456789012+00:00')".formatted(unit))::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'%s' is not a valid TIME field".formatted(unit)); + } } @Test From acc654b46e09ecf7accde08684ccf3de33b93129 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Sun, 24 Mar 2024 19:37:27 +0100 Subject: [PATCH 2/3] Test timestamp date_diff, date_add with all valid units Test `date_diff` and `date_add` functions on TIMESTAMP and TIMESTAMP WITH TIME ZONE types with all valid units. Existing tests exercised only some valid units. --- .../scalar/timestamp/TestTimestamp.java | 157 ++++++++++++++++++ .../TestTimestampWithTimeZone.java | 156 +++++++++++++++++ 2 files changed, 313 insertions(+) diff --git a/core/trino-main/src/test/java/io/trino/operator/scalar/timestamp/TestTimestamp.java b/core/trino-main/src/test/java/io/trino/operator/scalar/timestamp/TestTimestamp.java index 5cdfc4502460..f186fbf873c6 100644 --- a/core/trino-main/src/test/java/io/trino/operator/scalar/timestamp/TestTimestamp.java +++ b/core/trino-main/src/test/java/io/trino/operator/scalar/timestamp/TestTimestamp.java @@ -30,6 +30,7 @@ import java.util.function.BiFunction; import static io.trino.server.testing.TestingTrinoServer.SESSION_START_TIME_PROPERTY; +import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT; import static io.trino.spi.function.OperatorType.ADD; import static io.trino.spi.function.OperatorType.EQUAL; import static io.trino.spi.function.OperatorType.INDETERMINATE; @@ -41,6 +42,7 @@ import static io.trino.spi.type.VarcharType.createVarcharType; import static io.trino.testing.TestingSession.DEFAULT_TIME_ZONE_KEY; import static io.trino.testing.TestingSession.testSessionBuilder; +import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy; import static io.trino.type.DateTimes.MICROSECONDS_PER_SECOND; import static io.trino.type.DateTimes.PICOSECONDS_PER_MICROSECOND; import static org.assertj.core.api.Assertions.assertThat; @@ -2649,6 +2651,84 @@ public void testDateDiff() assertThat(assertions.expression("date_diff('hour', TIMESTAMP '2020-05-10 11:34:55.1111111111', TIMESTAMP '2020-05-10 12:34:56.9999999999')")).matches("BIGINT '1'"); assertThat(assertions.expression("date_diff('hour', TIMESTAMP '2020-05-10 11:34:55.11111111111', TIMESTAMP '2020-05-10 12:34:56.99999999999')")).matches("BIGINT '1'"); assertThat(assertions.expression("date_diff('hour', TIMESTAMP '2020-05-10 11:34:55.111111111111', TIMESTAMP '2020-05-10 12:34:56.999999999999')")).matches("BIGINT '1'"); + + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55', TIMESTAMP '2005-09-10 13:31:00')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.1', TIMESTAMP '2005-09-10 13:31:00.9')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11', TIMESTAMP '2005-09-10 13:31:00.99')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.111', TIMESTAMP '2005-09-10 13:31:00.999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.1111', TIMESTAMP '2005-09-10 13:31:00.9999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11111', TIMESTAMP '2005-09-10 13:31:00.99999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.111111', TIMESTAMP '2005-09-10 13:31:00.999999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.1111111', TIMESTAMP '2005-09-10 13:31:00.9999999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11111111', TIMESTAMP '2005-09-10 13:31:00.99999999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.111111111', TIMESTAMP '2005-09-10 13:31:00.999999999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.1111111111', TIMESTAMP '2005-09-10 13:31:00.9999999999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11111111111', TIMESTAMP '2005-09-10 13:31:00.99999999999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11111111111', TIMESTAMP '2005-09-10 13:31:00.999999999999')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.111111111111', TIMESTAMP '2005-09-10 13:31:00.999999999999')")).matches("BIGINT '1682'"); + + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55', TIMESTAMP '2005-09-10 13:31:00')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.1', TIMESTAMP '2005-09-10 13:31:00.9')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.11', TIMESTAMP '2005-09-10 13:31:00.99')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.111', TIMESTAMP '2005-09-10 13:31:00.999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.1111', TIMESTAMP '2005-09-10 13:31:00.9999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.11111', TIMESTAMP '2005-09-10 13:31:00.99999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.111111', TIMESTAMP '2005-09-10 13:31:00.999999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.1111111', TIMESTAMP '2005-09-10 13:31:00.9999999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.11111111', TIMESTAMP '2005-09-10 13:31:00.99999999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.111111111', TIMESTAMP '2005-09-10 13:31:00.999999999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.1111111111', TIMESTAMP '2005-09-10 13:31:00.9999999999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.11111111111', TIMESTAMP '2005-09-10 13:31:00.99999999999')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.111111111111', TIMESTAMP '2005-09-10 13:31:00.999999999999')")).matches("BIGINT '240'"); + + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55', TIMESTAMP '2005-09-10 13:31:00')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.1', TIMESTAMP '2005-09-10 13:31:00.9')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.11', TIMESTAMP '2005-09-10 13:31:00.99')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.111', TIMESTAMP '2005-09-10 13:31:00.999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.1111', TIMESTAMP '2005-09-10 13:31:00.9999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.11111', TIMESTAMP '2005-09-10 13:31:00.99999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.111111', TIMESTAMP '2005-09-10 13:31:00.999999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.1111111', TIMESTAMP '2005-09-10 13:31:00.9999999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.11111111', TIMESTAMP '2005-09-10 13:31:00.99999999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.111111111', TIMESTAMP '2005-09-10 13:31:00.999999999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.1111111111', TIMESTAMP '2005-09-10 13:31:00.9999999999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.11111111111', TIMESTAMP '2005-09-10 13:31:00.99999999999')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.111111111111', TIMESTAMP '2005-09-10 13:31:00.999999999999')")).matches("BIGINT '55'"); + + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55', TIMESTAMP '2005-09-10 13:31:00')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.1', TIMESTAMP '2005-09-10 13:31:00.9')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.11', TIMESTAMP '2005-09-10 13:31:00.99')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.111', TIMESTAMP '2005-09-10 13:31:00.999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.1111', TIMESTAMP '2005-09-10 13:31:00.9999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.11111', TIMESTAMP '2005-09-10 13:31:00.99999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.111111', TIMESTAMP '2005-09-10 13:31:00.999999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.1111111', TIMESTAMP '2005-09-10 13:31:00.9999999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.11111111', TIMESTAMP '2005-09-10 13:31:00.99999999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.111111111', TIMESTAMP '2005-09-10 13:31:00.999999999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.1111111111', TIMESTAMP '2005-09-10 13:31:00.9999999999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.11111111111', TIMESTAMP '2005-09-10 13:31:00.99999999999')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.111111111111', TIMESTAMP '2005-09-10 13:31:00.999999999999')")).matches("BIGINT '18'"); + + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55', TIMESTAMP '2005-09-10 13:31:00')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.1', TIMESTAMP '2005-09-10 13:31:00.9')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.11', TIMESTAMP '2005-09-10 13:31:00.99')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.111', TIMESTAMP '2005-09-10 13:31:00.999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.1111', TIMESTAMP '2005-09-10 13:31:00.9999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.11111', TIMESTAMP '2005-09-10 13:31:00.99999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.111111', TIMESTAMP '2005-09-10 13:31:00.999999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.1111111', TIMESTAMP '2005-09-10 13:31:00.9999999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.11111111', TIMESTAMP '2005-09-10 13:31:00.99999999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.111111111', TIMESTAMP '2005-09-10 13:31:00.999999999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.1111111111', TIMESTAMP '2005-09-10 13:31:00.9999999999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.11111111111', TIMESTAMP '2005-09-10 13:31:00.99999999999')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.111111111111', TIMESTAMP '2005-09-10 13:31:00.999999999999')")).matches("BIGINT '4'"); + + assertTrinoExceptionThrownBy(assertions.expression("date_diff('foo', TIMESTAMP '2001-01-31 19:34:55', TIMESTAMP '2005-09-10 13:31:00')")::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'foo' is not a valid TIMESTAMP field"); + assertTrinoExceptionThrownBy(assertions.expression("date_diff('foo', TIMESTAMP '2001-01-31 19:34:55.111111111111', TIMESTAMP '2005-09-10 13:31:00.999999999999')")::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'foo' is not a valid TIMESTAMP field"); } @Test @@ -2712,6 +2792,83 @@ public void testDateAdd() assertThat(assertions.expression("date_add('millisecond', 1, TIMESTAMP '1500-05-10 12:34:56.5555555555')")).matches("TIMESTAMP '1500-05-10 12:34:56.5565555555'"); assertThat(assertions.expression("date_add('millisecond', 1, TIMESTAMP '1500-05-10 12:34:56.55555555555')")).matches("TIMESTAMP '1500-05-10 12:34:56.55655555555'"); assertThat(assertions.expression("date_add('millisecond', 1, TIMESTAMP '1500-05-10 12:34:56.555555555555')")).matches("TIMESTAMP '1500-05-10 12:34:56.556555555555'"); + + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00')")).matches("TIMESTAMP '2005-09-10 13:31:00'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.1')")).matches("TIMESTAMP '2005-09-10 13:31:00.1'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.11')")).matches("TIMESTAMP '2005-09-10 13:31:00.11'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.1111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.11111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.1111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.11111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.1111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.11111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.111111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111'"); + + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00')")).matches("TIMESTAMP '2005-09-10 13:31:00'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.1')")).matches("TIMESTAMP '2005-09-10 13:31:00.1'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.11')")).matches("TIMESTAMP '2005-09-10 13:31:00.11'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.1111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.11111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.1111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.11111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.1111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.11111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.111111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111'"); + + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00')")).matches("TIMESTAMP '2005-09-10 13:31:00'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.1')")).matches("TIMESTAMP '2005-09-10 13:31:00.1'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.11')")).matches("TIMESTAMP '2005-09-10 13:31:00.11'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.1111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.11111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.1111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.11111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.1111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.11111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.111111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111'"); + + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00')")).matches("TIMESTAMP '2005-09-10 13:31:00'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.1')")).matches("TIMESTAMP '2005-09-10 13:31:00.1'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.11')")).matches("TIMESTAMP '2005-09-10 13:31:00.11'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.1111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.11111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.1111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.11111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.1111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.11111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.111111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111'"); + + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00')")).matches("TIMESTAMP '2005-09-10 13:31:00'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.1')")).matches("TIMESTAMP '2005-09-10 13:31:00.1'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.11')")).matches("TIMESTAMP '2005-09-10 13:31:00.11'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.1111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.11111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.1111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.11111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.1111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.11111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.111111111111')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111'"); + + assertTrinoExceptionThrownBy(assertions.expression("date_diff('foo', TIMESTAMP '2001-01-31 19:34:55', TIMESTAMP '2005-09-10 13:31:00')")::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'foo' is not a valid TIMESTAMP field"); + assertTrinoExceptionThrownBy(assertions.expression("date_diff('foo', TIMESTAMP '2001-01-31 19:34:55.111111111111', TIMESTAMP '2005-09-10 13:31:00.999999999999')")::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'foo' is not a valid TIMESTAMP field"); } @Test diff --git a/core/trino-main/src/test/java/io/trino/operator/scalar/timestamptz/TestTimestampWithTimeZone.java b/core/trino-main/src/test/java/io/trino/operator/scalar/timestamptz/TestTimestampWithTimeZone.java index d356e9b38d5f..7abca09678f4 100644 --- a/core/trino-main/src/test/java/io/trino/operator/scalar/timestamptz/TestTimestampWithTimeZone.java +++ b/core/trino-main/src/test/java/io/trino/operator/scalar/timestamptz/TestTimestampWithTimeZone.java @@ -28,6 +28,7 @@ import java.util.function.BiFunction; import static io.trino.server.testing.TestingTrinoServer.SESSION_START_TIME_PROPERTY; +import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT; import static io.trino.spi.StandardErrorCode.INVALID_LITERAL; import static io.trino.spi.function.OperatorType.ADD; import static io.trino.spi.function.OperatorType.SUBTRACT; @@ -2402,6 +2403,84 @@ public void testDateDiff() assertThat(assertions.expression("date_diff('hour', TIMESTAMP '2020-05-10 11:34:55.1111111111 Asia/Kathmandu', TIMESTAMP '2020-05-10 12:34:56.9999999999 Asia/Kathmandu')")).matches("BIGINT '1'"); assertThat(assertions.expression("date_diff('hour', TIMESTAMP '2020-05-10 11:34:55.11111111111 Asia/Kathmandu', TIMESTAMP '2020-05-10 12:34:56.99999999999 Asia/Kathmandu')")).matches("BIGINT '1'"); assertThat(assertions.expression("date_diff('hour', TIMESTAMP '2020-05-10 11:34:55.111111111111 Asia/Kathmandu', TIMESTAMP '2020-05-10 12:34:56.999999999999 Asia/Kathmandu')")).matches("BIGINT '1'"); + + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.1 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.1111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.1111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.1111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.11111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999999 Europe/Warsaw')")).matches("BIGINT '1682'"); + assertThat(assertions.expression("date_diff('day', TIMESTAMP '2001-01-31 19:34:55.111111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999999 Europe/Warsaw')")).matches("BIGINT '1682'"); + + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.1 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.11 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.1111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.11111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.1111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.11111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.1111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.11111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999999 Europe/Warsaw')")).matches("BIGINT '240'"); + assertThat(assertions.expression("date_diff('week', TIMESTAMP '2001-01-31 19:34:55.111111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999999 Europe/Warsaw')")).matches("BIGINT '240'"); + + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.1 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.11 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.1111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.11111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.1111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.11111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.1111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.11111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999999 Europe/Warsaw')")).matches("BIGINT '55'"); + assertThat(assertions.expression("date_diff('month', TIMESTAMP '2001-01-31 19:34:55.111111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999999 Europe/Warsaw')")).matches("BIGINT '55'"); + + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.1 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.11 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.1111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.11111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.1111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.11111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.1111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.11111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999999 Europe/Warsaw')")).matches("BIGINT '18'"); + assertThat(assertions.expression("date_diff('quarter', TIMESTAMP '2001-01-31 19:34:55.111111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999999 Europe/Warsaw')")).matches("BIGINT '18'"); + + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.1 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.11 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.1111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.11111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.1111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.11111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.1111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.9999999999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.11111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.99999999999 Europe/Warsaw')")).matches("BIGINT '4'"); + assertThat(assertions.expression("date_diff('year', TIMESTAMP '2001-01-31 19:34:55.111111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999999 Europe/Warsaw')")).matches("BIGINT '4'"); + + assertTrinoExceptionThrownBy(assertions.expression("date_diff('foo', TIMESTAMP '2001-01-31 19:34:55 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw')")::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'foo' is not a valid TIMESTAMP field"); + assertTrinoExceptionThrownBy(assertions.expression("date_diff('foo', TIMESTAMP '2001-01-31 19:34:55.111111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999999 Europe/Warsaw')")::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'foo' is not a valid TIMESTAMP field"); } @Test @@ -2450,6 +2529,83 @@ public void testDateAdd() assertThat(assertions.expression("date_add('millisecond', 1, TIMESTAMP '1500-05-10 12:34:56.5555555555 Asia/Kathmandu')")).matches("TIMESTAMP '1500-05-10 12:34:56.5565555555 Asia/Kathmandu'"); assertThat(assertions.expression("date_add('millisecond', 1, TIMESTAMP '1500-05-10 12:34:56.55555555555 Asia/Kathmandu')")).matches("TIMESTAMP '1500-05-10 12:34:56.55655555555 Asia/Kathmandu'"); assertThat(assertions.expression("date_add('millisecond', 1, TIMESTAMP '1500-05-10 12:34:56.555555555555 Asia/Kathmandu')")).matches("TIMESTAMP '1500-05-10 12:34:56.556555555555 Asia/Kathmandu'"); + + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.1 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.11 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.1111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.11111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.1111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.11111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.1111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.11111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('day', 1683, TIMESTAMP '2001-01-31 13:31:00.111111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111 Europe/Warsaw'"); + + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.1 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.11 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.1111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.11111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.1111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.11111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.1111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.11111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('week', 240, TIMESTAMP '2001-02-03 13:31:00.111111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111 Europe/Warsaw'"); + + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.1 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.11 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.1111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.11111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.1111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.11111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.1111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.11111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('month', 55, TIMESTAMP '2001-02-10 13:31:00.111111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111 Europe/Warsaw'"); + + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.1 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.11 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.1111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.11111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.1111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.11111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.1111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.11111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('quarter', 18, TIMESTAMP '2001-03-10 13:31:00.111111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111 Europe/Warsaw'"); + + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.1 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.11 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.1111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.11111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.1111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.11111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.1111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.1111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.11111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.11111111111 Europe/Warsaw'"); + assertThat(assertions.expression("date_add('year', 4, TIMESTAMP '2001-09-10 13:31:00.111111111111 Europe/Warsaw')")).matches("TIMESTAMP '2005-09-10 13:31:00.111111111111 Europe/Warsaw'"); + + assertTrinoExceptionThrownBy(assertions.expression("date_diff('foo', TIMESTAMP '2001-01-31 19:34:55 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00 Europe/Warsaw')")::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'foo' is not a valid TIMESTAMP field"); + assertTrinoExceptionThrownBy(assertions.expression("date_diff('foo', TIMESTAMP '2001-01-31 19:34:55.111111111111 Europe/Warsaw', TIMESTAMP '2005-09-10 13:31:00.999999999999 Europe/Warsaw')")::evaluate) + .hasErrorCode(INVALID_FUNCTION_ARGUMENT) + .hasMessage("'foo' is not a valid TIMESTAMP field"); } @Test From 5a6f4b240313f8dec8390e38f832ad68742da013 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Sun, 24 Mar 2024 22:32:57 -0700 Subject: [PATCH 3/3] =?UTF-8?q?empty:=20roll=20the=20dice=20=F0=9F=8E=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit