use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class BlockAssertions method createStringDictionaryBlock.
public static Block createStringDictionaryBlock(int start, int length) {
checkArgument(length > 5, "block must have more than 5 entries");
int dictionarySize = length / 5;
BlockBuilder builder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), dictionarySize);
for (int i = start; i < start + dictionarySize; i++) {
VARCHAR.writeString(builder, String.valueOf(i));
}
int[] ids = new int[length];
for (int i = 0; i < length; i++) {
ids[i] = i % dictionarySize;
}
return new DictionaryBlock(length, builder.build(), ids);
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestPageProcessorCompiler method testSanityColumnarDictionary.
@Test
public void testSanityColumnarDictionary() throws Exception {
PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()).compilePageProcessor(new ConstantExpression(TRUE, BOOLEAN), ImmutableList.of(new InputReferenceExpression(0, VARCHAR))).get();
Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR));
assertEquals(outputPage.getPositionCount(), 100);
assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock);
DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestPageProcessorCompiler method testSanityFilterOnDictionary.
@Test
public void testSanityFilterOnDictionary() throws Exception {
CallExpression lengthVarchar = new CallExpression(new Signature("length", SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.VARCHAR)), BIGINT, ImmutableList.of(new InputReferenceExpression(0, VARCHAR)));
Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
CallExpression filter = new CallExpression(lessThan, BOOLEAN, ImmutableList.of(lengthVarchar, new ConstantExpression(10L, BIGINT)));
PageProcessor processor = new ExpressionCompiler(createTestMetadataManager()).compilePageProcessor(filter, ImmutableList.of(new InputReferenceExpression(0, VARCHAR))).get();
Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
Page outputPage = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR));
assertEquals(outputPage.getPositionCount(), 100);
assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock);
DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
// test filter caching
Page outputPage2 = processor.processColumnarDictionary(null, page, ImmutableList.of(VARCHAR));
assertEquals(outputPage2.getPositionCount(), 100);
assertTrue(outputPage2.getBlock(0) instanceof DictionaryBlock);
DictionaryBlock dictionaryBlock2 = (DictionaryBlock) outputPage2.getBlock(0);
// both output pages must have the same dictionary
assertEquals(dictionaryBlock2.getDictionary(), dictionaryBlock.getDictionary());
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class GenericPageProcessor method projectDictionary.
private Block projectDictionary(ProjectionFunction projection, Page page) {
int inputChannel = getOnlyElement(projection.getInputChannels());
Block dictionary = ((DictionaryBlock) page.getBlock(inputChannel)).getDictionary();
int projectionIndex = projections.indexOf(projection);
if (inputDictionaries[projectionIndex] == dictionary) {
return outputDictionaries[projectionIndex];
}
BlockBuilder dictionaryBuilder = projection.getType().createBlockBuilder(new BlockBuilderStatus(), dictionary.getPositionCount());
Block[] blocks = new Block[page.getChannelCount()];
blocks[inputChannel] = dictionary;
for (int i = 0; i < dictionary.getPositionCount(); i++) {
projection.project(i, blocks, dictionaryBuilder);
}
inputDictionaries[projectionIndex] = dictionary;
outputDictionaries[projectionIndex] = dictionaryBuilder.build();
return outputDictionaries[projectionIndex];
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class GenericPageProcessor method projectColumnarDictionary.
private Block projectColumnarDictionary(Page inputPage, int[] selectedPositions, ProjectionFunction projection, Map<DictionaryId, DictionaryId> dictionarySourceIds) {
int inputChannel = getOnlyElement(projection.getInputChannels());
Block[] blocks = new Block[inputPage.getChannelCount()];
if (inputPage.getBlock(inputChannel) instanceof RunLengthEncodedBlock) {
RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) inputPage.getBlock(inputChannel);
BlockBuilder builder = projection.getType().createBlockBuilder(new BlockBuilderStatus(), 1);
blocks[inputChannel] = rleBlock.getValue();
projection.project(0, blocks, builder);
return new RunLengthEncodedBlock(builder.build(), selectedPositions.length);
}
Block outputDictionary = projectDictionary(projection, inputPage);
int[] outputIds = filterIds(projection, inputPage, selectedPositions);
DictionaryBlock dictionaryBlock = (DictionaryBlock) inputPage.getBlock(inputChannel);
DictionaryId sourceId = dictionarySourceIds.get(dictionaryBlock.getDictionarySourceId());
if (sourceId == null) {
sourceId = randomDictionaryId();
dictionarySourceIds.put(dictionaryBlock.getDictionarySourceId(), sourceId);
}
return new DictionaryBlock(selectedPositions.length, outputDictionary, outputIds, false, sourceId);
}
Aggregations