Java Code Examples for com.facebook.presto.spi.type.IntegerType#INTEGER
The following examples show how to use
com.facebook.presto.spi.type.IntegerType#INTEGER .
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: TypeHelper.java From presto-kudu with Apache License 2.0 | 6 votes |
public static long getLong(Type type, RowResult row, int field) { if (type == TimestampType.TIMESTAMP) { return row.getLong(field) / 1000; } else if (type == BigintType.BIGINT) { return row.getLong(field); } else if (type == IntegerType.INTEGER) { return row.getInt(field); } else if (type == SmallintType.SMALLINT) { return row.getShort(field); } else if (type == TinyintType.TINYINT) { return row.getByte(field); } else if (type == RealType.REAL) { return floatToRawIntBits(row.getFloat(field)); } else if (type instanceof DecimalType) { DecimalType dtype = (DecimalType) type; if (dtype.isShort()) { return row.getDecimal(field).unscaledValue().longValue(); } else { throw new IllegalStateException("getLong not supported for long decimal: " + type); } } else { throw new IllegalStateException("getLong not implemented for " + type); } }
Example 2
Source File: ParaflowTableLayoutHandle.java From paraflow with Apache License 2.0 | 5 votes |
public ParaflowTableLayoutHandle(ParaflowTableHandle table) { this(table, new ParaflowColumnHandle("null", IntegerType.INTEGER, "", ParaflowColumnHandle.ColumnType.REGULAR, ""), new ParaflowColumnHandle("null", IntegerType.INTEGER, "", ParaflowColumnHandle.ColumnType.REGULAR, ""), "", StorageFormat.PARQUET, Optional.empty()); }
Example 3
Source File: TypeHelper.java From presto-kudu with Apache License 2.0 | 5 votes |
public static org.apache.kudu.Type toKuduClientType(Type type) { if (type instanceof VarcharType) { return org.apache.kudu.Type.STRING; } else if (type == TimestampType.TIMESTAMP) { return org.apache.kudu.Type.UNIXTIME_MICROS; } else if (type == BigintType.BIGINT) { return org.apache.kudu.Type.INT64; } else if (type == IntegerType.INTEGER) { return org.apache.kudu.Type.INT32; } else if (type == SmallintType.SMALLINT) { return org.apache.kudu.Type.INT16; } else if (type == TinyintType.TINYINT) { return org.apache.kudu.Type.INT8; } else if (type == RealType.REAL) { return org.apache.kudu.Type.FLOAT; } else if (type == DoubleType.DOUBLE) { return org.apache.kudu.Type.DOUBLE; } else if (type == BooleanType.BOOLEAN) { return org.apache.kudu.Type.BOOL; } else if (type instanceof VarbinaryType) { return org.apache.kudu.Type.BINARY; } else if (type instanceof DecimalType) { return org.apache.kudu.Type.DECIMAL; } else if (type == DateType.DATE) { return org.apache.kudu.Type.STRING; } else if (type instanceof CharType) { return org.apache.kudu.Type.STRING; } else { throw new IllegalStateException("Type mapping implemented for Presto type: " + type); } }
Example 4
Source File: TypeHelper.java From presto-kudu 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 5
Source File: TypeHelper.java From presto-kudu with Apache License 2.0 | 5 votes |
public static NullableValue getColumnValue(Type type, PartialRow row, int i) { if (row.isNull(i)) { return NullableValue.asNull(type); } else { if (type instanceof VarcharType) { return NullableValue.of(type, utf8Slice(row.getString(i))); } else if (type == TimestampType.TIMESTAMP) { return NullableValue.of(type, row.getLong(i) / 1000); } else if (type == BigintType.BIGINT) { return NullableValue.of(type, row.getLong(i)); } else if (type == IntegerType.INTEGER) { return NullableValue.of(type, row.getInt(i)); } else if (type == SmallintType.SMALLINT) { return NullableValue.of(type, row.getShort(i)); } else if (type == TinyintType.TINYINT) { return NullableValue.of(type, row.getByte(i)); } else if (type == DoubleType.DOUBLE) { return NullableValue.of(type, row.getDouble(i)); } else if (type == RealType.REAL) { return NullableValue.of(type, (long) floatToRawIntBits(row.getFloat(i))); } else if (type == BooleanType.BOOLEAN) { return NullableValue.of(type, row.getBoolean(i)); } else if (type instanceof VarbinaryType) { return NullableValue.of(type, wrappedBuffer(row.getBinary(i))); } else if (type instanceof DecimalType) { return NullableValue.of(type, row.getDecimal(i)); } else { throw new IllegalStateException("Handling of type " + type + " is not implemented"); } } }
Example 6
Source File: TypeHelper.java From presto-kudu with Apache License 2.0 | 5 votes |
public static Object getJavaValue(Type type, Object nativeValue) { if (type instanceof VarcharType) { return ((Slice) nativeValue).toStringUtf8(); } else if (type == TimestampType.TIMESTAMP) { return ((Long) nativeValue) * 1000; } else if (type == BigintType.BIGINT) { return nativeValue; } else if (type == IntegerType.INTEGER) { return ((Long) nativeValue).intValue(); } else if (type == SmallintType.SMALLINT) { return ((Long) nativeValue).shortValue(); } else if (type == TinyintType.TINYINT) { return ((Long) nativeValue).byteValue(); } else if (type == DoubleType.DOUBLE) { return nativeValue; } else if (type == RealType.REAL) { // conversion can result in precision lost return intBitsToFloat(((Long) nativeValue).intValue()); } else if (type == BooleanType.BOOLEAN) { return nativeValue; } else if (type instanceof VarbinaryType) { return ((Slice) nativeValue).toByteBuffer(); } else if (type instanceof DecimalType) { return nativeValue; } else { throw new IllegalStateException("Back conversion not implemented for " + type); } }
Example 7
Source File: TypeHelper.java From presto-kudu with Apache License 2.0 | 5 votes |
public static Object getObject(Type type, RowResult row, int field) { if (row.isNull(field)) { return null; } else { if (type instanceof VarcharType) { return row.getString(field); } else if (type == TimestampType.TIMESTAMP) { return row.getLong(field) / 1000; } else if (type == BigintType.BIGINT) { return row.getLong(field); } else if (type == IntegerType.INTEGER) { return row.getInt(field); } else if (type == SmallintType.SMALLINT) { return row.getShort(field); } else if (type == TinyintType.TINYINT) { return row.getByte(field); } else if (type == DoubleType.DOUBLE) { return row.getDouble(field); } else if (type == RealType.REAL) { return row.getFloat(field); } else if (type == BooleanType.BOOLEAN) { return row.getBoolean(field); } else if (type instanceof VarbinaryType) { return Slices.wrappedBuffer(row.getBinary(field)); } else if (type instanceof DecimalType) { return row.getDecimal(field); } else { throw new IllegalStateException("getObject not implemented for " + type); } } }
Example 8
Source File: ParaflowMetaDataReader.java From paraflow with Apache License 2.0 | 4 votes |
private Type getType(String typeName) { log.debug("Get type " + typeName); typeName = typeName.toLowerCase(); // check if type is varchar(xx) Pattern vcpattern = Pattern.compile("varchar\\(\\s*(\\d+)\\s*\\)"); Matcher vcmatcher = vcpattern.matcher(typeName); if (vcmatcher.find()) { String vlen = vcmatcher.group(1); if (!vlen.isEmpty()) { return VarcharType.createVarcharType(Integer.parseInt(vlen)); } return UnknownType.UNKNOWN; } // check if type is char(xx) Pattern cpattern = Pattern.compile("char\\(\\s*(\\d+)\\s*\\)"); Matcher cmatcher = cpattern.matcher(typeName); if (cmatcher.find()) { String clen = cmatcher.group(1); if (!clen.isEmpty()) { return CharType.createCharType(Integer.parseInt(clen)); } return UnknownType.UNKNOWN; } // check if type is decimal(precision, scale) Pattern dpattern = Pattern.compile("decimal\\((\\d+)\\s*,?\\s*(\\d*)\\)"); Matcher dmatcher = dpattern.matcher(typeName); if (dmatcher.find()) { String dprecision = dmatcher.group(1); String dscale = dmatcher.group(2); if (dprecision.isEmpty()) { return UnknownType.UNKNOWN; } if (dscale.isEmpty()) { return DecimalType.createDecimalType(Integer.parseInt(dprecision)); } return DecimalType.createDecimalType(Integer.parseInt(dprecision), Integer.parseInt(dscale)); } switch (typeName) { case "boolean": return BooleanType.BOOLEAN; case "tinyint": return TinyintType.TINYINT; case "smallint": return SmallintType.SMALLINT; case "integer": return IntegerType.INTEGER; case "bigint": return BigintType.BIGINT; case "real": return RealType.REAL; case "double": return DoubleType.DOUBLE; case "date": return DateType.DATE; case "time": return TimeType.TIME; case "timestamp": return TimestampType.TIMESTAMP; default: return UnknownType.UNKNOWN; } }