Search in sources :

Example 1 with SqlTimeWithTimeZone

use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.

the class TestTimestampBase method testCastToTimeWithTimeZone.

@Test
public void testCastToTimeWithTimeZone() {
    assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, "03:04:05.321 " + DATE_TIME_ZONE.getID());
}
Also used : SqlTimeWithTimeZone(com.facebook.presto.common.type.SqlTimeWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with SqlTimeWithTimeZone

use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.

the class TestTimeWithTimeZoneBase method testLiteral.

@Test
public void testLiteral() {
    assertFunction("TIME '03:04:05.321 +07:09'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05 +07:09'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIME '03:04 +07:09'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 0, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIME '3:4:5.321+07:09'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIME '3:4:5+07:09'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIME '3:4+07:09'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 0, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimeWithTimeZone(com.facebook.presto.common.type.SqlTimeWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 3 with SqlTimeWithTimeZone

use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.

the class TestDateTimeOperatorsBase method testTimePlusInterval.

@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));
    assertFunction("TIME '03:04:05.321 +05:09' + INTERVAL '3' hour", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 6, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' hour + TIME '03:04:05.321 +05:09'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 6, 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("INTERVAL '3' day + TIME '03:04:05.321 +05:09'", 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("INTERVAL '3' month + TIME '03:04:05.321 +05:09'", 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("INTERVAL '3' year + TIME '03:04:05.321 +05:09'", 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 '27' hour", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 6, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '27' hour + TIME '03:04:05.321 +05:09'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 6, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimeWithTimeZone(com.facebook.presto.common.type.SqlTimeWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 4 with SqlTimeWithTimeZone

use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.

the class TestDateTimeOperators method testTimeWithTimeZoneRepresentation.

@Test
public void testTimeWithTimeZoneRepresentation() {
    // PST -> PDT date
    testTimeRepresentationOnDate(new DateTime(2017, 3, 12, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '02:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(37800000, getTimeZoneKey("America/Los_Angeles")));
    testTimeRepresentationOnDate(new DateTime(2017, 3, 12, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '03:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(41400000, getTimeZoneKey("America/Los_Angeles")));
    // PDT -> PST date
    testTimeRepresentationOnDate(new DateTime(2017, 10, 4, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '02:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(37800000, getTimeZoneKey("America/Los_Angeles")));
    testTimeRepresentationOnDate(new DateTime(2017, 10, 4, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '03:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(41400000, getTimeZoneKey("America/Los_Angeles")));
    // PDT date
    testTimeRepresentationOnDate(new DateTime(2017, 6, 6, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '02:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(37800000, getTimeZoneKey("America/Los_Angeles")));
    testTimeRepresentationOnDate(new DateTime(2017, 6, 6, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '03:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(41400000, getTimeZoneKey("America/Los_Angeles")));
    // PST date
    testTimeRepresentationOnDate(new DateTime(2017, 11, 1, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '02:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(37800000, getTimeZoneKey("America/Los_Angeles")));
    testTimeRepresentationOnDate(new DateTime(2017, 11, 1, 10, 0, 0, 0, DateTimeZone.UTC), "TIME '03:30:00.000 America/Los_Angeles'", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(41400000, getTimeZoneKey("America/Los_Angeles")));
}
Also used : SqlTimeWithTimeZone(com.facebook.presto.common.type.SqlTimeWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 5 with SqlTimeWithTimeZone

use of com.facebook.presto.common.type.SqlTimeWithTimeZone in project presto by prestodb.

the class TestDateTimeFunctionsBase method testTimeWithTimeZoneAtTimeZone.

@Test
public void testTimeWithTimeZoneAtTimeZone() {
    // this test does use hidden at_timezone function as it is equivalent of using SQL syntax AT TIME ZONE
    // but our test framework doesn't support that syntax directly.
    Session oldKathmanduTimeZoneOffsetSession = Session.builder(this.session).setTimeZoneKey(TIME_ZONE_KEY).setStartTime(new DateTime(1980, 1, 1, 10, 0, 0, DATE_TIME_ZONE).getMillis()).build();
    TimeZoneKey europeWarsawTimeZoneKey = getTimeZoneKey("Europe/Warsaw");
    DateTimeZone europeWarsawTimeZone = getDateTimeZone(europeWarsawTimeZoneKey);
    Session europeWarsawSessionWinter = Session.builder(this.session).setTimeZoneKey(europeWarsawTimeZoneKey).setStartTime(new DateTime(2017, 1, 1, 10, 0, 0, europeWarsawTimeZone).getMillis()).build();
    try (FunctionAssertions europeWarsawAssertionsWinter = new FunctionAssertions(europeWarsawSessionWinter);
        FunctionAssertions oldKathmanduTimeZoneOffsetAssertions = new FunctionAssertions(oldKathmanduTimeZoneOffsetSession)) {
        long millisTenOClockWarsawWinter = new DateTime(1970, 1, 1, 9, 0, 0, 0, UTC_TIME_ZONE).getMillis();
        // Simple shift to UTC
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '10:00 Europe/Warsaw', 'UTC')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(millisTenOClockWarsawWinter, UTC_KEY));
        // Simple shift to fixed TZ
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '10:00 Europe/Warsaw', '+00:45')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(millisTenOClockWarsawWinter, getTimeZoneKey("+00:45")));
        // Simple shift to geographical TZ
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '10:00 Europe/Warsaw', 'America/New_York')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(millisTenOClockWarsawWinter, getTimeZoneKey("America/New_York")));
        // No shift but different time zone
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '10:00 Europe/Warsaw', 'Europe/Berlin')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(millisTenOClockWarsawWinter, getTimeZoneKey("Europe/Berlin")));
        // Noop on UTC
        assertFunction("at_timezone(TIME '10:00 UTC', 'UTC')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 10, 0, 0, 0, UTC_TIME_ZONE).getMillis(), TimeZoneKey.UTC_KEY));
        // Noop on other TZ
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '10:00 Europe/Warsaw', 'Europe/Warsaw')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(millisTenOClockWarsawWinter, europeWarsawTimeZoneKey));
        // Noop on other TZ on different session TZ
        assertFunction("at_timezone(TIME '10:00 Europe/Warsaw', 'Europe/Warsaw')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(millisTenOClockWarsawWinter, europeWarsawTimeZoneKey));
        // Shift through days back
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '2:00 Europe/Warsaw', 'America/New_York')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 20, 0, 0, 0, getDateTimeZone(getTimeZoneKey("America/New_York"))).getMillis(), getTimeZoneKey("America/New_York")));
        // Shift through days forward
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '22:00 America/New_York', 'Europe/Warsaw')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 4, 0, 0, 0, europeWarsawTimeZone).getMillis(), europeWarsawTimeZoneKey));
        // Shift backward on min value
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '00:00 +14:00', '+13:00')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 23, 0, 0, 0, getDateTimeZone(getTimeZoneKey("+13:00"))).getMillis(), getTimeZoneKey("+13:00")));
        // Shift backward on min value
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '00:00 +14:00', '-14:00')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 20, 0, 0, 0, getDateTimeZone(getTimeZoneKey("-14:00"))).getMillis(), getTimeZoneKey("-14:00")));
        // Shift backward on max value
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '23:59:59.999 +14:00', '+13:00')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 22, 59, 59, 999, getDateTimeZone(getTimeZoneKey("+13:00"))).getMillis(), getTimeZoneKey("+13:00")));
        // Shift forward on max value
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '23:59:59.999 +14:00', '-14:00')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 19, 59, 59, 999, getDateTimeZone(getTimeZoneKey("-14:00"))).getMillis(), getTimeZoneKey("-14:00")));
        // Asia/Kathmandu used +5:30 TZ until 1986 and than switched to +5:45
        // This test checks if we do use offset of time zone valid currently and not the historical one
        assertFunction("at_timezone(TIME '10:00 Asia/Kathmandu', 'UTC')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 4, 15, 0, 0, UTC_TIME_ZONE).getMillis(), TimeZoneKey.UTC_KEY));
        // Noop when time zone doesn't change
        TimeZoneKey kabul = TimeZoneKey.getTimeZoneKey("Asia/Kabul");
        assertFunction("at_timezone(TIME '10:00 Asia/Kabul', 'Asia/Kabul')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 10, 0, 0, 0, getDateTimeZone(kabul)).getMillis(), kabul));
        // This test checks if the TZ offset isn't calculated on other fixed point in time by checking if
        // session started in 1980 would get historical Asia/Kathmandu offset.
        oldKathmanduTimeZoneOffsetAssertions.assertFunction("at_timezone(TIME '10:00 Asia/Kathmandu', 'UTC')", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 4, 30, 0, 0, UTC_TIME_ZONE).getMillis(), TimeZoneKey.UTC_KEY));
        // Check simple interval shift
        europeWarsawAssertionsWinter.assertFunction("at_timezone(TIME '10:00 +01:00', INTERVAL '2' HOUR)", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 11, 0, 0, 0, getDateTimeZone(getTimeZoneKey("+02:00"))).getMillis(), getTimeZoneKey("+02:00")));
        // Check to high interval shift
        europeWarsawAssertionsWinter.assertInvalidFunction("at_timezone(TIME '10:00 +01:00', INTERVAL '60' HOUR)", StandardErrorCode.INVALID_FUNCTION_ARGUMENT, "Invalid offset minutes 3600");
    }
}
Also used : SqlTimeWithTimeZone(com.facebook.presto.common.type.SqlTimeWithTimeZone) TimeZoneKey.getTimeZoneKey(com.facebook.presto.common.type.TimeZoneKey.getTimeZoneKey) TimeZoneKey(com.facebook.presto.common.type.TimeZoneKey) DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone) DateTimeZoneIndex.getDateTimeZone(com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone) TestingSession(com.facebook.presto.testing.TestingSession) Session(com.facebook.presto.Session) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) Test(org.testng.annotations.Test)

Aggregations

SqlTimeWithTimeZone (com.facebook.presto.common.type.SqlTimeWithTimeZone)10 DateTime (org.joda.time.DateTime)9 Test (org.testng.annotations.Test)9 Session (com.facebook.presto.Session)2 TimeZoneKey (com.facebook.presto.common.type.TimeZoneKey)2 TimeZoneKey.getTimeZoneKey (com.facebook.presto.common.type.TimeZoneKey.getTimeZoneKey)2 TestingSession (com.facebook.presto.testing.TestingSession)2 DateTimeZoneIndex.getDateTimeZone (com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone)2 DateTimeZone (org.joda.time.DateTimeZone)2 SqlDate (com.facebook.presto.common.type.SqlDate)1 SqlDecimal (com.facebook.presto.common.type.SqlDecimal)1 SqlTime (com.facebook.presto.common.type.SqlTime)1 SqlTimestamp (com.facebook.presto.common.type.SqlTimestamp)1 SqlTimestampWithTimeZone (com.facebook.presto.common.type.SqlTimestampWithTimeZone)1 FunctionAssertions (com.facebook.presto.operator.scalar.FunctionAssertions)1 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1