@Override public Work<?> addPage(Page page) { currentPageSizeInBytes = page.getRetainedSizeInBytes(); if (isRunLengthEncoded(page)) { return new AddRunLengthEncodedPageWork(page); } if (canProcessDictionary(page)) { return new AddDictionaryPageWork(page); } return new AddNonDictionaryPageWork(page); }
@Override public Work<GroupByIdBlock> getGroupIds(Page page) { currentPageSizeInBytes = page.getRetainedSizeInBytes(); if (isRunLengthEncoded(page)) { return new GetRunLengthEncodedGroupIdsWork(page); } if (canProcessDictionary(page)) { return new GetDictionaryGroupIdsWork(page); } return new GetNonDictionaryGroupIdsWork(page); }
@Override public void addPage(Page page) { Block maskBlock = null; if (maskChannel >= 0) { maskBlock = page.getBlock(maskChannel); } if (canProcessDictionary(page)) { addDictionaryPage(page); return; } // get the group id for each position int positionCount = page.getPositionCount(); for (int position = 0; position < positionCount; position++) { // skip masked rows if (maskBlock != null && !BOOLEAN.getBoolean(maskBlock, position)) { continue; } // get the group for the current row putIfAbsent(position, page); } }
private void addDictionaryPage(Page page) { verify(canProcessDictionary(page), "invalid call to addDictionaryPage"); DictionaryBlock dictionaryBlock = (DictionaryBlock) page.getBlock(channels[0]); updateDictionaryLookBack(dictionaryBlock.getDictionary()); Page dictionaryPage = createPageWithExtractedDictionary(page); for (int i = 0; i < page.getPositionCount(); i++) { int positionInDictionary = dictionaryBlock.getId(i); getGroupId(hashGenerator, dictionaryPage, positionInDictionary); } }
@Override public GroupByIdBlock getGroupIds(Page page) { int positionCount = page.getPositionCount(); // we know the exact size required for the block BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(positionCount); Block maskBlock = null; if (maskChannel >= 0) { maskBlock = page.getBlock(maskChannel); } if (canProcessDictionary(page)) { Block groupIds = processDictionary(page); return new GroupByIdBlock(nextGroupId, groupIds); } // get the group id for each position for (int position = 0; position < positionCount; position++) { // skip masked rows if (maskBlock != null && !BOOLEAN.getBoolean(maskBlock, position)) { blockBuilder.appendNull(); continue; } // get the group for the current row int groupId = putIfAbsent(position, page); // output the group id for this row BIGINT.writeLong(blockBuilder, groupId); } return new GroupByIdBlock(nextGroupId, blockBuilder.build()); }
private Block processDictionary(Page page) { verify(canProcessDictionary(page), "invalid call to processDictionary"); DictionaryBlock dictionaryBlock = (DictionaryBlock) page.getBlock(channels[0]); updateDictionaryLookBack(dictionaryBlock.getDictionary()); Page dictionaryPage = createPageWithExtractedDictionary(page); BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(page.getPositionCount()); for (int i = 0; i < page.getPositionCount(); i++) { int positionInDictionary = dictionaryBlock.getId(i); int groupId = getGroupId(hashGenerator, dictionaryPage, positionInDictionary); BIGINT.writeLong(blockBuilder, groupId); } verify(blockBuilder.getPositionCount() == page.getPositionCount(), "invalid position count"); return blockBuilder.build(); }