Search in sources :

Example 16 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestArrayOfRowsUnnester method testArrayOfRowsUnnester.

/**
 * Test operations of ArrayOfRowUnnester incrementally on the input.
 * Output final blocks after the whole input has been processed.
 *
 * Input 3d array {@code elements} stores values from a column with type <array<row<varchar, varchar, ... {@code fieldCount} times> >.
 * elements[i] corresponds to a position in this column, represents one array of row(....).
 * elements[i][j] represents one row(....) object in the array.
 * elements[i][j][k] represents value of kth field in row(...) object.
 */
private static Block[] testArrayOfRowsUnnester(int[] requiredOutputCounts, int[] unnestedLengths, Slice[][][] elements, int fieldCount) {
    validateTestInput(requiredOutputCounts, unnestedLengths, elements, fieldCount);
    int positionCount = requiredOutputCounts.length;
    // True if there is a null Row element inside the array at this position
    boolean[] containsNullRowElement = new boolean[positionCount];
    // Populate containsNullRowElement
    for (int i = 0; i < positionCount; i++) {
        containsNullRowElement[i] = false;
        if (elements[i] != null) {
            for (int j = 0; j < elements[i].length; j++) {
                if (elements[i][j] == null) {
                    containsNullRowElement[i] = true;
                }
            }
        }
    }
    // Check for null elements in individual input fields
    boolean[] nullsPresent = new boolean[fieldCount];
    for (int field = 0; field < fieldCount; field++) {
        nullsPresent[field] = nullExists(elements[field]);
    }
    // Create the unnester and input block
    RowType rowType = RowType.anonymous(Collections.nCopies(fieldCount, VARCHAR));
    Unnester arrayofRowsUnnester = new ArrayOfRowsUnnester(rowType);
    Block arrayBlockOfRows = createArrayBlockOfRowBlocks(elements, rowType);
    Block[] blocks = null;
    // Verify output being produced after processing every position. (quadratic)
    for (int inputTestCount = 1; inputTestCount <= elements.length; inputTestCount++) {
        // Reset input and prepare for new output
        PageBuilderStatus status = new PageBuilderStatus();
        arrayofRowsUnnester.resetInput(arrayBlockOfRows);
        assertEquals(arrayofRowsUnnester.getInputEntryCount(), elements.length);
        arrayofRowsUnnester.startNewOutput(status, 10);
        boolean misAligned = false;
        // Process inputTestCount positions
        for (int i = 0; i < inputTestCount; i++) {
            arrayofRowsUnnester.processCurrentAndAdvance(requiredOutputCounts[i]);
            int elementsSize = (elements[i] != null ? elements[i].length : 0);
            // (2) null Row element
            if ((requiredOutputCounts[i] > elementsSize) || containsNullRowElement[i]) {
                misAligned = true;
            }
        }
        // Build output block and verify
        blocks = arrayofRowsUnnester.buildOutputBlocksAndFlush();
        assertEquals(blocks.length, rowType.getFields().size());
        // Verify output blocks for individual fields
        for (int field = 0; field < blocks.length; field++) {
            assertTrue((blocks[field] instanceof DictionaryBlock) || (!nullsPresent[field] && misAligned));
            assertFalse((blocks[field] instanceof DictionaryBlock) && (!nullsPresent[field] && misAligned));
            Slice[][] fieldElements = getFieldElements(elements, field);
            Slice[] expectedOutput = computeExpectedUnnestedOutput(fieldElements, requiredOutputCounts, 0, inputTestCount);
            assertBlock(blocks[field], expectedOutput);
        }
    }
    return blocks;
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) RowType(io.prestosql.spi.type.RowType) PageBuilderStatus(io.prestosql.spi.block.PageBuilderStatus) Slice(io.airlift.slice.Slice) ColumnarTestUtils.assertBlock(io.prestosql.block.ColumnarTestUtils.assertBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block)

Example 17 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestArrayUnnester method testArrayUnnester.

private static Block[] testArrayUnnester(int[] requiredOutputCounts, int[] unnestedLengths, Slice[][][] elements) {
    Slice[][] slices = getFieldElements(elements, 0);
    validateTestInput(requiredOutputCounts, unnestedLengths, elements, 1);
    // Check if there is a null element in the input
    boolean nullPresent = nullExists(slices);
    // Initialize unnester
    Unnester arrayUnnester = new ArrayUnnester(VARCHAR);
    Block arrayBlock = createArrayBlock(slices);
    Block[] blocks = null;
    // Verify output being produced after processing every position. (quadratic)
    for (int inputTestCount = 1; inputTestCount <= elements.length; inputTestCount++) {
        // Reset input
        arrayUnnester.resetInput(arrayBlock);
        assertEquals(arrayUnnester.getInputEntryCount(), elements.length);
        // Prepare for new output
        PageBuilderStatus status = new PageBuilderStatus();
        arrayUnnester.startNewOutput(status, 10);
        boolean misAligned = false;
        // Process inputTestCount positions
        for (int i = 0; i < inputTestCount; i++) {
            int elementsSize = (elements[i] != null ? elements[i].length : 0);
            assertEquals(arrayUnnester.getCurrentUnnestedLength(), elementsSize);
            arrayUnnester.processCurrentAndAdvance(requiredOutputCounts[i]);
            if (requiredOutputCounts[i] > elementsSize) {
                misAligned = true;
            }
        }
        // Verify output
        blocks = arrayUnnester.buildOutputBlocksAndFlush();
        assertEquals(blocks.length, 1);
        assertTrue((blocks[0] instanceof DictionaryBlock) || (!nullPresent && misAligned));
        assertFalse((blocks[0] instanceof DictionaryBlock) && (!nullPresent && misAligned));
        Slice[] expectedOutput = computeExpectedUnnestedOutput(slices, requiredOutputCounts, 0, inputTestCount);
        assertBlock(blocks[0], expectedOutput);
    }
    return blocks;
}
Also used : PageBuilderStatus(io.prestosql.spi.block.PageBuilderStatus) Slice(io.airlift.slice.Slice) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) TestUnnesterUtil.createArrayBlock(io.prestosql.operator.unnest.TestUnnesterUtil.createArrayBlock) ColumnarTestUtils.assertBlock(io.prestosql.block.ColumnarTestUtils.assertBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block)

