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);
}
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));
}
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));
}
Aggregations