@Override public BlockBuilder writeInt(int value) { blockBuilder.writeInt(value); return this; }
@Override public BlockBuilder writeInt(int value) { checkFieldIndexToWrite(); fieldBlockBuilders[currentFieldIndexToWrite].writeInt(value); return this; }
@Override public void writeLong(BlockBuilder blockBuilder, long value) { blockBuilder.writeInt((int) value).closeEntry(); }
@Override public void writePositionTo(int position, BlockBuilder blockBuilder) { checkReadablePosition(position); blockBuilder.writeInt(values[position]); blockBuilder.closeEntry(); }
@Override public void writeLong(BlockBuilder blockBuilder, long value) { try { toIntExact(value); } catch (ArithmeticException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Value (%sb) is not a valid single-precision float", Long.toBinaryString(value).replace(' ', '0'))); } blockBuilder.writeInt((int) value).closeEntry(); }
@Override public final void writeLong(BlockBuilder blockBuilder, long value) { if (value > Integer.MAX_VALUE) { throw new PrestoException(GENERIC_INTERNAL_ERROR, String.format("Value %d exceeds MAX_INT", value)); } else if (value < Integer.MIN_VALUE) { throw new PrestoException(GENERIC_INTERNAL_ERROR, String.format("Value %d is less than MIN_INT", value)); } blockBuilder.writeInt((int) value).closeEntry(); }
@Override public void writePositionTo(int position, BlockBuilder blockBuilder) { checkReadablePosition(position); blockBuilder.writeInt(values[position + arrayOffset]); blockBuilder.closeEntry(); }
@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)); } }
@Override public final void appendTo(Block block, int position, BlockBuilder blockBuilder) { if (block.isNull(position)) { blockBuilder.appendNull(); } else { blockBuilder.writeInt(block.getInt(position, 0)).closeEntry(); } }
@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 Block spatialPartitions(KdbTree kdbTree, Rectangle envelope) { Map<Integer, Rectangle> partitions = kdbTree.findIntersectingLeaves(envelope); if (partitions.isEmpty()) { return EMPTY_ARRAY_OF_INTS; } // For input rectangles that represent a single point, return at most one partition // by excluding right and upper sides of partition rectangles. The logic that builds // KDB tree needs to make sure to add some padding to the right and upper sides of the // overall extent of the tree to avoid missing right-most and top-most points. boolean point = (envelope.getWidth() == 0 && envelope.getHeight() == 0); if (point) { for (Map.Entry<Integer, Rectangle> partition : partitions.entrySet()) { if (envelope.getXMin() < partition.getValue().getXMax() && envelope.getYMin() < partition.getValue().getYMax()) { BlockBuilder blockBuilder = IntegerType.INTEGER.createFixedSizeBlockBuilder(1); blockBuilder.writeInt(partition.getKey()); return blockBuilder.build(); } } throw new VerifyException(format("Cannot find half-open partition extent for a point: (%s, %s)", envelope.getXMin(), envelope.getYMin())); } BlockBuilder blockBuilder = IntegerType.INTEGER.createFixedSizeBlockBuilder(partitions.size()); for (int id : partitions.keySet()) { blockBuilder.writeInt(id); } return blockBuilder.build(); }
private static void writeValues(Slice[] expectedValues, BlockBuilder blockBuilder) { for (Slice expectedValue : expectedValues) { if (expectedValue == null) { blockBuilder.appendNull(); } else { blockBuilder.writeInt(expectedValue.getInt(0)).closeEntry(); } } }
private static void writeValues(Slice[] expectedValues, BlockBuilder blockBuilder) { for (Slice expectedValue : expectedValues) { if (expectedValue == null) { blockBuilder.appendNull(); } else { blockBuilder.writeInt(expectedValue.getInt(0)).closeEntry(); } } }
@Test public void testRetainedSizeWithOverlappingBlocks() { int entries = 123; BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, entries); for (int i = 0; i < entries; i++) { blockBuilder.writeInt(i); } Block block = blockBuilder.build(); // Verify we do not over count int arraySize = 456; int blocks = 7890; BlockBigArray blockBigArray = new BlockBigArray(); blockBigArray.ensureCapacity(arraySize); for (int i = 0; i < blocks; i++) { blockBigArray.set(i % arraySize, block.getRegion(0, entries)); } ReferenceCountMap referenceCountMap = new ReferenceCountMap(); referenceCountMap.incrementAndGet(block); long expectedSize = ClassLayout.parseClass(BlockBigArray.class).instanceSize() + referenceCountMap.sizeOf() + (new ObjectBigArray()).sizeOf() + block.getRetainedSizeInBytes() + (arraySize - 1) * ClassLayout.parseClass(block.getClass()).instanceSize(); assertEquals(blockBigArray.sizeOf(), expectedSize); } }
@Test public void testRetainedSizeWithOverlappingBlocks() { int entries = 123; BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, entries); for (int i = 0; i < entries; i++) { blockBuilder.writeInt(i); } Block block = blockBuilder.build(); // Verify we do not over count int arraySize = 456; int blocks = 7890; BlockBigArray blockBigArray = new BlockBigArray(); blockBigArray.ensureCapacity(arraySize); for (int i = 0; i < blocks; i++) { blockBigArray.set(i % arraySize, block.getRegion(0, entries)); } ReferenceCountMap referenceCountMap = new ReferenceCountMap(); referenceCountMap.incrementAndGet(block); long expectedSize = ClassLayout.parseClass(BlockBigArray.class).instanceSize() + referenceCountMap.sizeOf() + (new ObjectBigArray()).sizeOf() + block.getRetainedSizeInBytes() + (arraySize - 1) * ClassLayout.parseClass(block.getClass()).instanceSize(); assertEquals(blockBigArray.sizeOf(), expectedSize); } }
Block expectedInt = VARBINARY.createBlockBuilder(null, 1).writeInt(1).closeEntry().build(); Block actualInt = toBinaryBlock(INTEGER, 1, getInspector(Integer.class)); assertBlockEquals(actualInt, expectedInt); Block expectedFloat = VARBINARY.createBlockBuilder(null, 1).writeInt(floatToRawIntBits(20.0f)).closeEntry().build(); Block actualFloat = toBinaryBlock(REAL, 20.0f, getInspector(Float.class)); assertBlockEquals(actualFloat, expectedFloat);
Block expectedInt = VARBINARY.createBlockBuilder(null, 1).writeInt(1).closeEntry().build(); Block actualInt = toBinaryBlock(INTEGER, 1, getInspector(Integer.class)); assertBlockEquals(actualInt, expectedInt); Block expectedFloat = VARBINARY.createBlockBuilder(null, 1).writeInt(floatToRawIntBits(20.0f)).closeEntry().build(); Block actualFloat = toBinaryBlock(REAL, 20.0f, getInspector(Float.class)); assertBlockEquals(actualFloat, expectedFloat);