Example 18 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestReplicatedBlockBuilder method testReplication.

private static void testReplication(Slice[] values, int[] counts) {
    assertEquals(values.length, counts.length);
    ReplicatedBlockBuilder replicateBlockBuilder = new ReplicatedBlockBuilder();
    Block valuesBlock = createSimpleBlock(values);
    replicateBlockBuilder.resetInputBlock(valuesBlock);
    replicateBlockBuilder.startNewOutput(100);
    for (int i = 0; i < counts.length; i++) {
        replicateBlockBuilder.appendRepeated(i, counts[i]);
    }
    Block outputBlock = replicateBlockBuilder.buildOutputAndFlush();
    assertBlock(outputBlock, createReplicatedOutputSlice(values, counts));
    assertTrue(outputBlock instanceof DictionaryBlock);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) TestUnnesterUtil.createSimpleBlock(io.prestosql.operator.unnest.TestUnnesterUtil.createSimpleBlock) ColumnarTestUtils.assertBlock(io.prestosql.block.ColumnarTestUtils.assertBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block)

Example 19 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestUnnestBlockBuilder method testAppendRange.

private static void testAppendRange(UnnestBlockBuilder unnestBlockBuilder, Slice[] values) {
    unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
    assertTrue(values.length >= 3, "test requires at least 3 elements in values");
    int startIndex = 1;
    int length = values.length - 2;
    unnestBlockBuilder.appendRange(startIndex, length);
    Block block = unnestBlockBuilder.buildOutputAndFlush();
    assertTrue(block instanceof DictionaryBlock);
    assertBlock(block, Arrays.copyOfRange(values, startIndex, startIndex + length));
}
Also used : PageBuilderStatus(io.prestosql.spi.block.PageBuilderStatus) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) TestUnnesterUtil.createSimpleBlock(io.prestosql.operator.unnest.TestUnnesterUtil.createSimpleBlock) ColumnarTestUtils.assertBlock(io.prestosql.block.ColumnarTestUtils.assertBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block)

Example 20 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestPageProcessorCompiler method testNonDeterministicProject.

@Test
public void testNonDeterministicProject() {
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression random = new CallExpression(QualifiedObjectName.valueOfDefaultFunction("random").getObjectName(), new BuiltInFunctionHandle(new Signature(QualifiedObjectName.valueOfDefaultFunction("random"), SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))), BIGINT, singletonList(constant(10L, BIGINT)), Optional.empty());
    InputReferenceExpression col0 = field(0, BIGINT);
    CallExpression lessThanRandomExpression = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(col0, random), Optional.empty());
    PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(lessThanRandomExpression), MAX_BATCH_SIZE).get();
    assertFalse(new RowExpressionDeterminismEvaluator(metadata).isDeterministic(lessThanRandomExpression));
    Page page = new Page(createLongDictionaryBlock(1, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock);
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) PageProcessor(io.prestosql.operator.project.PageProcessor) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(io.prestosql.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Page(io.prestosql.spi.Page) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Aggregations

DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)69 Block (io.prestosql.spi.block.Block)31 Test (org.testng.annotations.Test)29 Slice (io.airlift.slice.Slice)17 BlockBuilder (io.prestosql.spi.block.BlockBuilder)16 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)11 Page (io.prestosql.spi.Page)9 ColumnarTestUtils.assertBlock (io.prestosql.block.ColumnarTestUtils.assertBlock)8 LazyBlock (io.prestosql.spi.block.LazyBlock)8 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)8 PageBuilderStatus (io.prestosql.spi.block.PageBuilderStatus)8 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)7 DictionaryId (io.prestosql.spi.block.DictionaryId)6 TestUnnesterUtil.createSimpleBlock (io.prestosql.operator.unnest.TestUnnesterUtil.createSimpleBlock)5 DictionaryId.randomDictionaryId (io.prestosql.spi.block.DictionaryId.randomDictionaryId)5 BlockAssertions.createLongsBlock (io.prestosql.block.BlockAssertions.createLongsBlock)4 BlockAssertions.createLongDictionaryBlock (io.prestosql.block.BlockAssertions.createLongDictionaryBlock)3 ColumnarTestUtils.createTestDictionaryBlock (io.prestosql.block.ColumnarTestUtils.createTestDictionaryBlock)3 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)3 JoinProbeFactory (io.prestosql.operator.JoinProbe.JoinProbeFactory)3