@Override public Block toBlock(Type desiredType) { checkArgument(INTEGER.equals(desiredType), "type doesn't match: %s", desiredType); int numberOfRecords = numberOfRecords(); return new IntArrayBlock( numberOfRecords, Optional.ofNullable(nulls), ints == null ? new int[numberOfRecords] : ints); }
private StateField(String name, Class<?> type, Object initialValue, String getterName, Optional<Type> sqlType) { this.name = requireNonNull(name, "name is null"); checkArgument(!name.isEmpty(), "name is empty"); this.type = requireNonNull(type, "type is null"); this.getterName = requireNonNull(getterName, "getterName is null"); this.initialValue = initialValue; checkArgument(sqlType != null, "sqlType is null"); if (sqlType.isPresent()) { checkArgument( (sqlType.get().getJavaType() == type) || ((type == byte.class) && TINYINT.equals(sqlType.get())) || ((type == int.class) && INTEGER.equals(sqlType.get())), "Stack type (%s) and provided sql type (%s) are incompatible", type.getName(), sqlType.get().getDisplayName()); } else { sqlType = sqlTypeFromStackType(type); } this.sqlType = sqlType; }
private StateField(String name, Class<?> type, Object initialValue, String getterName, Optional<Type> sqlType) { this.name = requireNonNull(name, "name is null"); checkArgument(!name.isEmpty(), "name is empty"); this.type = requireNonNull(type, "type is null"); this.getterName = requireNonNull(getterName, "getterName is null"); this.initialValue = initialValue; checkArgument(sqlType != null, "sqlType is null"); if (sqlType.isPresent()) { checkArgument( (sqlType.get().getJavaType() == type) || ((type == byte.class) && TINYINT.equals(sqlType.get())) || ((type == int.class) && INTEGER.equals(sqlType.get())), "Stack type (%s) and provided sql type (%s) are incompatible", type.getName(), sqlType.get().getDisplayName()); } else { sqlType = sqlTypeFromStackType(type); } this.sqlType = sqlType; }
checkArgument(value instanceof Boolean, "Expected value %d to be an instance of Boolean, but is a %s", i, value.getClass().getSimpleName()); else if (INTEGER.equals(type)) { checkArgument(value instanceof Integer, "Expected value %d to be an instance of Integer, but is a %s", i, value.getClass().getSimpleName());
public static String serializeSessionProperty(Type type, Object value) { if (value == null) { throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null"); } if (BooleanType.BOOLEAN.equals(type)) { return value.toString(); } if (BigintType.BIGINT.equals(type)) { return value.toString(); } if (IntegerType.INTEGER.equals(type)) { return value.toString(); } if (DoubleType.DOUBLE.equals(type)) { return value.toString(); } if (VarcharType.VARCHAR.equals(type)) { return value.toString(); } if (type instanceof ArrayType || type instanceof MapType) { return getJsonCodecForType(type).toJson(value); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
public static String serializeSessionProperty(Type type, Object value) { if (value == null) { throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null"); } if (BooleanType.BOOLEAN.equals(type)) { return value.toString(); } if (BigintType.BIGINT.equals(type)) { return value.toString(); } if (IntegerType.INTEGER.equals(type)) { return value.toString(); } if (DoubleType.DOUBLE.equals(type)) { return value.toString(); } if (VarcharType.VARCHAR.equals(type)) { return value.toString(); } if (type instanceof ArrayType || type instanceof MapType) { return getJsonCodecForType(type).toJson(value); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
private static Object deserializeSessionProperty(Type type, String value) { if (value == null) { throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null"); } if (VarcharType.VARCHAR.equals(type)) { return value; } if (BooleanType.BOOLEAN.equals(type)) { return Boolean.valueOf(value); } if (BigintType.BIGINT.equals(type)) { return Long.valueOf(value); } if (IntegerType.INTEGER.equals(type)) { return Integer.valueOf(value); } if (DoubleType.DOUBLE.equals(type)) { return Double.valueOf(value); } if (type instanceof ArrayType || type instanceof MapType) { return getJsonCodecForType(type).fromJson(value); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
private static Object deserializeSessionProperty(Type type, String value) { if (value == null) { throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null"); } if (VarcharType.VARCHAR.equals(type)) { return value; } if (BooleanType.BOOLEAN.equals(type)) { return Boolean.valueOf(value); } if (BigintType.BIGINT.equals(type)) { return Long.valueOf(value); } if (IntegerType.INTEGER.equals(type)) { return Integer.valueOf(value); } if (DoubleType.DOUBLE.equals(type)) { return Double.valueOf(value); } if (type instanceof ArrayType || type instanceof MapType) { return getJsonCodecForType(type).fromJson(value); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
private static Class<?> getMapKeyType(Type type) { if (VarcharType.VARCHAR.equals(type)) { return String.class; } if (BooleanType.BOOLEAN.equals(type)) { return Boolean.class; } if (BigintType.BIGINT.equals(type)) { return Long.class; } if (IntegerType.INTEGER.equals(type)) { return Integer.class; } if (DoubleType.DOUBLE.equals(type)) { return Double.class; } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property map key type %s is not supported", type)); }
private static Class<?> getMapKeyType(Type type) { if (VarcharType.VARCHAR.equals(type)) { return String.class; } if (BooleanType.BOOLEAN.equals(type)) { return Boolean.class; } if (BigintType.BIGINT.equals(type)) { return Long.class; } if (IntegerType.INTEGER.equals(type)) { return Integer.class; } if (DoubleType.DOUBLE.equals(type)) { return Double.class; } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property map key type %s is not supported", type)); }
values.add(type.getLong(block, position)); else if (INTEGER.equals(type)) { values.add(toIntExact(type.getLong(block, position)));
private static boolean convertibleToDoubleWithCast(Type type) { return type instanceof DecimalType || DoubleType.DOUBLE.equals(type) || RealType.REAL.equals(type) || BigintType.BIGINT.equals(type) || IntegerType.INTEGER.equals(type) || SmallintType.SMALLINT.equals(type) || TinyintType.TINYINT.equals(type) || BooleanType.BOOLEAN.equals(type); } }
private static boolean convertibleToDoubleWithCast(Type type) { return type instanceof DecimalType || DoubleType.DOUBLE.equals(type) || RealType.REAL.equals(type) || BigintType.BIGINT.equals(type) || IntegerType.INTEGER.equals(type) || SmallintType.SMALLINT.equals(type) || TinyintType.TINYINT.equals(type) || BooleanType.BOOLEAN.equals(type); } }
private static boolean isValidPartitionType(Type type) { return type instanceof DecimalType || BOOLEAN.equals(type) || TINYINT.equals(type) || SMALLINT.equals(type) || INTEGER.equals(type) || BIGINT.equals(type) || REAL.equals(type) || DOUBLE.equals(type) || DATE.equals(type) || TIMESTAMP.equals(type) || isVarcharType(type) || isCharType(type); }
return ((Number) value).longValue(); if (INTEGER.equals(type)) { return ((Number) value).intValue();
return ((Number) value).longValue(); if (INTEGER.equals(type)) { return ((Number) value).intValue();
private static <T> JsonCodec<T> getJsonCodecForType(Type type) { if (VarcharType.VARCHAR.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(String.class); } if (BooleanType.BOOLEAN.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Boolean.class); } if (BigintType.BIGINT.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Long.class); } if (IntegerType.INTEGER.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Integer.class); } if (DoubleType.DOUBLE.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class); } if (type instanceof ArrayType) { Type elementType = ((ArrayType) type).getElementType(); return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType)); } if (type instanceof MapType) { Type keyType = ((MapType) type).getKeyType(); Type valueType = ((MapType) type).getValueType(); return (JsonCodec<T>) JSON_CODEC_FACTORY.mapJsonCodec(getMapKeyType(keyType), getJsonCodecForType(valueType)); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
private static <T> JsonCodec<T> getJsonCodecForType(Type type) { if (VarcharType.VARCHAR.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(String.class); } if (BooleanType.BOOLEAN.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Boolean.class); } if (BigintType.BIGINT.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Long.class); } if (IntegerType.INTEGER.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Integer.class); } if (DoubleType.DOUBLE.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class); } if (type instanceof ArrayType) { Type elementType = ((ArrayType) type).getElementType(); return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType)); } if (type instanceof MapType) { Type keyType = ((MapType) type).getKeyType(); Type valueType = ((MapType) type).getValueType(); return (JsonCodec<T>) JSON_CODEC_FACTORY.mapJsonCodec(getMapKeyType(keyType), getJsonCodecForType(valueType)); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
cursor.getBoolean(columnIndex); else if (INTEGER.equals(type)) { cursor.getLong(columnIndex);
parseLongColumn(column); else if (INTEGER.equals(type)) { parseLongColumn(column);