Java Code Examples for io.prestosql.spi.type.RealType#REAL
The following examples show how to use
io.prestosql.spi.type.RealType#REAL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DoubleStatisticsBuilder.java From presto with Apache License 2.0 | 6 votes |
@Override public void addBlock(Type type, Block block) { for (int position = 0; position < block.getPositionCount(); position++) { if (!block.isNull(position)) { double value; if (type == RealType.REAL) { value = Float.intBitsToFloat((int) type.getLong(block, position)); } else { value = type.getDouble(block, position); } addValue(value); } } }
Example 2
Source File: TypeHelper.java From presto with Apache License 2.0 | 5 votes |
private static Type fromKuduClientType(org.apache.kudu.Type ktype, ColumnTypeAttributes attributes) { switch (ktype) { case STRING: return VarcharType.VARCHAR; case UNIXTIME_MICROS: return TimestampType.TIMESTAMP; case INT64: return BigintType.BIGINT; case INT32: return IntegerType.INTEGER; case INT16: return SmallintType.SMALLINT; case INT8: return TinyintType.TINYINT; case FLOAT: return RealType.REAL; case DOUBLE: return DoubleType.DOUBLE; case BOOL: return BooleanType.BOOLEAN; case BINARY: return VarbinaryType.VARBINARY; case DECIMAL: return DecimalType.createDecimalType(attributes.getPrecision(), attributes.getScale()); default: throw new IllegalStateException("Kudu type not implemented for " + ktype); } }
Example 3
Source File: TypeHelper.java From presto with Apache License 2.0 | 5 votes |
public static Object getObject(Type type, RowResult row, int field) { if (row.isNull(field)) { return null; } if (type instanceof VarcharType) { return row.getString(field); } if (type.equals(TimestampType.TIMESTAMP)) { return row.getLong(field) / 1000; } if (type == BigintType.BIGINT) { return row.getLong(field); } if (type == IntegerType.INTEGER) { return row.getInt(field); } if (type == SmallintType.SMALLINT) { return row.getShort(field); } if (type == TinyintType.TINYINT) { return row.getByte(field); } if (type == DoubleType.DOUBLE) { return row.getDouble(field); } if (type == RealType.REAL) { return row.getFloat(field); } if (type == BooleanType.BOOLEAN) { return row.getBoolean(field); } if (type instanceof VarbinaryType) { return Slices.wrappedBuffer(row.getBinary(field)); } if (type instanceof DecimalType) { return row.getDecimal(field); } throw new IllegalStateException("getObject not implemented for " + type); }
Example 4
Source File: TypeHelper.java From presto with Apache License 2.0 | 5 votes |
public static long getLong(Type type, RowResult row, int field) { if (type.equals(TimestampType.TIMESTAMP)) { return row.getLong(field) / 1000; } if (type == BigintType.BIGINT) { return row.getLong(field); } if (type == IntegerType.INTEGER) { return row.getInt(field); } if (type == SmallintType.SMALLINT) { return row.getShort(field); } if (type == TinyintType.TINYINT) { return row.getByte(field); } if (type == RealType.REAL) { return floatToRawIntBits(row.getFloat(field)); } if (type instanceof DecimalType) { DecimalType dtype = (DecimalType) type; if (dtype.isShort()) { return row.getDecimal(field).unscaledValue().longValue(); } throw new IllegalStateException("getLong not supported for long decimal: " + type); } throw new IllegalStateException("getLong not implemented for " + type); }
Example 5
Source File: PulsarMetadata.java From pulsar with Apache License 2.0 | 5 votes |
@VisibleForTesting static Type convertPulsarType(SchemaType pulsarType) { switch (pulsarType) { case BOOLEAN: return BooleanType.BOOLEAN; case INT8: return TinyintType.TINYINT; case INT16: return SmallintType.SMALLINT; case INT32: return IntegerType.INTEGER; case INT64: return BigintType.BIGINT; case FLOAT: return RealType.REAL; case DOUBLE: return DoubleType.DOUBLE; case NONE: case BYTES: return VarbinaryType.VARBINARY; case STRING: return VarcharType.VARCHAR; case DATE: return DateType.DATE; case TIME: return TimeType.TIME; case TIMESTAMP: return TimestampType.TIMESTAMP; default: log.error("Cannot convert type: %s", pulsarType); return null; } }
Example 6
Source File: PulsarMetadata.java From pulsar with Apache License 2.0 | 5 votes |
@VisibleForTesting static Type convertType(Schema.Type avroType, LogicalType logicalType) { switch (avroType) { case BOOLEAN: return BooleanType.BOOLEAN; case INT: if (logicalType == LogicalTypes.timeMillis()) { return TIME; } else if (logicalType == LogicalTypes.date()) { return DATE; } return IntegerType.INTEGER; case LONG: if (logicalType == LogicalTypes.timestampMillis()) { return TIMESTAMP; } return BigintType.BIGINT; case FLOAT: return RealType.REAL; case DOUBLE: return DoubleType.DOUBLE; case BYTES: return VarbinaryType.VARBINARY; case STRING: return VarcharType.VARCHAR; case ENUM: return VarcharType.VARCHAR; default: log.error("Cannot convert type: %s", avroType); return null; } }
Example 7
Source File: TypeConverter.java From presto with Apache License 2.0 | 4 votes |
public static Type toPrestoType(org.apache.iceberg.types.Type type, TypeManager typeManager) { switch (type.typeId()) { case BOOLEAN: return BooleanType.BOOLEAN; case BINARY: case FIXED: return VarbinaryType.VARBINARY; case DATE: return DateType.DATE; case DECIMAL: Types.DecimalType decimalType = (Types.DecimalType) type; return DecimalType.createDecimalType(decimalType.precision(), decimalType.scale()); case DOUBLE: return DoubleType.DOUBLE; case LONG: return BigintType.BIGINT; case FLOAT: return RealType.REAL; case INTEGER: return IntegerType.INTEGER; case TIME: return TimeType.TIME; case TIMESTAMP: Types.TimestampType timestampType = (Types.TimestampType) type; if (timestampType.shouldAdjustToUTC()) { return TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE; } return TimestampType.TIMESTAMP; case UUID: case STRING: return VarcharType.createUnboundedVarcharType(); case LIST: Types.ListType listType = (Types.ListType) type; return new ArrayType(toPrestoType(listType.elementType(), typeManager)); case MAP: Types.MapType mapType = (Types.MapType) type; TypeSignature keyType = toPrestoType(mapType.keyType(), typeManager).getTypeSignature(); TypeSignature valueType = toPrestoType(mapType.valueType(), typeManager).getTypeSignature(); return typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(keyType), TypeSignatureParameter.typeParameter(valueType))); case STRUCT: List<Types.NestedField> fields = ((Types.StructType) type).fields(); return RowType.from(fields.stream() .map(field -> new RowType.Field(Optional.of(field.name()), toPrestoType(field.type(), typeManager))) .collect(toImmutableList())); default: throw new UnsupportedOperationException(format("Cannot convert from Iceberg type '%s' (%s) to Presto type", type, type.typeId())); } }
Example 8
Source File: TypeHelper.java From presto with Apache License 2.0 | 4 votes |
public static org.apache.kudu.Type toKuduClientType(Type type) { if (type instanceof VarcharType) { return org.apache.kudu.Type.STRING; } if (type.equals(TimestampType.TIMESTAMP)) { return org.apache.kudu.Type.UNIXTIME_MICROS; } if (type == BigintType.BIGINT) { return org.apache.kudu.Type.INT64; } if (type == IntegerType.INTEGER) { return org.apache.kudu.Type.INT32; } if (type == SmallintType.SMALLINT) { return org.apache.kudu.Type.INT16; } if (type == TinyintType.TINYINT) { return org.apache.kudu.Type.INT8; } if (type == RealType.REAL) { return org.apache.kudu.Type.FLOAT; } if (type == DoubleType.DOUBLE) { return org.apache.kudu.Type.DOUBLE; } if (type == BooleanType.BOOLEAN) { return org.apache.kudu.Type.BOOL; } if (type instanceof VarbinaryType) { return org.apache.kudu.Type.BINARY; } if (type instanceof DecimalType) { return org.apache.kudu.Type.DECIMAL; } if (type == DateType.DATE) { return org.apache.kudu.Type.STRING; } if (type instanceof CharType) { return org.apache.kudu.Type.STRING; } throw new PrestoException(NOT_SUPPORTED, "Unsupported type: " + type); }
Example 9
Source File: TypeHelper.java From presto with Apache License 2.0 | 4 votes |
public static Object getJavaValue(Type type, Object nativeValue) { if (type instanceof VarcharType) { return ((Slice) nativeValue).toStringUtf8(); } if (type.equals(TimestampType.TIMESTAMP)) { return ((Long) nativeValue) * 1000; } if (type == BigintType.BIGINT) { return nativeValue; } if (type == IntegerType.INTEGER) { return ((Long) nativeValue).intValue(); } if (type == SmallintType.SMALLINT) { return ((Long) nativeValue).shortValue(); } if (type == TinyintType.TINYINT) { return ((Long) nativeValue).byteValue(); } if (type == DoubleType.DOUBLE) { return nativeValue; } if (type == RealType.REAL) { // conversion can result in precision lost return intBitsToFloat(((Long) nativeValue).intValue()); } if (type == BooleanType.BOOLEAN) { return nativeValue; } if (type instanceof VarbinaryType) { return ((Slice) nativeValue).toByteBuffer(); } if (type instanceof DecimalType) { DecimalType decimalType = (DecimalType) type; if (decimalType.isShort()) { return new BigDecimal(BigInteger.valueOf((long) nativeValue), decimalType.getScale()); } return new BigDecimal(decodeUnscaledValue((Slice) nativeValue), decimalType.getScale()); } throw new IllegalStateException("Back conversion not implemented for " + type); }