Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading