use of com.facebook.presto.common.type.DecimalType in project presto by prestodb.
the class KuduClientSession method setTypeAttributes.
private void setTypeAttributes(ColumnMetadata columnMetadata, ColumnSchema.ColumnSchemaBuilder builder) {
if (columnMetadata.getType() instanceof DecimalType) {
DecimalType type = (DecimalType) columnMetadata.getType();
ColumnTypeAttributes attributes = new ColumnTypeAttributes.ColumnTypeAttributesBuilder().precision(type.getPrecision()).scale(type.getScale()).build();
builder.typeAttributes(attributes);
}
}
use of com.facebook.presto.common.type.DecimalType in project presto by prestodb.
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.equals(type)) {
row.addLong(destChannel, type.getLong(block, position) * 1000);
} else if (REAL.equals(type)) {
row.addFloat(destChannel, intBitsToFloat((int) type.getLong(block, position)));
} else if (BIGINT.equals(type)) {
row.addLong(destChannel, type.getLong(block, position));
} else if (INTEGER.equals(type)) {
row.addInt(destChannel, (int) type.getLong(block, position));
} else if (SMALLINT.equals(type)) {
row.addShort(destChannel, (short) type.getLong(block, position));
} else if (TINYINT.equals(type)) {
row.addByte(destChannel, (byte) 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 (isVarcharType(type)) {
Type originalType = originalColumnTypes.get(destChannel);
if (DATE.equals(originalType)) {
SqlDate date = (SqlDate) originalType.getObjectValue(connectorSession.getSqlFunctionProperties(), 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.getSqlFunctionProperties(), block, position);
row.addDecimal(destChannel, sqlDecimal.toBigDecimal());
} else {
throw new UnsupportedOperationException("Type is not supported: " + type);
}
}
use of com.facebook.presto.common.type.DecimalType in project presto by prestodb.
the class TestChecksumAggregation method testLongDecimal.
@Test
public void testLongDecimal() {
InternalAggregationFunction decimalAgg = getAggregation(createDecimalType(19, 2));
Block block = createLongDecimalsBlock("11.11", "22.22", null, "33.33", "44.44");
DecimalType longDecimalType = createDecimalType(19);
assertAggregation(decimalAgg, expectedChecksum(longDecimalType, block), block);
}
use of com.facebook.presto.common.type.DecimalType in project presto by prestodb.
the class HiveUtil method parsePartitionValue.
public static NullableValue parsePartitionValue(String partitionName, String value, Type type, DateTimeZone timeZone) {
verifyPartitionTypeSupported(partitionName, type);
boolean isNull = HIVE_DEFAULT_DYNAMIC_PARTITION.equals(value);
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (isNull) {
return NullableValue.asNull(decimalType);
}
if (decimalType.isShort()) {
if (value.isEmpty()) {
return NullableValue.of(decimalType, 0L);
}
return NullableValue.of(decimalType, shortDecimalPartitionKey(value, decimalType, partitionName));
} else {
if (value.isEmpty()) {
return NullableValue.of(decimalType, Decimals.encodeUnscaledValue(BigInteger.ZERO));
}
return NullableValue.of(decimalType, longDecimalPartitionKey(value, decimalType, partitionName));
}
}
if (BOOLEAN.equals(type)) {
if (isNull) {
return NullableValue.asNull(BOOLEAN);
}
if (value.isEmpty()) {
return NullableValue.of(BOOLEAN, false);
}
return NullableValue.of(BOOLEAN, booleanPartitionKey(value, partitionName));
}
if (TINYINT.equals(type)) {
if (isNull) {
return NullableValue.asNull(TINYINT);
}
if (value.isEmpty()) {
return NullableValue.of(TINYINT, 0L);
}
return NullableValue.of(TINYINT, tinyintPartitionKey(value, partitionName));
}
if (SMALLINT.equals(type)) {
if (isNull) {
return NullableValue.asNull(SMALLINT);
}
if (value.isEmpty()) {
return NullableValue.of(SMALLINT, 0L);
}
return NullableValue.of(SMALLINT, smallintPartitionKey(value, partitionName));
}
if (INTEGER.equals(type)) {
if (isNull) {
return NullableValue.asNull(INTEGER);
}
if (value.isEmpty()) {
return NullableValue.of(INTEGER, 0L);
}
return NullableValue.of(INTEGER, integerPartitionKey(value, partitionName));
}
if (BIGINT.equals(type)) {
if (isNull) {
return NullableValue.asNull(BIGINT);
}
if (value.isEmpty()) {
return NullableValue.of(BIGINT, 0L);
}
return NullableValue.of(BIGINT, bigintPartitionKey(value, partitionName));
}
if (DATE.equals(type)) {
if (isNull) {
return NullableValue.asNull(DATE);
}
return NullableValue.of(DATE, datePartitionKey(value, partitionName));
}
if (TIMESTAMP.equals(type)) {
if (isNull) {
return NullableValue.asNull(TIMESTAMP);
}
return NullableValue.of(TIMESTAMP, timestampPartitionKey(value, timeZone, partitionName));
}
if (REAL.equals(type)) {
if (isNull) {
return NullableValue.asNull(REAL);
}
if (value.isEmpty()) {
return NullableValue.of(REAL, (long) floatToRawIntBits(0.0f));
}
return NullableValue.of(REAL, floatPartitionKey(value, partitionName));
}
if (DOUBLE.equals(type)) {
if (isNull) {
return NullableValue.asNull(DOUBLE);
}
if (value.isEmpty()) {
return NullableValue.of(DOUBLE, 0.0);
}
return NullableValue.of(DOUBLE, doublePartitionKey(value, partitionName));
}
if (isVarcharType(type)) {
if (isNull) {
return NullableValue.asNull(type);
}
return NullableValue.of(type, varcharPartitionKey(value, partitionName, type));
}
if (isCharType(type)) {
if (isNull) {
return NullableValue.asNull(type);
}
return NullableValue.of(type, charPartitionKey(value, partitionName, type));
}
throw new VerifyException(format("Unhandled type [%s] for partition: %s", type, partitionName));
}
use of com.facebook.presto.common.type.DecimalType in project presto by prestodb.
the class HiveWriteUtils method getJavaObjectInspector.
public static ObjectInspector getJavaObjectInspector(Type type) {
if (type.equals(BooleanType.BOOLEAN)) {
return javaBooleanObjectInspector;
} else if (type.equals(BigintType.BIGINT)) {
return javaLongObjectInspector;
} else if (type.equals(IntegerType.INTEGER)) {
return javaIntObjectInspector;
} else if (type.equals(SmallintType.SMALLINT)) {
return javaShortObjectInspector;
} else if (type.equals(TinyintType.TINYINT)) {
return javaByteObjectInspector;
} else if (type.equals(RealType.REAL)) {
return javaFloatObjectInspector;
} else if (type.equals(DoubleType.DOUBLE)) {
return javaDoubleObjectInspector;
} else if (type instanceof VarcharType) {
return writableStringObjectInspector;
} else if (type instanceof CharType) {
return writableHiveCharObjectInspector;
} else if (type.equals(VarbinaryType.VARBINARY)) {
return javaByteArrayObjectInspector;
} else if (type.equals(DateType.DATE)) {
return javaDateObjectInspector;
} else if (type.equals(TimestampType.TIMESTAMP)) {
return javaTimestampObjectInspector;
} else if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
return getPrimitiveJavaObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
} else if (isArrayType(type)) {
return ObjectInspectorFactory.getStandardListObjectInspector(getJavaObjectInspector(type.getTypeParameters().get(0)));
} else if (isMapType(type)) {
ObjectInspector keyObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(0));
ObjectInspector valueObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(1));
return ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
} else if (isRowType(type)) {
return ObjectInspectorFactory.getStandardStructObjectInspector(type.getTypeSignature().getParameters().stream().map(parameter -> parameter.getNamedTypeSignature().getName().get()).collect(toList()), type.getTypeParameters().stream().map(HiveWriteUtils::getJavaObjectInspector).collect(toList()));
}
throw new IllegalArgumentException("unsupported type: " + type);
}
Aggregations