else if (REAL.equals(type)) { float floatValue = resultSet.getFloat(i); if (resultSet.wasNull()) {
public static Block createTestBlock() { BlockBuilder blockBuilder = REAL.createBlockBuilder(null, 30); REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F)); REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F)); REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(33.33F)); REAL.writeLong(blockBuilder, floatToRawIntBits(33.33F)); REAL.writeLong(blockBuilder, floatToRawIntBits(44.44F)); return blockBuilder.build(); }
@Override public void writeJsonValue(JsonGenerator jsonGenerator, Block block, int position, ConnectorSession session) throws IOException { if (block.isNull(position)) { jsonGenerator.writeNull(); } else { float value = intBitsToFloat((int) REAL.getLong(block, position)); jsonGenerator.writeNumber(value); } } }
public static Block createSequenceBlockOfReal(int start, int end) { BlockBuilder builder = REAL.createFixedSizeBlockBuilder(end - start); for (int i = start; i < end; i++) { REAL.writeLong(builder, floatToRawIntBits((float) i)); } return builder.build(); }
@Override public void append(JsonParser parser, BlockBuilder blockBuilder) throws IOException { Long result = currentTokenAsReal(parser); if (result == null) { blockBuilder.appendNull(); } else { REAL.writeLong(blockBuilder, result); } } }
@Override public long hash(Block block, int position) { // convert to canonical NaN if necessary return hash(floatToIntBits(intBitsToFloat(block.getInt(position, 0)))); }
@Override public void append(JsonParser parser, BlockBuilder blockBuilder) throws IOException { Long result = currentTokenAsReal(parser); if (result == null) { blockBuilder.appendNull(); } else { REAL.writeLong(blockBuilder, result); } } }
public static Block createSequenceBlockOfReal(int start, int end) { BlockBuilder builder = REAL.createFixedSizeBlockBuilder(end - start); for (int i = start; i < end; i++) { REAL.writeLong(builder, floatToRawIntBits((float) i)); } return builder.build(); }
@Test public void testNaNHash() { BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, 4); blockBuilder.writeInt(floatToIntBits(Float.NaN)); blockBuilder.writeInt(floatToRawIntBits(Float.NaN)); // the following two are the integer values of a float NaN blockBuilder.writeInt(-0x400000); blockBuilder.writeInt(0x7fc00000); assertEquals(REAL.hash(blockBuilder, 0), REAL.hash(blockBuilder, 1)); assertEquals(REAL.hash(blockBuilder, 0), REAL.hash(blockBuilder, 2)); assertEquals(REAL.hash(blockBuilder, 0), REAL.hash(blockBuilder, 3)); } }
values.add(type.getDouble(block, position)); else if (REAL.equals(type)) { values.add(intBitsToFloat(toIntExact(type.getLong(block, position))));
@Override public Block[] getSequenceBlocks(int start, int length) { BlockBuilder blockBuilder = REAL.createBlockBuilder(null, length); for (int i = start; i < start + length; i++) { REAL.writeLong(blockBuilder, floatToRawIntBits((float) i)); } return new Block[] {blockBuilder.build()}; }
@OutputFunction("map(real,real)") public static void output(@AggregationState DoubleHistogramAggregation.State state, BlockBuilder out) { if (state.get() == null) { out.appendNull(); } else { Map<Double, Double> value = state.get().getBuckets(); BlockBuilder entryBuilder = out.beginBlockEntry(); for (Map.Entry<Double, Double> entry : value.entrySet()) { REAL.writeLong(entryBuilder, floatToRawIntBits(entry.getKey().floatValue())); REAL.writeLong(entryBuilder, floatToRawIntBits(entry.getValue().floatValue())); } out.closeEntry(); } } }
@Override public void writeJsonValue(JsonGenerator jsonGenerator, Block block, int position, ConnectorSession session) throws IOException { if (block.isNull(position)) { jsonGenerator.writeNull(); } else { float value = intBitsToFloat((int) REAL.getLong(block, position)); jsonGenerator.writeNumber(value); } } }
@Test public void testNaNHash() { BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, 4); blockBuilder.writeInt(floatToIntBits(Float.NaN)); blockBuilder.writeInt(floatToRawIntBits(Float.NaN)); // the following two are the integer values of a float NaN blockBuilder.writeInt(-0x400000); blockBuilder.writeInt(0x7fc00000); assertEquals(REAL.hash(blockBuilder, 0), REAL.hash(blockBuilder, 1)); assertEquals(REAL.hash(blockBuilder, 0), REAL.hash(blockBuilder, 2)); assertEquals(REAL.hash(blockBuilder, 0), REAL.hash(blockBuilder, 3)); } }
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 Block[] getSequenceBlocks(int start, int length) { BlockBuilder blockBuilder = REAL.createBlockBuilder(null, length); for (int i = start; i < start + length; i++) { REAL.writeLong(blockBuilder, floatToRawIntBits((float) i)); } return new Block[] {blockBuilder.build()}; }
@OutputFunction("map(real,real)") public static void output(@AggregationState DoubleHistogramAggregation.State state, BlockBuilder out) { if (state.get() == null) { out.appendNull(); } else { Map<Double, Double> value = state.get().getBuckets(); BlockBuilder entryBuilder = out.beginBlockEntry(); for (Map.Entry<Double, Double> entry : value.entrySet()) { REAL.writeLong(entryBuilder, floatToRawIntBits(entry.getKey().floatValue())); REAL.writeLong(entryBuilder, floatToRawIntBits(entry.getValue().floatValue())); } out.closeEntry(); } } }
@Override public void setField(Block block, int position) { value.set(intBitsToFloat((int) RealType.REAL.getLong(block, position))); rowInspector.setStructFieldData(row, field, value); } }
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 Block[] getSequenceBlocks(int start, int length) { BlockBuilder blockBuilder = REAL.createBlockBuilder(null, length); for (int i = start; i < start + length; i++) { REAL.writeLong(blockBuilder, floatToRawIntBits((float) i)); } return new Block[] {blockBuilder.build()}; }