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;
}
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;
}
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);
}
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));
}
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);
}
Aggregations