Search in sources :

Example 1 with SqlTimeWithTimeZone

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

the class TestTimeWithTimeZone 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.spi.type.SqlTimeWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with SqlTimeWithTimeZone

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

the class TestDateTimeOperators method testTimeMinusInterval.

@Test
public void testTimeMinusInterval() {
    assertFunction("TIME '03:04:05.321' - INTERVAL '3' hour", TIME, new SqlTime(new DateTime(1970, 1, 1, 0, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05.321' - INTERVAL '3' day", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05.321' - INTERVAL '3' month", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05.321' - INTERVAL '3' year", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05.321' - INTERVAL '6' hour", TIME, new SqlTime(new DateTime(1970, 1, 1, 21, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    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));
}
Also used : SqlTime(com.facebook.presto.spi.type.SqlTime) SqlTimeWithTimeZone(com.facebook.presto.spi.type.SqlTimeWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 3 with SqlTimeWithTimeZone

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

the class TestDateTimeOperators method testTimePlusInterval.

@Test
public void testTimePlusInterval() {
    assertFunction("TIME '03:04:05.321' + INTERVAL '3' hour", TIME, new SqlTime(new DateTime(1970, 1, 1, 6, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' hour + TIME '03:04:05.321'", TIME, new SqlTime(new DateTime(1970, 1, 1, 6, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05.321' + INTERVAL '3' day", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' day + TIME '03:04:05.321'", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05.321' + INTERVAL '3' month", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' month + TIME '03:04:05.321'", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05.321' + INTERVAL '3' year", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' year + TIME '03:04:05.321'", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIME '03:04:05.321' + INTERVAL '27' hour", TIME, new SqlTime(new DateTime(1970, 1, 1, 6, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '27' hour + TIME '03:04:05.321'", TIME, new SqlTime(new DateTime(1970, 1, 1, 6, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    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 : SqlTime(com.facebook.presto.spi.type.SqlTime) SqlTimeWithTimeZone(com.facebook.presto.spi.type.SqlTimeWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 4 with SqlTimeWithTimeZone

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

the class TestDateTimeFunctions method testCurrentTime.

@Test
public void testCurrentTime() throws Exception {
    long millis = new LocalTime(session.getStartTime(), DATE_TIME_ZONE).getMillisOfDay();
    functionAssertions.assertFunction("CURRENT_TIME", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(millis, session.getTimeZoneKey()));
}
Also used : LocalTime(org.joda.time.LocalTime) SqlTimeWithTimeZone(com.facebook.presto.spi.type.SqlTimeWithTimeZone) Test(org.testng.annotations.Test)

Example 5 with SqlTimeWithTimeZone

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

the class MaterializedResult method convertToJdbcTypes.

private static MaterializedRow convertToJdbcTypes(MaterializedRow prestoRow) {
    List<Object> jdbcValues = new ArrayList<>();
    for (int field = 0; field < prestoRow.getFieldCount(); field++) {
        Object prestoValue = prestoRow.getField(field);
        Object jdbcValue;
        if (prestoValue instanceof SqlDate) {
            int days = ((SqlDate) prestoValue).getDays();
            jdbcValue = new Date(TimeUnit.DAYS.toMillis(days));
        } else if (prestoValue instanceof SqlTime) {
            jdbcValue = new Time(((SqlTime) prestoValue).getMillisUtc());
        } else if (prestoValue instanceof SqlTimeWithTimeZone) {
            jdbcValue = new Time(((SqlTimeWithTimeZone) prestoValue).getMillisUtc());
        } else if (prestoValue instanceof SqlTimestamp) {
            jdbcValue = new Timestamp(((SqlTimestamp) prestoValue).getMillisUtc());
        } else if (prestoValue instanceof SqlTimestampWithTimeZone) {
            jdbcValue = new Timestamp(((SqlTimestampWithTimeZone) prestoValue).getMillisUtc());
        } else if (prestoValue instanceof SqlDecimal) {
            jdbcValue = ((SqlDecimal) prestoValue).toBigDecimal();
        } else {
            jdbcValue = prestoValue;
        }
        jdbcValues.add(jdbcValue);
    }
    return new MaterializedRow(prestoRow.getPrecision(), jdbcValues);
}
Also used : ArrayList(java.util.ArrayList) SqlTime(com.facebook.presto.spi.type.SqlTime) SqlTimeWithTimeZone(com.facebook.presto.spi.type.SqlTimeWithTimeZone) Time(java.sql.Time) SqlTime(com.facebook.presto.spi.type.SqlTime) SqlTimestamp(com.facebook.presto.spi.type.SqlTimestamp) SqlDecimal(com.facebook.presto.spi.type.SqlDecimal) SqlTimestamp(com.facebook.presto.spi.type.SqlTimestamp) Timestamp(java.sql.Timestamp) SqlDate(com.facebook.presto.spi.type.SqlDate) Date(java.sql.Date) SqlTimestampWithTimeZone(com.facebook.presto.spi.type.SqlTimestampWithTimeZone) SqlDate(com.facebook.presto.spi.type.SqlDate)

Aggregations

SqlTimeWithTimeZone (com.facebook.presto.spi.type.SqlTimeWithTimeZone)5 Test (org.testng.annotations.Test)4 SqlTime (com.facebook.presto.spi.type.SqlTime)3 DateTime (org.joda.time.DateTime)3 SqlDate (com.facebook.presto.spi.type.SqlDate)1 SqlDecimal (com.facebook.presto.spi.type.SqlDecimal)1 SqlTimestamp (com.facebook.presto.spi.type.SqlTimestamp)1 SqlTimestampWithTimeZone (com.facebook.presto.spi.type.SqlTimestampWithTimeZone)1 Date (java.sql.Date)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 LocalTime (org.joda.time.LocalTime)1