use of com.facebook.presto.spi.type.SqlDate in project presto by prestodb.
the class TestTimestamp method testCastToDate.
@Test
public void testCastToDate() throws Exception {
long millis = new DateTime(2001, 1, 22, 0, 0, UTC).getMillis();
assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as date)", DATE, new SqlDate((int) TimeUnit.MILLISECONDS.toDays(millis)));
}
use of com.facebook.presto.spi.type.SqlDate in project presto by prestodb.
the class TestDate method testGreatest.
@Test
public void testGreatest() throws Exception {
int days = (int) TimeUnit.MILLISECONDS.toDays(new DateTime(2013, 3, 30, 0, 0, UTC).getMillis());
assertFunction("greatest(DATE '2013-03-30', DATE '2012-05-23')", DATE, new SqlDate(days));
assertFunction("greatest(DATE '2013-03-30', DATE '2012-05-23', DATE '2012-06-01')", DATE, new SqlDate(days));
}
use of com.facebook.presto.spi.type.SqlDate in project presto by prestodb.
the class TestDate method testLiteral.
@Test
public void testLiteral() throws Exception {
long millis = new DateTime(2001, 1, 22, 0, 0, UTC).getMillis();
assertFunction("DATE '2001-1-22'", DATE, new SqlDate((int) TimeUnit.MILLISECONDS.toDays(millis)));
}
use of com.facebook.presto.spi.type.SqlDate in project presto by prestodb.
the class OrcTester method preprocessWriteValueOld.
private static Object preprocessWriteValueOld(TypeInfo typeInfo, Object value) {
if (value == null) {
return null;
}
switch(typeInfo.getCategory()) {
case PRIMITIVE:
PrimitiveObjectInspector.PrimitiveCategory primitiveCategory = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory();
switch(primitiveCategory) {
case BOOLEAN:
return value;
case BYTE:
return ((Number) value).byteValue();
case SHORT:
return ((Number) value).shortValue();
case INT:
return ((Number) value).intValue();
case LONG:
return ((Number) value).longValue();
case FLOAT:
return ((Number) value).floatValue();
case DOUBLE:
return ((Number) value).doubleValue();
case DECIMAL:
return HiveDecimal.create(((SqlDecimal) value).toBigDecimal());
case STRING:
return value;
case CHAR:
return new HiveChar(value.toString(), ((CharTypeInfo) typeInfo).getLength());
case DATE:
int days = ((SqlDate) value).getDays();
LocalDate localDate = LocalDate.ofEpochDay(days);
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
long millis = zonedDateTime.toEpochSecond() * 1000;
Date date = new Date(0);
// mills must be set separately to avoid masking
date.setTime(millis);
return date;
case TIMESTAMP:
long millisUtc = (int) ((SqlTimestamp) value).getMillisUtc();
return new Timestamp(millisUtc);
case BINARY:
return ((SqlVarbinary) value).getBytes();
}
break;
case MAP:
MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
TypeInfo keyTypeInfo = mapTypeInfo.getMapKeyTypeInfo();
TypeInfo valueTypeInfo = mapTypeInfo.getMapValueTypeInfo();
Map<Object, Object> newMap = new HashMap<>();
for (Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
newMap.put(preprocessWriteValueOld(keyTypeInfo, entry.getKey()), preprocessWriteValueOld(valueTypeInfo, entry.getValue()));
}
return newMap;
case LIST:
ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
TypeInfo elementTypeInfo = listTypeInfo.getListElementTypeInfo();
List<Object> newList = new ArrayList<>(((Collection<?>) value).size());
for (Object element : (Iterable<?>) value) {
newList.add(preprocessWriteValueOld(elementTypeInfo, element));
}
return newList;
case STRUCT:
StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
List<?> fieldValues = (List<?>) value;
List<TypeInfo> fieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos();
List<Object> newStruct = new ArrayList<>();
for (int fieldId = 0; fieldId < fieldValues.size(); fieldId++) {
newStruct.add(preprocessWriteValueOld(fieldTypeInfos.get(fieldId), fieldValues.get(fieldId)));
}
return newStruct;
}
throw new PrestoException(NOT_SUPPORTED, format("Unsupported Hive type: %s", typeInfo));
}
use of com.facebook.presto.spi.type.SqlDate in project presto by prestodb.
the class AbstractTestOrcReader method testRoundTripNumeric.
private void testRoundTripNumeric(Iterable<? extends Number> values) throws Exception {
List<Long> writeValues = ImmutableList.copyOf(values).stream().map(Number::longValue).collect(toList());
tester.testRoundTrip(javaByteObjectInspector, writeValues.stream().map(// truncate values to byte range
value -> (long) value.byteValue()).collect(toList()), BIGINT);
tester.testRoundTrip(javaShortObjectInspector, writeValues.stream().map(// truncate values to short range
value -> (long) value.shortValue()).collect(toList()), BIGINT);
tester.testRoundTrip(javaIntObjectInspector, writeValues, BIGINT);
tester.testRoundTrip(javaLongObjectInspector, writeValues, BIGINT);
tester.testRoundTrip(javaDateObjectInspector, writeValues.stream().map(Long::intValue).map(SqlDate::new).collect(toList()), DATE);
tester.testRoundTrip(javaTimestampObjectInspector, writeValues.stream().map(timestamp -> new SqlTimestamp(timestamp, UTC_KEY)).collect(toList()), TIMESTAMP);
}
Aggregations