use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class PagePartitioner method partitionBySingleRleValue.
private void partitionBySingleRleValue(Page page, int position, Page partitionFunctionArgs, IntArrayList[] partitionPositions) {
// copy all positions because all hash function args are the same for every position
if (nullChannel != -1 && page.getBlock(nullChannel).isNull(0)) {
verify(page.getBlock(nullChannel) instanceof RunLengthEncodedBlock, "null channel is not RunLengthEncodedBlock", page.getBlock(nullChannel));
// all positions are null
int[] allPositions = integersInRange(position, page.getPositionCount());
for (IntList partitionPosition : partitionPositions) {
partitionPosition.addElements(position, allPositions);
}
} else {
// extract rle page to prevent JIT profile pollution
Page rlePage = extractRlePage(partitionFunctionArgs);
int partition = partitionFunction.getPartition(rlePage, 0);
IntArrayList positions = partitionPositions[partition];
for (int i = position; i < page.getPositionCount(); i++) {
positions.add(i);
}
}
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class HiveUpdatablePageSource method updateRows.
@Override
public void updateRows(Page page, List<Integer> columnValueAndRowIdChannels) {
int positionCount = page.getPositionCount();
// should be filtered out by engine
verify(positionCount > 0, "Unexpected empty page");
HiveUpdateProcessor updateProcessor = transaction.getUpdateProcessor().orElseThrow(() -> new IllegalArgumentException("updateProcessor not present"));
ColumnarRow acidBlock = updateProcessor.getAcidBlock(page, columnValueAndRowIdChannels);
int fieldCount = acidBlock.getFieldCount();
checkArgument(fieldCount == 3 || fieldCount == 4, "The rowId block for UPDATE should have 3 or 4 children, but has %s", fieldCount);
deleteRowsInternal(acidBlock);
Block mergedColumnsBlock = updateProcessor.createMergedColumnsBlock(page, columnValueAndRowIdChannels);
Block currentTransactionBlock = RunLengthEncodedBlock.create(BIGINT, writeId, positionCount);
Block[] blockArray = { new RunLengthEncodedBlock(INSERT_OPERATION_BLOCK, positionCount), currentTransactionBlock, acidBlock.getField(BUCKET_CHANNEL), createRowIdBlock(positionCount), currentTransactionBlock, mergedColumnsBlock };
Page insertPage = new Page(blockArray);
lazyInitializeInsertFileWriter();
insertFileWriter.orElseThrow(() -> new IllegalArgumentException("insertFileWriter not present")).appendRows(insertPage);
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class HiveUpdatablePageSource method deleteRowsInternal.
private void deleteRowsInternal(ColumnarRow columnarRow) {
int positionCount = columnarRow.getPositionCount();
if (columnarRow.mayHaveNull()) {
for (int position = 0; position < positionCount; position++) {
checkArgument(!columnarRow.isNull(position), "In the delete rowIds, found null row at position %s", position);
}
}
Block originalTransactionChannel = columnarRow.getField(ORIGINAL_TRANSACTION_CHANNEL);
Block[] blockArray = { new RunLengthEncodedBlock(DELETE_OPERATION_BLOCK, positionCount), originalTransactionChannel, columnarRow.getField(BUCKET_CHANNEL), columnarRow.getField(ROW_ID_CHANNEL), RunLengthEncodedBlock.create(BIGINT, writeId, positionCount), new RunLengthEncodedBlock(hiveRowTypeNullsBlock, positionCount) };
Page deletePage = new Page(blockArray);
for (int index = 0; index < positionCount; index++) {
maxWriteId = Math.max(maxWriteId, originalTransactionChannel.getLong(index, 0));
}
lazyInitializeDeleteFileWriter();
deleteFileWriter.orElseThrow(() -> new IllegalArgumentException("deleteFileWriter not present")).appendRows(deletePage);
rowCount += positionCount;
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class RcFilePageSource method getNextPage.
@Override
public Page getNextPage() {
try {
// advance in the current batch
pageId++;
// if the batch has been consumed, read the next batch
int currentPageSize = rcFileReader.advance();
if (currentPageSize < 0) {
close();
return null;
}
Block[] blocks = new Block[hiveColumnIndexes.length];
for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
if (constantBlocks[fieldId] != null) {
blocks[fieldId] = new RunLengthEncodedBlock(constantBlocks[fieldId], currentPageSize);
} else {
blocks[fieldId] = createBlock(currentPageSize, fieldId);
}
}
return new Page(currentPageSize, blocks);
} catch (TrinoException e) {
closeAllSuppress(e, this);
throw e;
} catch (RcFileCorruptionException e) {
closeAllSuppress(e, this);
throw new TrinoException(HIVE_BAD_DATA, format("Corrupted RC file: %s", rcFileReader.getId()), e);
} catch (IOException | RuntimeException e) {
closeAllSuppress(e, this);
throw new TrinoException(HIVE_CURSOR_ERROR, format("Failed to read RC file: %s", rcFileReader.getId()), e);
}
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestGroupByHash method testProperWorkTypesSelected.
@Test
public void testProperWorkTypesSelected() {
Block bigintBlock = BlockAssertions.createLongsBlock(1, 2, 3, 4, 5, 6, 7, 8);
Block bigintDictionaryBlock = BlockAssertions.createLongDictionaryBlock(0, 8);
Block bigintRleBlock = BlockAssertions.createRLEBlock(42, 8);
Block varcharBlock = BlockAssertions.createStringsBlock("1", "2", "3", "4", "5", "6", "7", "8");
Block varcharDictionaryBlock = BlockAssertions.createStringDictionaryBlock(1, 8);
Block varcharRleBlock = new RunLengthEncodedBlock(new VariableWidthBlock(1, Slices.EMPTY_SLICE, new int[] { 0, 1 }, Optional.empty()), 8);
Block bigintBigDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 8, 1000);
Block bigintSingletonDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 500000, 1);
// Above Short.MAX_VALUE
Block bigintHugeDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 500000, 66000);
Page singleBigintPage = new Page(bigintBlock);
assertGroupByHashWork(singleBigintPage, ImmutableList.of(BIGINT), BigintGroupByHash.GetGroupIdsWork.class);
Page singleBigintDictionaryPage = new Page(bigintDictionaryBlock);
assertGroupByHashWork(singleBigintDictionaryPage, ImmutableList.of(BIGINT), BigintGroupByHash.GetDictionaryGroupIdsWork.class);
Page singleBigintRlePage = new Page(bigintRleBlock);
assertGroupByHashWork(singleBigintRlePage, ImmutableList.of(BIGINT), BigintGroupByHash.GetRunLengthEncodedGroupIdsWork.class);
Page singleVarcharPage = new Page(varcharBlock);
assertGroupByHashWork(singleVarcharPage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
Page singleVarcharDictionaryPage = new Page(varcharDictionaryBlock);
assertGroupByHashWork(singleVarcharDictionaryPage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetDictionaryGroupIdsWork.class);
Page singleVarcharRlePage = new Page(varcharRleBlock);
assertGroupByHashWork(singleVarcharRlePage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetRunLengthEncodedGroupIdsWork.class);
Page lowCardinalityDictionaryPage = new Page(bigintDictionaryBlock, varcharDictionaryBlock);
assertGroupByHashWork(lowCardinalityDictionaryPage, ImmutableList.of(BIGINT, VARCHAR), MultiChannelGroupByHash.GetLowCardinalityDictionaryGroupIdsWork.class);
Page highCardinalityDictionaryPage = new Page(bigintDictionaryBlock, bigintBigDictionaryBlock);
assertGroupByHashWork(highCardinalityDictionaryPage, ImmutableList.of(BIGINT, VARCHAR), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
// Cardinality above Short.MAX_VALUE
Page lowCardinalityHugeDictionaryPage = new Page(bigintSingletonDictionaryBlock, bigintHugeDictionaryBlock);
assertGroupByHashWork(lowCardinalityHugeDictionaryPage, ImmutableList.of(BIGINT, BIGINT), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
}
Aggregations