Search in sources :

Example 6 with SqlTimestampWithTimeZone

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

the class TestTimestampWithTimeZoneBase method testLeast.

@Test
public void testLeast() {
    assertFunction("least(TIMESTAMP '2001-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 01:04:05.321 +02:09', TIMESTAMP '2002-01-02 01:04:05.321 +02:09')", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("least(TIMESTAMP '2001-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 01:04:05.321 +02:09')", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 7 with SqlTimestampWithTimeZone

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

the class TestTimestampWithTimeZoneBase method testCastFromSlice.

@Test
public void testCastFromSlice() {
    assertFunction("cast('2001-1-22 03:04:05.321' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04:05' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 0, 0, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04:05.321 +07:09' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04:05 +07:09' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04 +07:09' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 0, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 +07:09' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 0, 0, 0, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04:05.321 Europe/Berlin' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04:05 Europe/Berlin' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 0, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04 Europe/Berlin' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 0, 0, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 Europe/Berlin' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 0, 0, 0, 0, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("cast('\n\t 2001-1-22 03:04:05.321 Europe/Berlin' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("cast('2001-1-22 03:04:05.321 Europe/Berlin \t\n' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("cast('\n\t 2001-1-22 03:04:05.321 Europe/Berlin \t\n' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 8 with SqlTimestampWithTimeZone

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

the class MaterializedResult method convertToTestTypes.

private static MaterializedRow convertToTestTypes(MaterializedRow prestoRow) {
    List<Object> convertedValues = new ArrayList<>();
    for (int field = 0; field < prestoRow.getFieldCount(); field++) {
        Object prestoValue = prestoRow.getField(field);
        Object convertedValue;
        if (prestoValue instanceof SqlDate) {
            convertedValue = LocalDate.ofEpochDay(((SqlDate) prestoValue).getDays());
        } else if (prestoValue instanceof SqlTime) {
            convertedValue = DateTimeFormatter.ISO_LOCAL_TIME.parse(prestoValue.toString(), LocalTime::from);
        } else if (prestoValue instanceof SqlTimeWithTimeZone) {
            // Political timezone cannot be represented in OffsetTime and there isn't any better representation.
            long millisUtc = ((SqlTimeWithTimeZone) prestoValue).getMillisUtc();
            ZoneOffset zone = toZoneOffset(((SqlTimeWithTimeZone) prestoValue).getTimeZoneKey());
            convertedValue = OffsetTime.of(LocalTime.ofNanoOfDay(MILLISECONDS.toNanos(millisUtc) + SECONDS.toNanos(zone.getTotalSeconds())), zone);
        } else if (prestoValue instanceof SqlTimestamp) {
            convertedValue = SqlTimestamp.JSON_FORMATTER.parse(prestoValue.toString(), LocalDateTime::from);
        } else if (prestoValue instanceof SqlTimestampWithTimeZone) {
            convertedValue = Instant.ofEpochMilli(((SqlTimestampWithTimeZone) prestoValue).getMillisUtc()).atZone(ZoneId.of(((SqlTimestampWithTimeZone) prestoValue).getTimeZoneKey().getId()));
        } else if (prestoValue instanceof SqlDecimal) {
            convertedValue = ((SqlDecimal) prestoValue).toBigDecimal();
        } else {
            convertedValue = prestoValue;
        }
        convertedValues.add(convertedValue);
    }
    return new MaterializedRow(prestoRow.getPrecision(), convertedValues);
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) ArrayList(java.util.ArrayList) SqlTime(com.facebook.presto.common.type.SqlTime) SqlTimeWithTimeZone(com.facebook.presto.common.type.SqlTimeWithTimeZone) SqlTimestamp(com.facebook.presto.common.type.SqlTimestamp) SqlDecimal(com.facebook.presto.common.type.SqlDecimal) ZoneOffset(java.time.ZoneOffset) SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) SqlDate(com.facebook.presto.common.type.SqlDate)

Example 9 with SqlTimestampWithTimeZone

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

the class TestDateTimeOperatorsBase method testTimestampMinusInterval.

@Test
public void testTimestampMinusInterval() {
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' - INTERVAL '3' day", TIMESTAMP, sqlTimestampOf(2001, 1, 19, 3, 4, 5, 321, session));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' - INTERVAL '3' day", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 19, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' - INTERVAL '3' month", TIMESTAMP, sqlTimestampOf(2000, 10, 22, 3, 4, 5, 321, session));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' - INTERVAL '3' month", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2000, 10, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 10 with SqlTimestampWithTimeZone

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

the class TestTimestampWithTimeZoneBase method testGreatest.

@Test
public void testGreatest() {
    assertFunction("greatest(TIMESTAMP '2002-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 01:04:05.321 +02:09', TIMESTAMP '2000-01-02 01:04:05.321 +02:09')", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2002, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("greatest(TIMESTAMP '2001-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 04:04:05.321 +10:09')", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

SqlTimestampWithTimeZone (com.facebook.presto.common.type.SqlTimestampWithTimeZone)11 Test (org.testng.annotations.Test)9 DateTime (org.joda.time.DateTime)8 SqlDecimal (com.facebook.presto.common.type.SqlDecimal)2 BigintType (com.facebook.presto.common.type.BigintType)1 BooleanType (com.facebook.presto.common.type.BooleanType)1 CharType (com.facebook.presto.common.type.CharType)1 DecimalType (com.facebook.presto.common.type.DecimalType)1 DoubleType (com.facebook.presto.common.type.DoubleType)1 IntegerType (com.facebook.presto.common.type.IntegerType)1 RealType (com.facebook.presto.common.type.RealType)1 SmallintType (com.facebook.presto.common.type.SmallintType)1 SqlDate (com.facebook.presto.common.type.SqlDate)1 SqlTime (com.facebook.presto.common.type.SqlTime)1 SqlTimeWithTimeZone (com.facebook.presto.common.type.SqlTimeWithTimeZone)1 SqlTimestamp (com.facebook.presto.common.type.SqlTimestamp)1 SqlVarbinary (com.facebook.presto.common.type.SqlVarbinary)1 TimestampType (com.facebook.presto.common.type.TimestampType)1 TimestampWithTimeZoneType (com.facebook.presto.common.type.TimestampWithTimeZoneType)1 TinyintType (com.facebook.presto.common.type.TinyintType)1