-
Notifications
You must be signed in to change notification settings - Fork 3.6k
PartitionedOutputOperator RLE blocks support #11289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef30eac
Remove BIGINT type redirection from PrecomputedHashGenerator
lukasz-stec bd55816
Extract inner PositionsAppender impls to top level classes
lukasz-stec 77ec276
Rename SmallintPositionsAppender to ShortPositionsAppender
lukasz-stec e4d60e5
Move most of PartitionedOutputOperator tests to TestPagePartitioner
lukasz-stec cec089f
Replace class isolation with manual dispatch
lukasz-stec d39f99e
Optimize partitionNotNullPositions
lukasz-stec 018bc00
Add RLE support to PagePartitioner
lukasz-stec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
core/trino-main/src/main/java/io/trino/operator/output/BytePositionsAppender.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.operator.output; | ||
|
|
||
| import io.trino.spi.block.Block; | ||
| import io.trino.spi.block.ByteArrayBlock; | ||
| import io.trino.spi.block.RunLengthEncodedBlock; | ||
| import it.unimi.dsi.fastutil.ints.IntArrayList; | ||
| import org.openjdk.jol.info.ClassLayout; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Optional; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static io.airlift.slice.SizeOf.sizeOf; | ||
| import static io.trino.operator.output.PositionsAppenderUtil.calculateBlockResetSize; | ||
| import static io.trino.operator.output.PositionsAppenderUtil.calculateNewArraySize; | ||
| import static java.lang.Math.max; | ||
|
|
||
| public class BytePositionsAppender | ||
| implements PositionsAppender | ||
| { | ||
| private static final int INSTANCE_SIZE = ClassLayout.parseClass(BytePositionsAppender.class).instanceSize(); | ||
| private static final Block NULL_VALUE_BLOCK = new ByteArrayBlock(1, Optional.of(new boolean[] {true}), new byte[1]); | ||
|
|
||
| private boolean initialized; | ||
| private int initialEntryCount; | ||
|
|
||
| private int positionCount; | ||
| private boolean hasNullValue; | ||
| private boolean hasNonNullValue; | ||
|
|
||
| // it is assumed that these arrays are the same length | ||
| private boolean[] valueIsNull = new boolean[0]; | ||
| private byte[] values = new byte[0]; | ||
|
|
||
| private long retainedSizeInBytes; | ||
| private long sizeInBytes; | ||
|
|
||
| public BytePositionsAppender(int expectedEntries) | ||
| { | ||
| this.initialEntryCount = max(expectedEntries, 1); | ||
lukasz-stec marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| updateRetainedSize(); | ||
| } | ||
|
|
||
| @Override | ||
| public void append(IntArrayList positions, Block block) | ||
| { | ||
| if (positions.isEmpty()) { | ||
| return; | ||
| } | ||
| // performance of this method depends on block being always the same, flat type | ||
| checkArgument(block instanceof ByteArrayBlock); | ||
| int[] positionArray = positions.elements(); | ||
| int positionsSize = positions.size(); | ||
| ensureCapacity(positionCount + positionsSize); | ||
|
|
||
| if (block.mayHaveNull()) { | ||
| for (int i = 0; i < positionsSize; i++) { | ||
| int position = positionArray[i]; | ||
| boolean isNull = block.isNull(position); | ||
| int positionIndex = positionCount + i; | ||
| if (isNull) { | ||
| valueIsNull[positionIndex] = true; | ||
| hasNullValue = true; | ||
| } | ||
| else { | ||
| values[positionIndex] = block.getByte(position, 0); | ||
| hasNonNullValue = true; | ||
| } | ||
| } | ||
| positionCount += positionsSize; | ||
| } | ||
| else { | ||
| for (int i = 0; i < positionsSize; i++) { | ||
| int position = positionArray[i]; | ||
| values[positionCount + i] = block.getByte(position, 0); | ||
| } | ||
| positionCount += positionsSize; | ||
| hasNonNullValue = true; | ||
| } | ||
|
|
||
| updateSize(positionsSize); | ||
| } | ||
|
|
||
| @Override | ||
| public void appendRle(RunLengthEncodedBlock block) | ||
| { | ||
| int rlePositionCount = block.getPositionCount(); | ||
| if (rlePositionCount == 0) { | ||
| return; | ||
| } | ||
| int sourcePosition = 0; | ||
| ensureCapacity(positionCount + rlePositionCount); | ||
| if (block.isNull(sourcePosition)) { | ||
| Arrays.fill(valueIsNull, positionCount, positionCount + rlePositionCount, true); | ||
| hasNullValue = true; | ||
| } | ||
| else { | ||
| byte value = block.getByte(sourcePosition, 0); | ||
| Arrays.fill(values, positionCount, positionCount + rlePositionCount, value); | ||
| hasNonNullValue = true; | ||
| } | ||
| positionCount += rlePositionCount; | ||
|
|
||
| updateSize(rlePositionCount); | ||
| } | ||
|
|
||
| @Override | ||
| public Block build() | ||
| { | ||
| if (!hasNonNullValue) { | ||
| return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, positionCount); | ||
| } | ||
| ByteArrayBlock result = new ByteArrayBlock(positionCount, hasNullValue ? Optional.of(valueIsNull) : Optional.empty(), values); | ||
| reset(); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public long getRetainedSizeInBytes() | ||
| { | ||
| return retainedSizeInBytes; | ||
| } | ||
|
|
||
| @Override | ||
| public long getSizeInBytes() | ||
| { | ||
| return sizeInBytes; | ||
| } | ||
|
|
||
| private void reset() | ||
| { | ||
| initialEntryCount = calculateBlockResetSize(positionCount); | ||
| initialized = false; | ||
| valueIsNull = new boolean[0]; | ||
| values = new byte[0]; | ||
| positionCount = 0; | ||
| sizeInBytes = 0; | ||
| hasNonNullValue = false; | ||
| hasNullValue = false; | ||
| updateRetainedSize(); | ||
| } | ||
|
|
||
| private void ensureCapacity(int capacity) | ||
| { | ||
| if (values.length >= capacity) { | ||
| return; | ||
| } | ||
|
|
||
| int newSize; | ||
| if (initialized) { | ||
| newSize = calculateNewArraySize(values.length); | ||
| } | ||
| else { | ||
| newSize = initialEntryCount; | ||
| initialized = true; | ||
| } | ||
| newSize = Math.max(newSize, capacity); | ||
|
|
||
| valueIsNull = Arrays.copyOf(valueIsNull, newSize); | ||
| values = Arrays.copyOf(values, newSize); | ||
| updateRetainedSize(); | ||
| } | ||
|
|
||
| private void updateSize(long positionsSize) | ||
| { | ||
| sizeInBytes += ByteArrayBlock.SIZE_IN_BYTES_PER_POSITION * positionsSize; | ||
| } | ||
|
|
||
| private void updateRetainedSize() | ||
| { | ||
| retainedSizeInBytes = INSTANCE_SIZE + sizeOf(valueIsNull) + sizeOf(values); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.