private static Page createPage(int size) { return new Page(BlockAssertions.createLongSequenceBlock(0, size)); }
@Test public void testSimpleBlock() { Block block = createLongSequenceBlock(0, 100); testFilter(block, LongArrayBlock.class); }
@Test(dataProvider = "forceYield") public void testSimpleBlock(boolean forceYield) { Block block = createLongSequenceBlock(0, 100); testProject(block, block.getClass(), forceYield); }
@Override public Block[] getSequenceBlocks(int start, int length) { return new Block[] {createLongSequenceBlock(start, start + length), createLongRepeatBlock(2, length)}; }
@Test(dataProvider = "forceYield") public void testRleBlock(boolean forceYield) { Block value = createLongSequenceBlock(42, 43); RunLengthEncodedBlock block = new RunLengthEncodedBlock(value, 100); testProject(block, RunLengthEncodedBlock.class, forceYield); }
@Test(dataProvider = "forceYield") public void testRleBlockWithFailure(boolean forceYield) { Block value = createLongSequenceBlock(-43, -42); RunLengthEncodedBlock block = new RunLengthEncodedBlock(value, 100); testProjectFails(block, RunLengthEncodedBlock.class, forceYield); }
@Test public void testProjectNoColumns() { PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(), OptionalInt.of(MAX_BATCH_SIZE)); Page inputPage = new Page(createLongSequenceBlock(0, 100)); Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage); List<Optional<Page>> outputPages = ImmutableList.copyOf(output); assertEquals(outputPages.size(), 1); Page outputPage = outputPages.get(0).orElse(null); assertEquals(outputPage.getChannelCount(), 0); assertEquals(outputPage.getPositionCount(), inputPage.getPositionCount()); }
private static DictionaryBlock createDictionaryBlockWithUnusedEntries(int dictionarySize, int blockSize) { Block dictionary = createLongSequenceBlock(-10, dictionarySize); int[] ids = new int[blockSize]; Arrays.setAll(ids, index -> (index % dictionarySize) + 10); return new DictionaryBlock(dictionary, ids); }
private static DictionaryBlock createDictionaryBlock(int dictionarySize, int blockSize) { Block dictionary = createLongSequenceBlock(0, dictionarySize); int[] ids = new int[blockSize]; Arrays.setAll(ids, index -> index % dictionarySize); return new DictionaryBlock(dictionary, ids); }
private static DictionaryBlock createDictionaryBlockWithFailure(int dictionarySize, int blockSize) { Block dictionary = createLongSequenceBlock(-10, dictionarySize - 10); int[] ids = new int[blockSize]; Arrays.setAll(ids, index -> index % dictionarySize); return new DictionaryBlock(dictionary, ids); }
private static DictionaryBlock createDictionaryBlock(int dictionarySize, int blockSize) { Block dictionary = createLongSequenceBlock(0, dictionarySize); int[] ids = new int[blockSize]; Arrays.setAll(ids, index -> index % dictionarySize); return new DictionaryBlock(dictionary, ids); }
private static DictionaryBlock createDictionaryBlockWithUnusedEntries(int dictionarySize, int blockSize) { Block dictionary = createLongSequenceBlock(-10, dictionarySize); int[] ids = new int[blockSize]; Arrays.setAll(ids, index -> (index % dictionarySize) + 10); return new DictionaryBlock(dictionary, ids); }
private static DictionaryBlock createDictionaryBlockWithFailure(int dictionarySize, int blockSize) { Block dictionary = createLongSequenceBlock(-10, dictionarySize - 10); int[] ids = new int[blockSize]; Arrays.setAll(ids, index -> index % dictionarySize); return new DictionaryBlock(dictionary, ids); }
@Test public void testSelectAllFilter() { PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new InputPageProjection(0, BIGINT)), OptionalInt.of(MAX_BATCH_SIZE)); Page inputPage = new Page(createLongSequenceBlock(0, 100)); Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage); List<Optional<Page>> outputPages = ImmutableList.copyOf(output); assertEquals(outputPages.size(), 1); assertPageEquals(ImmutableList.of(BIGINT), outputPages.get(0).orElse(null), new Page(createLongSequenceBlock(0, 100))); }
@Test public void testProjectLazyLoad() { PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new LazyPagePageProjection()), OptionalInt.of(MAX_BATCH_SIZE)); // if channel 1 is loaded, test will fail Page inputPage = new Page(createLongSequenceBlock(0, 100), new LazyBlock(100, lazyBlock -> { throw new AssertionError("Lazy block should not be loaded"); })); LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()); Iterator<Optional<Page>> output = pageProcessor.process(SESSION, new DriverYieldSignal(), memoryContext, inputPage); List<Optional<Page>> outputPages = ImmutableList.copyOf(output); assertEquals(outputPages.size(), 1); assertPageEquals(ImmutableList.of(BIGINT), outputPages.get(0).orElse(null), new Page(createLongSequenceBlock(0, 100))); }
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 testSelectNoneFilter() { PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(new InputPageProjection(0, BIGINT))); Page inputPage = new Page(createLongSequenceBlock(0, 100)); LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()); Iterator<Optional<Page>> output = pageProcessor.process(SESSION, new DriverYieldSignal(), memoryContext, inputPage); assertEquals(memoryContext.getBytes(), 0); List<Optional<Page>> outputPages = ImmutableList.copyOf(output); assertEquals(outputPages.size(), 0); }
@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)); }
@Test public void testProjectEmptyPage() { PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new InputPageProjection(0, BIGINT))); Page inputPage = new Page(createLongSequenceBlock(0, 0)); LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()); Iterator<Optional<Page>> output = pageProcessor.process(SESSION, new DriverYieldSignal(), memoryContext, inputPage); assertEquals(memoryContext.getBytes(), 0); // output should be one page containing no columns (only a count) List<Optional<Page>> outputPages = ImmutableList.copyOf(output); assertEquals(outputPages.size(), 0); }
@Test public void testDictionaryBlock() { // match some testFilter(createDictionaryBlock(20, 100), LongArrayBlock.class); // match none testFilter(createDictionaryBlock(20, 0), LongArrayBlock.class); // match all testFilter(new DictionaryBlock(createLongSequenceBlock(4, 5), new int[100]), LongArrayBlock.class); }