use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class CommonSubExpressionBenchmark method createDictionaryStringJsonPage.
private static Page createDictionaryStringJsonPage() {
int dictionarySize = POSITIONS / 5;
BlockBuilder builder = VARCHAR.createBlockBuilder(null, dictionarySize);
for (int i = 0; i < dictionarySize; i++) {
VARCHAR.writeString(builder, "{\"a\": 1, \"b\": 2}");
}
int[] ids = new int[POSITIONS];
for (int i = 0; i < POSITIONS; i++) {
ids[i] = i % dictionarySize;
}
return new Page(new DictionaryBlock(builder.build(), ids));
}
use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class MultiChannelGroupByHash method createPageWithExtractedDictionary.
// For a page that contains DictionaryBlocks, create a new page in which
// the dictionaries from the DictionaryBlocks are extracted into the corresponding channels
// From Page(DictionaryBlock1, DictionaryBlock2) create new page with Page(dictionary1, dictionary2)
private Page createPageWithExtractedDictionary(Page page) {
Block[] blocks = new Block[page.getChannelCount()];
Block dictionary = ((DictionaryBlock) page.getBlock(channels[0])).getDictionary();
// extract data dictionary
blocks[channels[0]] = dictionary;
// extract hash dictionary
if (inputHashChannel.isPresent()) {
blocks[inputHashChannel.get()] = ((DictionaryBlock) page.getBlock(inputHashChannel.get())).getDictionary();
}
return new Page(dictionary.getPositionCount(), blocks);
}
use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class TestPageSplitterUtil method testSplitDictionaryBlock.
@Test
public void testSplitDictionaryBlock() {
// create a huge dictionary with a single entry
Block dictionary = createSlicesBlock(Slices.utf8Slice(new String(new char[1_000_000])));
// make every row in the block identical to the single entry in the dictionary
DictionaryBlock dictionaryBlock = createRandomDictionaryBlock(dictionary, 50000);
List<Page> pages = splitPage(new Page(dictionaryBlock), 1000);
assertEquals(pages.size(), 2);
}
use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class TestPageProcessorCompiler method testSanityFilterOnDictionary.
@Test
public void testSanityFilterOnDictionary() {
FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
CallExpression lengthVarchar = new CallExpression("length", functionAndTypeManager.lookupFunction("length", fromTypes(VARCHAR)), BIGINT, ImmutableList.of(field(0, VARCHAR)));
FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
CallExpression filter = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(lengthVarchar, constant(10L, BIGINT)));
PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(0, VARCHAR)), false, MAX_BATCH_SIZE).get();
Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
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 = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
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.common.block.DictionaryBlock in project presto by prestodb.
the class TestPageProcessorCompiler method testSanityColumnarDictionary.
@Test
public void testSanityColumnarDictionary() {
PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(field(0, VARCHAR)), false, MAX_BATCH_SIZE).get();
Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
assertEquals(outputPage.getPositionCount(), 100);
assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock);
DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
}
Aggregations