use of io.trino.spi.type.SqlDate in project trino by trinodb.
the class KuduPageSink method appendColumn.
private void appendColumn(PartialRow row, Page page, int position, int channel, int destChannel) {
Block block = page.getBlock(channel);
Type type = columnTypes.get(destChannel);
if (block.isNull(position)) {
row.setNull(destChannel);
} else if (TIMESTAMP_MILLIS.equals(type)) {
row.addLong(destChannel, truncateEpochMicrosToMillis(type.getLong(block, position)));
} else if (REAL.equals(type)) {
row.addFloat(destChannel, intBitsToFloat(toIntExact(type.getLong(block, position))));
} else if (BIGINT.equals(type)) {
row.addLong(destChannel, type.getLong(block, position));
} else if (INTEGER.equals(type)) {
row.addInt(destChannel, toIntExact(type.getLong(block, position)));
} else if (SMALLINT.equals(type)) {
row.addShort(destChannel, Shorts.checkedCast(type.getLong(block, position)));
} else if (TINYINT.equals(type)) {
row.addByte(destChannel, SignedBytes.checkedCast(type.getLong(block, position)));
} else if (BOOLEAN.equals(type)) {
row.addBoolean(destChannel, type.getBoolean(block, position));
} else if (DOUBLE.equals(type)) {
row.addDouble(destChannel, type.getDouble(block, position));
} else if (type instanceof VarcharType) {
Type originalType = originalColumnTypes.get(destChannel);
if (DATE.equals(originalType)) {
SqlDate date = (SqlDate) originalType.getObjectValue(connectorSession, block, position);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(TimeUnit.DAYS.toSeconds(date.getDays()), 0, ZoneOffset.UTC);
byte[] bytes = ldt.format(DateTimeFormatter.ISO_LOCAL_DATE).getBytes(StandardCharsets.UTF_8);
row.addStringUtf8(destChannel, bytes);
} else {
row.addString(destChannel, type.getSlice(block, position).toStringUtf8());
}
} else if (VARBINARY.equals(type)) {
row.addBinary(destChannel, type.getSlice(block, position).toByteBuffer());
} else if (type instanceof DecimalType) {
SqlDecimal sqlDecimal = (SqlDecimal) type.getObjectValue(connectorSession, block, position);
row.addDecimal(destChannel, sqlDecimal.toBigDecimal());
} else {
throw new UnsupportedOperationException("Type is not supported: " + type);
}
}
Aggregations