private static Page extractColumns(Page page, int[] columns) { Block[] blocks = new Block[columns.length]; for (int i = 0; i < columns.length; i++) { int dataColumn = columns[i]; blocks[i] = page.getBlock(dataColumn); } return new Page(page.getPositionCount(), blocks); }
@Override public Page getNextPage() { Page nextPage = delegate.getNextPage(); if (nextPage == null) { return null; } Block[] blocks = Arrays.stream(delegateFieldIndex) .mapToObj(nextPage::getBlock) .toArray(Block[]::new); return new Page(nextPage.getPositionCount(), blocks); }
@Test public void testGetRegion() { assertEquals(new Page(10).getRegion(5, 5).getPositionCount(), 5); }
@Test public void testForceRehash() { // Create a page with positionCount >> expected size of groupByHash Block valuesBlock = BlockAssertions.createStringSequenceBlock(0, 100); Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(VARCHAR), valuesBlock); // Create group by hash with extremely small size GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] {0}, Optional.of(1), 4, JOIN_COMPILER); groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process(); // Ensure that all groups are present in group by hash for (int i = 0; i < valuesBlock.getPositionCount(); i++) { assertTrue(groupByHash.contains(i, new Page(valuesBlock, hashBlock), CONTAINS_CHANNELS)); } }
@Override public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns) { requireNonNull(columns, "columns is null"); ImmutableList<Block> blocks = columns.stream() .map(column -> new FixedWidthBlockBuilder(0, 1).appendNull().build()) .collect(toImmutableList()); return new FixedPageSource(ImmutableList.of(new Page(blocks.toArray(new Block[blocks.size()])))); } }
@Test public void testHappyPath() throws Exception Page expectedPage = new Page(100); requestComplete.await(10, TimeUnit.SECONDS); assertEquals(callback.getPages().size(), 1); assertPageEquals(expectedPage, callback.getPages().get(0)); assertEquals(callback.getCompletedRequests(), 1); assertEquals(callback.getFinishedBuffers(), 0); assertStatus(client, location, "queued", 1, 1, 1, 0, "not scheduled");
public static Page[] createPages(Block[] blocks) { int positions = blocks[0].getPositionCount(); for (int i = 1; i < blocks.length; i++) { assertEquals(positions, blocks[i].getPositionCount(), "input blocks provided are not equal in position count"); } if (positions == 0) { return new Page[] {}; } else if (positions == 1) { return new Page[] {new Page(positions, blocks)}; } else { int split = positions / 2; // [0, split - 1] goes to first list of blocks; [split, positions - 1] goes to second list of blocks. Block[] blockArray1 = new Block[blocks.length]; Block[] blockArray2 = new Block[blocks.length]; for (int i = 0; i < blocks.length; i++) { blockArray1[i] = blocks[i].getRegion(0, split); blockArray2[i] = blocks[i].getRegion(split, positions - split); } return new Page[] {new Page(blockArray1), new Page(blockArray2)}; } }
@Test public void testGetEmptyRegion() { assertEquals(new Page(0).getRegion(0, 0).getPositionCount(), 0); assertEquals(new Page(10).getRegion(5, 0).getPositionCount(), 0); }
@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); }
public ChannelSetBuilder(Type type, Optional<Integer> hashChannel, int expectedPositions, OperatorContext operatorContext, JoinCompiler joinCompiler) { List<Type> types = ImmutableList.of(type); this.hash = createGroupByHash( types, HASH_CHANNELS, hashChannel, expectedPositions, isDictionaryAggregationEnabled(operatorContext.getSession()), joinCompiler, this::updateMemoryReservation); this.nullBlockPage = new Page(type.createBlockBuilder(null, 1, UNKNOWN.getFixedSize()).appendNull().build()); this.operatorContext = requireNonNull(operatorContext, "operatorContext is null"); this.localMemoryContext = operatorContext.localUserMemoryContext(); }
@Test public void testOutOfBound() { InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("max_by", AGGREGATE, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))); try { groupedAggregation(function, new Page(createStringsBlock("z"), createLongsBlock(0), createLongsBlock(10001))); } catch (PrestoException e) { assertEquals(e.getMessage(), "third argument of max_by/min_by must be less than or equal to 10000; found 10001"); } } }
private static int computeActual(List<String> hiveTypeStrings, List<Object> hiveValues, int bucketCount, List<HiveType> hiveTypes, List<TypeInfo> hiveTypeInfos) { ImmutableList.Builder<Block> blockListBuilder = ImmutableList.builder(); Object[] nativeContainerValues = new Object[hiveValues.size()]; for (int i = 0; i < hiveTypeStrings.size(); i++) { Object hiveValue = hiveValues.get(i); Type type = hiveTypes.get(i).getType(TYPE_MANAGER); BlockBuilder blockBuilder = type.createBlockBuilder(null, 3); // prepend 2 nulls to make sure position is respected when HiveBucketing function blockBuilder.appendNull(); blockBuilder.appendNull(); appendToBlockBuilder(type, hiveValue, blockBuilder); Block block = blockBuilder.build(); blockListBuilder.add(block); nativeContainerValues[i] = toNativeContainerValue(type, hiveValue); } ImmutableList<Block> blockList = blockListBuilder.build(); int result1 = HiveBucketing.getHiveBucket(bucketCount, hiveTypeInfos, new Page(blockList.toArray(new Block[blockList.size()])), 2); int result2 = HiveBucketing.getHiveBucket(bucketCount, hiveTypeInfos, nativeContainerValues); assertEquals(result1, result2, "Overloads of getHiveBucket produced different result"); return result1; }
private static Page extractColumns(Page page, int[] channels) { Block[] newBlocks = new Block[channels.length]; for (int i = 0; i < channels.length; i++) { newBlocks[i] = page.getBlock(channels[i]); } return new Page(page.getPositionCount(), newBlocks); }
@Override public void addInput(Page page) { requireNonNull(page, "page is null"); checkState(!isFinished(), "Operator is already finished"); Block sourceBlock = page.getBlock(setChannel); Page sourcePage = hashChannel.isPresent() ? new Page(sourceBlock, page.getBlock(hashChannel.get())) : new Page(sourceBlock); unfinishedWork = channelSetBuilder.addPage(sourcePage); processUnfinishedWork(); }
@Test public void testGetRegionFromNoColumnPage() { assertEquals(new Page(100).getRegion(0, 10).getPositionCount(), 10); }
@Test public void testContains() { Block valuesBlock = BlockAssertions.createDoubleSequenceBlock(0, 10); Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(DOUBLE), valuesBlock); GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(DOUBLE), new int[] {0}, Optional.of(1), 100, JOIN_COMPILER); groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process(); Block testBlock = BlockAssertions.createDoublesBlock((double) 3); Block testHashBlock = TypeUtils.getHashBlock(ImmutableList.of(DOUBLE), testBlock); assertTrue(groupByHash.contains(0, new Page(testBlock, testHashBlock), CONTAINS_CHANNELS)); testBlock = BlockAssertions.createDoublesBlock(11.0); testHashBlock = TypeUtils.getHashBlock(ImmutableList.of(DOUBLE), testBlock); assertFalse(groupByHash.contains(0, new Page(testBlock, testHashBlock), CONTAINS_CHANNELS)); }
@Setup public void setup() { MetadataManager metadata = MetadataManager.createTestMetadataManager(); metadata.addFunctions(extractFunctions(BenchmarkArrayDistinct.class)); ExpressionCompiler compiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)); ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder(); Block[] blocks = new Block[TYPES.size()]; for (int i = 0; i < TYPES.size(); i++) { Type elementType = TYPES.get(i); ArrayType arrayType = new ArrayType(elementType); Signature signature = new Signature(name, FunctionKind.SCALAR, arrayType.getTypeSignature(), arrayType.getTypeSignature()); projectionsBuilder.add(new CallExpression(signature, arrayType, ImmutableList.of(field(i, arrayType)))); blocks[i] = createChannel(POSITIONS, ARRAY_SIZE, arrayType); } ImmutableList<RowExpression> projections = projectionsBuilder.build(); pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get(); page = new Page(blocks); }