public GetGroupIdsWork(Block block) { this.block = requireNonNull(block, "block is null"); // we know the exact size required for the block this.blockBuilder = BIGINT.createFixedSizeBlockBuilder(block.getPositionCount()); }
public GetNonDictionaryGroupIdsWork(Page page) { this.page = requireNonNull(page, "page is null"); // we know the exact size required for the block this.blockBuilder = BIGINT.createFixedSizeBlockBuilder(page.getPositionCount()); }
public GetDictionaryGroupIdsWork(Page page) { this.page = requireNonNull(page, "page is null"); verify(canProcessDictionary(page), "invalid call to processDictionary"); this.dictionaryBlock = (DictionaryBlock) page.getBlock(channels[0]); updateDictionaryLookBack(dictionaryBlock.getDictionary()); this.dictionaryPage = createPageWithExtractedDictionary(page); // we know the exact size required for the block this.blockBuilder = BIGINT.createFixedSizeBlockBuilder(page.getPositionCount()); }
public static Block createEmptyLongsBlock() { return BIGINT.createFixedSizeBlockBuilder(0).build(); }
@Override public GroupByIdBlock getResult() { checkState(processFinished); checkState(!resultProduced); resultProduced = true; return new GroupByIdBlock( nextGroupId, new RunLengthEncodedBlock( BIGINT.createFixedSizeBlockBuilder(1).writeLong(groupId).build(), page.getPositionCount())); } }
public static Block getHashBlock(List<? extends Type> hashTypes, Block... hashBlocks) { checkArgument(hashTypes.size() == hashBlocks.length); int[] hashChannels = new int[hashBlocks.length]; for (int i = 0; i < hashBlocks.length; i++) { hashChannels[i] = i; } HashGenerator hashGenerator = new InterpretedHashGenerator(ImmutableList.copyOf(hashTypes), hashChannels); int positionCount = hashBlocks[0].getPositionCount(); BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(positionCount); Page page = new Page(hashBlocks); for (int i = 0; i < positionCount; i++) { BIGINT.writeLong(builder, hashGenerator.hashPosition(i, page)); } return builder.build(); }
public static Block createLongSequenceBlock(int start, int end) { BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(end - start); for (int i = start; i < end; i++) { BIGINT.writeLong(builder, i); } return builder.build(); }
public static Block createLongRepeatBlock(int value, int length) { BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(length); for (int i = 0; i < length; i++) { BIGINT.writeLong(builder, value); } return builder.build(); }
@Test public void testBinaryMergeIteratorOverEmptyPage() { Page emptyPage = new Page(0, BIGINT.createFixedSizeBlockBuilder(0).build()); WorkProcessor<Page> mergedPage = new MergeHashSort(newSimpleAggregatedMemoryContext()).merge( ImmutableList.of(BIGINT), ImmutableList.of(BIGINT), ImmutableList.of(ImmutableList.of(emptyPage).iterator()).stream() .map(WorkProcessor::fromIterator) .collect(toImmutableList()), new DriverYieldSignal()); assertFinishes(mergedPage); }
private Block generateIdColumn() { BlockBuilder block = BIGINT.createFixedSizeBlockBuilder(inputPage.getPositionCount()); for (int currentPosition = 0; currentPosition < inputPage.getPositionCount(); currentPosition++) { if (rowIdCounter >= maxRowIdCounterValue) { requestValues(); } long rowId = rowIdCounter++; verify((rowId & uniqueValueMask) == 0, "RowId and uniqueValue mask overlaps"); BIGINT.writeLong(block, uniqueValueMask | rowId); } return block.build(); } }
private static Page createPage() { BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(POSITIONS_PER_PAGE); BIGINT.writeLong(blockBuilder, 42L); return new Page(0, blockBuilder.build()); }
private static Page createLongBlockPage(long... values) { BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(values.length); for (long value : values) { BIGINT.writeLong(builder, value); } return new Page(builder.build()); } }
private Block createRowNumberBlock() { BlockBuilder rowNumberBlock = BIGINT.createFixedSizeBlockBuilder(inputPage.getPositionCount()); for (int currentPosition = 0; currentPosition < inputPage.getPositionCount(); currentPosition++) { long partitionId = getPartitionId(currentPosition); long nextRowCount = partitionRowCount.get(partitionId) + 1; BIGINT.writeLong(rowNumberBlock, nextRowCount); partitionRowCount.set(partitionId, nextRowCount); } return rowNumberBlock.build(); }
@Test public void testGetElementPosition() { int elementCount = 100; // Set initialTypedSetEntryCount to a small number to trigger rehash() int initialTypedSetEntryCount = 10; TypedSet typedSet = new TypedSet(BIGINT, initialTypedSetEntryCount, FUNCTION_NAME); BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(elementCount); for (int i = 0; i < elementCount; i++) { BIGINT.writeLong(blockBuilder, i); typedSet.add(blockBuilder, i); } assertEquals(typedSet.size(), elementCount); for (int j = 0; j < blockBuilder.getPositionCount(); j++) { assertEquals(typedSet.positionOf(blockBuilder, j), j); } }
@Test public void testGetElementPositionWithProvidedEmptyBlockBuilder() { int elementCount = 100; // Set initialTypedSetEntryCount to a small number to trigger rehash() int initialTypedSetEntryCount = 10; BlockBuilder emptyBlockBuilder = BIGINT.createFixedSizeBlockBuilder(elementCount); TypedSet typedSet = new TypedSet(BIGINT, emptyBlockBuilder, initialTypedSetEntryCount, FUNCTION_NAME); BlockBuilder externalBlockBuilder = BIGINT.createFixedSizeBlockBuilder(elementCount); for (int i = 0; i < elementCount; i++) { if (i % 10 == 0) { externalBlockBuilder.appendNull(); } else { BIGINT.writeLong(externalBlockBuilder, i); } typedSet.add(externalBlockBuilder, i); } assertEquals(typedSet.size(), emptyBlockBuilder.getPositionCount()); assertEquals(typedSet.size(), elementCount - elementCount / 10 + 1); for (int j = 0; j < typedSet.size(); j++) { assertEquals(typedSet.positionOf(emptyBlockBuilder, j), j); } }
private static Page createOneMegaBytePage() { BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(POSITIONS_PER_PAGE); while (blockBuilder.getRetainedSizeInBytes() < 1024 * 1024) { BIGINT.writeLong(blockBuilder, 42L); } return new Page(0, blockBuilder.build()); } }
@Test public void testBinaryMergeIteratorOverPageWith() { Page emptyPage = new Page(0, BIGINT.createFixedSizeBlockBuilder(0).build()); Page page = rowPagesBuilder(BIGINT).row(42).build().get(0); WorkProcessor<Page> mergedPage = new MergeHashSort(newSimpleAggregatedMemoryContext()).merge( ImmutableList.of(BIGINT), ImmutableList.of(BIGINT), ImmutableList.of(ImmutableList.of(emptyPage, page).iterator()).stream() .map(WorkProcessor::fromIterator) .collect(toImmutableList()), new DriverYieldSignal()); assertTrue(mergedPage.process()); Page actualPage = mergedPage.getResult(); assertEquals(actualPage.getPositionCount(), 1); assertEquals(actualPage.getChannelCount(), 1); assertEquals(actualPage.getBlock(0).getLong(0, 0), 42); assertFinishes(mergedPage); }
@Test public void testBinaryMergeIteratorOverEmptyPageAndNonEmptyPage() { Page emptyPage = new Page(0, BIGINT.createFixedSizeBlockBuilder(0).build()); Page page = rowPagesBuilder(BIGINT).row(42).build().get(0); WorkProcessor<Page> mergedPage = new MergeHashSort(newSimpleAggregatedMemoryContext()).merge( ImmutableList.of(BIGINT), ImmutableList.of(BIGINT), ImmutableList.of(ImmutableList.of(emptyPage, page).iterator()).stream() .map(WorkProcessor::fromIterator) .collect(toImmutableList()), new DriverYieldSignal()); assertTrue(mergedPage.process()); Page actualPage = mergedPage.getResult(); assertEquals(actualPage.getPositionCount(), 1); assertEquals(actualPage.getChannelCount(), 1); assertEquals(actualPage.getBlock(0).getLong(0, 0), 42); assertFinishes(mergedPage); }
BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(elementCount); for (int i = 0; i < elementCount; i++) { if (i % 10 == 0) {
BlockBuilder externalBlockBuilder = BIGINT.createFixedSizeBlockBuilder(elementCount); for (int i = 0; i < elementCount; i++) { if (i % 10 == 0) {