Search in sources :

Example 6 with SqlTimestampWithTimeZone

use of com.facebook.presto.spi.type.SqlTimestampWithTimeZone 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)

Example 7 with SqlTimestampWithTimeZone

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

the class TestHistogram method testDuplicateKeysValues.

@Test
public void testDuplicateKeysValues() throws Exception {
    MapType mapType = new MapType(VARCHAR, BIGINT);
    InternalAggregationFunction aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.VARCHAR)));
    assertAggregation(aggregationFunction, ImmutableMap.of("a", 2L, "b", 1L), createStringsBlock("a", "b", "a"));
    mapType = new MapType(TIMESTAMP_WITH_TIME_ZONE, BIGINT);
    aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)));
    long timestampWithTimeZone1 = packDateTimeWithZone(new DateTime(1970, 1, 1, 0, 0, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY);
    long timestampWithTimeZone2 = packDateTimeWithZone(new DateTime(2015, 1, 1, 0, 0, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY);
    assertAggregation(aggregationFunction, ImmutableMap.of(new SqlTimestampWithTimeZone(timestampWithTimeZone1), 2L, new SqlTimestampWithTimeZone(timestampWithTimeZone2), 1L), createLongsBlock(timestampWithTimeZone1, timestampWithTimeZone1, timestampWithTimeZone2));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.spi.type.SqlTimestampWithTimeZone) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) MapType(com.facebook.presto.type.MapType) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 8 with SqlTimestampWithTimeZone

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

the class TestDateTimeOperators method testTimestampPlusInterval.

@Test
public void testTimestampPlusInterval() {
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' hour", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 22, 6, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' hour + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 22, 6, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' day", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 25, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' day + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 25, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' month", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 4, 22, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' month + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 4, 22, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' year", TIMESTAMP, new SqlTimestamp(new DateTime(2004, 1, 22, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' year + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, new SqlTimestamp(new DateTime(2004, 1, 22, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' + INTERVAL '3' hour", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 6, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' hour + TIMESTAMP '2001-1-22 03:04:05.321 +05:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 6, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' + INTERVAL '3' day", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 25, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' day + TIMESTAMP '2001-1-22 03:04:05.321 +05:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 25, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' + INTERVAL '3' month", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 4, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' month + TIMESTAMP '2001-1-22 03:04:05.321 +05:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 4, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' + INTERVAL '3' year", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2004, 1, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' year + TIMESTAMP '2001-1-22 03:04:05.321 +05:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2004, 1, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.spi.type.SqlTimestampWithTimeZone) SqlTimestamp(com.facebook.presto.spi.type.SqlTimestamp) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

SqlTimestampWithTimeZone (com.facebook.presto.spi.type.SqlTimestampWithTimeZone)8 DateTime (org.joda.time.DateTime)7 Test (org.testng.annotations.Test)7 SqlTimestamp (com.facebook.presto.spi.type.SqlTimestamp)3 Signature (com.facebook.presto.metadata.Signature)1 SqlDate (com.facebook.presto.spi.type.SqlDate)1 SqlDecimal (com.facebook.presto.spi.type.SqlDecimal)1 SqlTime (com.facebook.presto.spi.type.SqlTime)1 SqlTimeWithTimeZone (com.facebook.presto.spi.type.SqlTimeWithTimeZone)1 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)1 MapType (com.facebook.presto.type.MapType)1 Date (java.sql.Date)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1