@Override public Block build() { if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, positionCount); } return new ByteArrayBlock(0, positionCount, hasNullValue ? valueIsNull : null, values); }
@Override public Work<Block> project(ConnectorSession session, DriverYieldSignal yieldSignal, Page page, SelectedPositions selectedPositions) { return new CompletedWork<>(new RunLengthEncodedBlock(value, selectedPositions.size())); } }
private static Block buildSingleValueBlock(Type type, Object value) { Block block = nativeValueToBlock(type, value); return new RunLengthEncodedBlock(block, MAX_BATCH_SIZE); }
@Override public Block getLoadedBlock() { Block loadedValueBlock = value.getLoadedBlock(); if (loadedValueBlock == value) { return this; } return new RunLengthEncodedBlock(loadedValueBlock, positionCount); }
public static Block create(Type type, Object value, int positionCount) { Block block = Utils.nativeValueToBlock(type, value); if (block instanceof RunLengthEncodedBlock) { block = ((RunLengthEncodedBlock) block).getValue(); } return new RunLengthEncodedBlock(block, positionCount); }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); for (int i = offset; i < offset + length; i++) { checkValidPosition(positions[i], positionCount); } return new RunLengthEncodedBlock(value.copyRegion(0, 1), length); }
private static Block getNullBlock(Type type, int positionCount) { Block nullValueBlock = type.createBlockBuilder(null, 1) .appendNull() .build(); return new RunLengthEncodedBlock(nullValueBlock, positionCount); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } return new LongArrayBlock(positionOffset, length, hasNullValue ? valueIsNull : null, values); }
@Test(dataProvider = "forceYield") public void testRleBlockWithFailure(boolean forceYield) { Block value = createLongSequenceBlock(-43, -42); RunLengthEncodedBlock block = new RunLengthEncodedBlock(value, 100); testProjectFails(block, RunLengthEncodedBlock.class, forceYield); }
private static void testRleBlock(boolean filterRange) { DictionaryAwarePageFilter filter = createDictionaryAwarePageFilter(filterRange, LongArrayBlock.class); RunLengthEncodedBlock match = new RunLengthEncodedBlock(createLongSequenceBlock(4, 5), 100); testFilter(filter, match, filterRange); RunLengthEncodedBlock noMatch = new RunLengthEncodedBlock(createLongSequenceBlock(0, 1), 100); testFilter(filter, noMatch, filterRange); }
@Test public void testEstimatedDataSizeForStats() { int positionCount = 10; Slice expectedValue = createExpectedValue(5); Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount); for (int postition = 0; postition < positionCount; postition++) { assertEquals(block.getEstimatedDataSizeForStats(postition), expectedValue.length()); } }
@Test public void testRunLengthEncodedBlock() { BlockBuilder blockBuilder = new LongArrayBlockBuilder(null, 1); writeEntries(1, blockBuilder, BIGINT); checkRetainedSize(new RunLengthEncodedBlock(blockBuilder.build(), 1), false); }
public static RunLengthEncodedBlock createRLEBlock(double value, int positionCount) { BlockBuilder blockBuilder = DOUBLE.createBlockBuilder(null, 1); DOUBLE.writeDouble(blockBuilder, value); return new RunLengthEncodedBlock(blockBuilder.build(), positionCount); }
public static RunLengthEncodedBlock createRLEBlock(long value, int positionCount) { BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 1); BIGINT.writeLong(blockBuilder, value); return new RunLengthEncodedBlock(blockBuilder.build(), positionCount); } }
private void assertRleBlock(int positionCount) { Slice expectedValue = createExpectedValue(0); Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount); Slice[] expectedValues = new Slice[positionCount]; for (int position = 0; position < positionCount; position++) { expectedValues[position] = expectedValue; } assertBlock(block, TestRunLengthEncodedBlock::createBlockBuilder, expectedValues); }
@Test public void testRleBlockWithFailure() { DictionaryAwarePageFilter filter = createDictionaryAwarePageFilter(true, LongArrayBlock.class); RunLengthEncodedBlock fail = new RunLengthEncodedBlock(createLongSequenceBlock(-10, -9), 100); assertThrows(NegativeValueException.class, () -> testFilter(filter, fail, true)); }
private static RunLengthEncodedBlock createRLEBlock(double percentile, int positionCount) { BlockBuilder blockBuilder = DOUBLE.createBlockBuilder(null, 1); DOUBLE.writeDouble(blockBuilder, percentile); return new RunLengthEncodedBlock(blockBuilder.build(), positionCount); }
@Test public void testRleBlockWithFailure() { DictionaryAwarePageFilter filter = createDictionaryAwarePageFilter(true, LongArrayBlock.class); RunLengthEncodedBlock fail = new RunLengthEncodedBlock(createLongSequenceBlock(-10, -9), 100); assertThrows(NegativeValueException.class, () -> testFilter(filter, fail, true)); }
public static RunLengthEncodedBlock createRLEBlock(double value, int positionCount) { BlockBuilder blockBuilder = DOUBLE.createBlockBuilder(null, 1); DOUBLE.writeDouble(blockBuilder, value); return new RunLengthEncodedBlock(blockBuilder.build(), positionCount); }
private static RunLengthEncodedBlock createRLEBlock(Iterable<Double> percentiles, int positionCount) { BlockBuilder rleBlockBuilder = new ArrayType(DOUBLE).createBlockBuilder(null, 1); BlockBuilder arrayBlockBuilder = rleBlockBuilder.beginBlockEntry(); for (double percentile : percentiles) { DOUBLE.writeDouble(arrayBlockBuilder, percentile); } rleBlockBuilder.closeEntry(); return new RunLengthEncodedBlock(rleBlockBuilder.build(), positionCount); } }