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 public void setField(Block block, int position) { value.set(Shorts.checkedCast(SmallintType.SMALLINT.getLong(block, position))); rowInspector.setStructFieldData(row, field, value); } }
@ScalarFunction @SqlType("map(bigint,smallint)") public static Block hashCounts(@TypeParameter("map<bigint,smallint>") Type mapType, @SqlType(SetDigestType.NAME) Slice slice) { SetDigest digest = SetDigest.newInstance(slice); // Maybe use static BlockBuilderStatus in order avoid `new`? BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 1); BlockBuilder singleMapBlockBuilder = blockBuilder.beginBlockEntry(); for (Map.Entry<Long, Short> entry : digest.getHashCounts().entrySet()) { BIGINT.writeLong(singleMapBlockBuilder, entry.getKey()); SMALLINT.writeLong(singleMapBlockBuilder, entry.getValue()); } blockBuilder.closeEntry(); return (Block) mapType.getObject(blockBuilder, 0); }
public static Block createTestBlock() { BlockBuilder blockBuilder = SMALLINT.createBlockBuilder(null, 15); SMALLINT.writeLong(blockBuilder, 1111); SMALLINT.writeLong(blockBuilder, 1111); SMALLINT.writeLong(blockBuilder, 1111); SMALLINT.writeLong(blockBuilder, 2222); SMALLINT.writeLong(blockBuilder, 2222); SMALLINT.writeLong(blockBuilder, 2222); SMALLINT.writeLong(blockBuilder, 2222); SMALLINT.writeLong(blockBuilder, 2222); SMALLINT.writeLong(blockBuilder, 3333); SMALLINT.writeLong(blockBuilder, 3333); SMALLINT.writeLong(blockBuilder, 4444); return blockBuilder.build(); }
@Override protected Object getGreaterValue(Object value) { Block block = (Block) value; BlockBuilder blockBuilder = SMALLINT.createBlockBuilder(null, block.getPositionCount() + 1); for (int i = 0; i < block.getPositionCount(); i++) { SMALLINT.appendTo(block, i, blockBuilder); } SMALLINT.writeLong(blockBuilder, 1L); 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: SmallintType.SMALLINT.writeLong(builder, ((ShortObjectInspector) inspector).get(object)); 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:
@Override public void append(JsonParser parser, BlockBuilder blockBuilder) throws IOException { Long result = currentTokenAsInteger(parser); if (result == null) { blockBuilder.appendNull(); } else { SMALLINT.writeLong(blockBuilder, result); } } }
@Override public long hash(Block block, int position) { return hash(block.getShort(position, 0)); }
@Override public BlockBuilder createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries) { return createBlockBuilder(blockBuilderStatus, expectedEntries, Short.BYTES); }
@ScalarOperator(HASH_CODE) @SqlType(StandardTypes.BIGINT) public static long hashCode(@SqlType(StandardTypes.SMALLINT) long value) { return SmallintType.hash((short) value); }
@Override public BlockBuilder createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries) { return createBlockBuilder(blockBuilderStatus, expectedEntries, Short.BYTES); }
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); }
@SqlType(StandardTypes.BOOLEAN) public static boolean isDistinctFrom( @BlockPosition @SqlType(value = StandardTypes.SMALLINT, nativeContainerType = long.class) Block left, @BlockIndex int leftPosition, @BlockPosition @SqlType(value = StandardTypes.SMALLINT, 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(SMALLINT.getLong(left, leftPosition), SMALLINT.getLong(right, rightPosition)); } }
@Override public long hash(Block block, int position) { return hash(block.getShort(position, 0)); }
else if (TINYINT.equals(type)) { byte byteValue = resultSet.getByte(i); if (resultSet.wasNull()) { else if (SMALLINT.equals(type)) { short shortValue = resultSet.getShort(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()) {
Block block = reader.readBlock(0); for (int position = 0; position < block.getPositionCount(); position++) { values.add((int) SMALLINT.getLong(block, position));
if (BOOLEAN.equals(type)) { return value; else if (TINYINT.equals(type)) { return ((Number) value).byteValue(); else if (SMALLINT.equals(type)) { 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();
Block block = reader.readBlock(0); for (int position = 0; position < block.getPositionCount(); position++) { values.add((int) SMALLINT.getLong(block, position));
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))); else if (SMALLINT.equals(type)) { 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))));