private static SqlTimestamp sqlTimestampOf(DateTime dateTime, ConnectorSession session) { return sqlTimestampOf(dateTime.getMillis(), session); }
private SqlTime toTime(LocalTime time) { return sqlTimeOf(time, session); }
Session session) return sqlTimestampOf( year, monthOfYear, return new SqlTimestamp(new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond, baseZone).getMillis(), timestampZone); return sqlTimestampOf(LocalDateTime.of(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisToNanos(millisOfSecond)));
public static SqlTime sqlTimeOf( int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond, Session session) { LocalTime time = LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute, millisToNanos(millisOfSecond)); return sqlTimeOf(time, session); }
private static SqlTimestamp intToSqlTimestamp(Integer input) { if (input == null) { return null; } return sqlTimestampOf(input, SESSION); }
@Test @Override public void testCastToTime() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time)", TIME, sqlTimeOf(2 /* not 3 */, 4, 5, 321, session)); }
public static SqlTimestamp sqlTimestampOf(DateTime dateTime, Session session) { return sqlTimestampOf(dateTime, session.toConnectorSession()); }
@Test @Override public void testCastToTime() { assertFunction("cast(TIME '03:04:05.321 +07:09' as time)", TIME, sqlTimeOf(3, 4, 5, 321, session)); }
@Test public void testGreatest() { assertFunction("greatest(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05')", TIMESTAMP, sqlTimestampOf(2013, 3, 30, 1, 5, 0, 0, session)); assertFunction("greatest(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05', TIMESTAMP '2012-05-01 01:05')", TIMESTAMP, sqlTimestampOf(2013, 3, 30, 1, 5, 0, 0, session)); }
@Test @Override public void testCastToTime() { assertFunction("cast(TIME '03:04:05.321 +07:09' as time)", TIME, sqlTimeOf(2 /* not 3 */, 4, 5, 321, session)); }
@Test @Override public void testCastToTimestamp() { assertFunction("cast(TIME '03:04:05.321 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(1970, 1, 1, 2 /* not 3 */, 4, 5, 321, session)); } }
@Test public void testCastToTime() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as time)", TIME, sqlTimeOf(3, 4, 5, 321, session)); }
@Test public void testCastToTimestamp() { assertFunction("cast(TIME '03:04:05.321' as timestamp)", TIMESTAMP, sqlTimestampOf(1970, 1, 1, 3, 4, 5, 321, session)); }
@Test public void testLiteral() { assertFunction("TIME '03:04:05.321'", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05'", TIME, sqlTimeOf(3, 4, 5, 0, session)); assertFunction("TIME '03:04'", TIME, sqlTimeOf(3, 4, 0, 0, session)); assertInvalidFunction("TIME 'text'", SemanticErrorCode.INVALID_LITERAL, "line 1:1: 'text' is not a valid time literal"); }
@Test public void testLeast() { assertFunction("least(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05')", TIMESTAMP, sqlTimestampOf(2012, 3, 30, 1, 5, 0, 0, session)); assertFunction("least(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05', TIMESTAMP '2012-05-01 01:05')", TIMESTAMP, sqlTimestampOf(2012, 3, 30, 1, 5, 0, 0, session)); }
@Test @Override public void testCastToTime() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time)", TIME, sqlTimeOf(3, 4, 5, 321, session)); functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time)", TIME, "03:04:05.321"); }
@Test public void testFromUnixTime() { DateTime dateTime = new DateTime(2001, 1, 22, 3, 4, 5, 0, DATE_TIME_ZONE); double seconds = dateTime.getMillis() / 1000.0; assertFunction("from_unixtime(" + seconds + ")", TimestampType.TIMESTAMP, sqlTimestampOf(dateTime, session)); dateTime = new DateTime(2001, 1, 22, 3, 4, 5, 888, DATE_TIME_ZONE); seconds = dateTime.getMillis() / 1000.0; assertFunction("from_unixtime(" + seconds + ")", TimestampType.TIMESTAMP, sqlTimestampOf(dateTime, session)); }
@Test public void testTimeMinusInterval() { assertFunction("TIME '03:04:05.321' - INTERVAL '3' hour", TIME, sqlTimeOf(0, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' - INTERVAL '3' day", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' - INTERVAL '3' month", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' - INTERVAL '3' year", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' - INTERVAL '6' hour", TIME, sqlTimeOf(21, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' hour", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 0, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' day", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' month", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' year", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '6' hour", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 21, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); }
@Test public void testCastToTimestamp() { assertFunction("cast(DATE '2001-1-22' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, session)); }
@Test public void testTimePlusInterval() assertFunction("TIME '03:04:05.321' + INTERVAL '3' hour", TIME, sqlTimeOf(6, 4, 5, 321, session)); assertFunction("INTERVAL '3' hour + TIME '03:04:05.321'", TIME, sqlTimeOf(6, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' + INTERVAL '3' day", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("INTERVAL '3' day + TIME '03:04:05.321'", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' + INTERVAL '3' month", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("INTERVAL '3' month + TIME '03:04:05.321'", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' + INTERVAL '3' year", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("INTERVAL '3' year + TIME '03:04:05.321'", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' + INTERVAL '27' hour", TIME, sqlTimeOf(6, 4, 5, 321, session)); assertFunction("INTERVAL '27' hour + TIME '03:04:05.321'", TIME, sqlTimeOf(6, 4, 5, 321, session));