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); } }
@Override protected Object getGreaterValue(Object value) { Block block = (Block) value; BlockBuilder blockBuilder = TINYINT.createBlockBuilder(null, block.getPositionCount() + 1); for (int i = 0; i < block.getPositionCount(); i++) { TINYINT.appendTo(block, i, blockBuilder); } TINYINT.writeLong(blockBuilder, 1L); return blockBuilder.build(); } }
@Override public void setField(Block block, int position) { value.set(SignedBytes.checkedCast(TinyintType.TINYINT.getLong(block, position))); rowInspector.setStructFieldData(row, field, value); } }
public static Block createTestBlock() { BlockBuilder blockBuilder = TINYINT.createBlockBuilder(null, 15); TINYINT.writeLong(blockBuilder, 111); TINYINT.writeLong(blockBuilder, 111); TINYINT.writeLong(blockBuilder, 111); TINYINT.writeLong(blockBuilder, 22); TINYINT.writeLong(blockBuilder, 22); TINYINT.writeLong(blockBuilder, 22); TINYINT.writeLong(blockBuilder, 22); TINYINT.writeLong(blockBuilder, 22); TINYINT.writeLong(blockBuilder, 33); TINYINT.writeLong(blockBuilder, 33); TINYINT.writeLong(blockBuilder, 44); return blockBuilder.build(); }
private static void serializePrimitive(Type type, BlockBuilder builder, Object object) { requireNonNull(builder, "parent builder is null"); if (object == null) { builder.appendNull(); return; } if (BOOLEAN.equals(type)) { BOOLEAN.writeBoolean(builder, (Boolean) object); } else if (BIGINT.equals(type) || INTEGER.equals(type) || SMALLINT.equals(type) || TINYINT.equals(type) || REAL.equals(type) || DATE.equals(type) || TIMESTAMP.equals(type)) { type.writeLong(builder, getLongExpressedValue(object)); } else if (DOUBLE.equals(type)) { DOUBLE.writeDouble(builder, ((Number) object).doubleValue()); } else if (isVarcharType(type) || VARBINARY.equals(type) || isCharType(type)) { type.writeSlice(builder, getSliceExpressedValue(object, type)); } else { throw new UnsupportedOperationException("Unsupported primitive type: " + type); } }
BooleanType.BOOLEAN.writeBoolean(builder, ((BooleanObjectInspector) inspector).get(object)); return; case BYTE: TinyintType.TINYINT.writeLong(builder, ((ByteObjectInspector) inspector).get(object)); return; case SHORT: return; case INT: IntegerType.INTEGER.writeLong(builder, ((IntObjectInspector) inspector).get(object)); return; case LONG: BigintType.BIGINT.writeLong(builder, ((LongObjectInspector) inspector).get(object)); return; case FLOAT: RealType.REAL.writeLong(builder, floatToRawIntBits(((FloatObjectInspector) inspector).get(object))); return; case DOUBLE: DoubleType.DOUBLE.writeDouble(builder, ((DoubleObjectInspector) inspector).get(object)); return; case STRING: return; case DATE: DateType.DATE.writeLong(builder, formatDateAsLong(object, (DateObjectInspector) inspector)); return; case TIMESTAMP:
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; }
@Override public void append(JsonParser parser, BlockBuilder blockBuilder) throws IOException { Long result = currentTokenAsTinyint(parser); if (result == null) { blockBuilder.appendNull(); } else { TINYINT.writeLong(blockBuilder, result); } } }
@Override public long hash(Block block, int position) { return hash(block.getByte(position, 0)); }
@Override public BlockBuilder createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries) { return createBlockBuilder(blockBuilderStatus, expectedEntries, Byte.BYTES); }
@ScalarOperator(HASH_CODE) @SqlType(StandardTypes.BIGINT) public static long hashCode(@SqlType(StandardTypes.TINYINT) long value) { return TinyintType.hash((byte) value); }
@Test public void testPrimitiveByteSerialization() { AccumulatorStateFactory<ByteState> factory = StateCompiler.generateStateFactory(ByteState.class); AccumulatorStateSerializer<ByteState> serializer = StateCompiler.generateStateSerializer(ByteState.class); ByteState state = factory.createSingleState(); ByteState deserializedState = factory.createSingleState(); state.setByte((byte) 3); BlockBuilder builder = TINYINT.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.getByte(), state.getByte()); }
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); }
@Override public long hash(Block block, int position) { return hash(block.getByte(position, 0)); }
@Override public BlockBuilder createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries) { return createBlockBuilder(blockBuilderStatus, expectedEntries, Byte.BYTES); }
@SqlType(StandardTypes.BOOLEAN) public static boolean isDistinctFrom( @BlockPosition @SqlType(value = StandardTypes.TINYINT, nativeContainerType = long.class) Block left, @BlockIndex int leftPosition, @BlockPosition @SqlType(value = StandardTypes.TINYINT, nativeContainerType = long.class) Block right, @BlockIndex int rightPosition) { if (left.isNull(leftPosition) != right.isNull(rightPosition)) { return true; } if (left.isNull(leftPosition)) { return false; } return notEqual(TINYINT.getLong(left, leftPosition), TINYINT.getLong(right, rightPosition)); } }
for (int i = 1; i <= count; i++) { Type type = types.get(i - 1); if (BOOLEAN.equals(type)) { boolean booleanValue = resultSet.getBoolean(i); if (resultSet.wasNull()) { else if (TINYINT.equals(type)) { byte byteValue = resultSet.getByte(i); if (resultSet.wasNull()) { else if (INTEGER.equals(type)) { int intValue = resultSet.getInt(i); if (resultSet.wasNull()) { else if (BIGINT.equals(type)) { long longValue = resultSet.getLong(i); if (resultSet.wasNull()) { else if (REAL.equals(type)) { float floatValue = resultSet.getFloat(i); if (resultSet.wasNull()) { else if (DOUBLE.equals(type)) { double doubleValue = resultSet.getDouble(i); if (resultSet.wasNull()) { else if (DATE.equals(type)) {
if (BOOLEAN.equals(type)) { return value; else if (TINYINT.equals(type)) { return ((Number) value).byteValue(); return ((Number) value).shortValue(); else if (INTEGER.equals(type)) { return ((Number) value).intValue(); else if (BIGINT.equals(type)) { return ((Number) value).longValue(); else if (DOUBLE.equals(type)) { return ((Number) value).doubleValue(); else if (REAL.equals(type)) { return ((Number) value).floatValue(); return value; else if (DATE.equals(type)) { return DateTimeFormatter.ISO_LOCAL_DATE.parse(((String) value), LocalDate::from);
if (BOOLEAN.equals(type)) { statement.setBoolean(parameter, type.getBoolean(block, position)); else if (BIGINT.equals(type)) { statement.setLong(parameter, type.getLong(block, position)); else if (INTEGER.equals(type)) { statement.setInt(parameter, toIntExact(type.getLong(block, position))); statement.setShort(parameter, Shorts.checkedCast(type.getLong(block, position))); else if (TINYINT.equals(type)) { statement.setByte(parameter, SignedBytes.checkedCast(type.getLong(block, position))); else if (DOUBLE.equals(type)) { statement.setDouble(parameter, type.getDouble(block, position)); else if (REAL.equals(type)) { statement.setFloat(parameter, intBitsToFloat(toIntExact(type.getLong(block, position)))); statement.setBytes(parameter, type.getSlice(block, position).getBytes()); else if (DATE.equals(type)) {
if (BOOLEAN.equals(type)) { statisticsBuilder = new BooleanStatisticsBuilder(); fieldExtractor = ignored -> ImmutableList.of(); fieldBuilders = ImmutableList.of(); else if (TINYINT.equals(type)) { statisticsBuilder = new CountStatisticsBuilder(); fieldExtractor = ignored -> ImmutableList.of(); fieldBuilders = ImmutableList.of(); else if (INTEGER.equals(type)) { statisticsBuilder = new IntegerStatisticsBuilder(); fieldExtractor = ignored -> ImmutableList.of(); fieldBuilders = ImmutableList.of(); else if (REAL.equals(type)) { statisticsBuilder = new DoubleStatisticsBuilder(); fieldExtractor = ignored -> ImmutableList.of(); fieldBuilders = ImmutableList.of(); else if (DATE.equals(type)) { statisticsBuilder = new DateStatisticsBuilder(); fieldExtractor = ignored -> ImmutableList.of();