private static SqlTimestamp sqlTimestampOf(DateTime dateTime, ConnectorSession session) { return sqlTimestampOf(dateTime.getMillis(), session); }
private static SqlTimestamp intToSqlTimestamp(Integer input) { if (input == null) { return null; } return sqlTimestampOf(input, SESSION); }
private static SqlTimestamp intToSqlTimestamp(Integer input) { if (input == null) { return null; } return sqlTimestampOf(input, SESSION); }
@Test @Override public void testCastToTimestamp() { assertFunction("cast(TIME '03:04:05.321 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(1970, 1, 1, 3, 4, 5, 321, session)); } }
@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 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 testCastToTimestamp() { assertFunction("cast(DATE '2001-1-22' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, session)); }
@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 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 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 @Override public void testCastToTimestamp() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 2 /* not 3 */, 4, 5, 321, session)); // This TZ had switch in 2014 assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 Pacific/Bougainville' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 21 /* not 22 */, 23 /* not 3 */, 13, 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 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 testCastToTimestamp() { assertFunction("cast(TIME '03:04:05.321 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(1970, 1, 1, 3, 4, 5, 321, session)); } }
@Test @Override public void testCastToTimestamp() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); // This TZ had switch in 2014, so if we test for 2014 and used unpacked value we would use wrong shift assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 Pacific/Bougainville' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); } }
@Test @Override public void testCastToTimestamp() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 2 /* not 3 */, 4, 5, 321, session)); // This TZ had switch in 2014 assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 Pacific/Bougainville' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 21 /* not 22 */, 23 /* not 3 */, 13, 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 testCastToTimestamp() { assertFunction("cast(TIME '03:04:05.321' as timestamp)", TIMESTAMP, sqlTimestampOf(1970, 1, 1, 3, 4, 5, 321, session)); }
@Test public void testCastFromTimestamp() { assertFunction("cast(cast (null as timestamp) as JSON)", JSON, null); assertFunction("CAST(TIMESTAMP '1970-01-01 00:00:01' AS JSON)", JSON, format("\"%s\"", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); }
@Test public void testCastFromTimestamp() { assertFunction("cast(cast (null as timestamp) as JSON)", JSON, null); assertFunction("CAST(TIMESTAMP '1970-01-01 00:00:01' AS JSON)", JSON, format("\"%s\"", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); }