-
Notifications
You must be signed in to change notification settings - Fork 24
[PIXELS-1367] Align PixelsBlockLoader with Trino 466 native blocks #178
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
Open
gengdy1545
wants to merge
2
commits into
pixelsdb:master
Choose a base branch
from
gengdy1545:fixbug/blockLoader
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,6 @@ | |
| import io.airlift.slice.Slices; | ||
| import io.pixelsdb.pixels.core.TypeDescription; | ||
| import io.pixelsdb.pixels.core.vector.*; | ||
| import io.pixelsdb.pixels.trino.block.TimeArrayBlock; | ||
| import io.pixelsdb.pixels.trino.block.VarcharArrayBlock; | ||
| import io.pixelsdb.pixels.trino.block.VarcharArrayBlockEncoding; | ||
| import io.trino.spi.block.*; | ||
| import io.trino.spi.type.Type; | ||
|
|
||
|
|
@@ -70,7 +67,26 @@ public Block load() | |
| switch (typeCategory) | ||
| { | ||
| case BYTE: | ||
| ByteColumnVector bytecv = (ByteColumnVector) vector; | ||
| block = new ByteArrayBlock(batchSize, Optional.ofNullable(bytecv.isNull), bytecv.vector); | ||
| break; | ||
| case SHORT: | ||
| IntColumnVector shortcv = (IntColumnVector) vector; | ||
| short[] shortValues = new short[batchSize]; | ||
| for (int i = 0; i < batchSize; ++i) | ||
| { | ||
| if (!shortcv.isNull[i]) | ||
| { | ||
| int value = shortcv.vector[i]; | ||
| if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) | ||
| { | ||
| throw new IllegalArgumentException("SMALLINT value out of range: " + value); | ||
| } | ||
| shortValues[i] = (short) value; | ||
| } | ||
| } | ||
| block = new ShortArrayBlock(batchSize, Optional.ofNullable(shortcv.isNull), shortValues); | ||
| break; | ||
| case INT: | ||
| IntColumnVector icv = (IntColumnVector) vector; | ||
| block = new IntArrayBlock(batchSize, Optional.ofNullable(icv.isNull), icv.vector); | ||
|
|
@@ -109,9 +125,31 @@ public Block load() | |
| case VARBINARY: | ||
| if (vector instanceof BinaryColumnVector scv) | ||
| { | ||
| block = VarcharArrayBlockEncoding.Instance() | ||
| .replacementBlockForWrite(new VarcharArrayBlock(batchSize, scv.vector, scv.start, scv.lens, !scv.noNulls, scv.isNull).getLoadedBlock()) | ||
| .get(); | ||
| int totalLength = 0; | ||
| for (int i = 0; i < batchSize; ++i) | ||
| { | ||
| if (!scv.noNulls && scv.isNull[i]) | ||
| { | ||
| continue; | ||
| } | ||
| totalLength += scv.lens[i]; | ||
| } | ||
| byte[] content = new byte[totalLength]; | ||
| int[] offsets = new int[batchSize + 1]; | ||
| int curOffset = 0; | ||
| for (int i = 0; i < batchSize; ++i) | ||
| { | ||
| offsets[i] = curOffset; | ||
| if (!scv.noNulls && scv.isNull[i]) | ||
| { | ||
| continue; | ||
| } | ||
| int len = scv.lens[i]; | ||
| System.arraycopy(scv.vector[i], scv.start[i], content, curOffset, len); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional memory copy is inefficient. |
||
| curOffset += len; | ||
| } | ||
| offsets[batchSize] = curOffset; | ||
| block = new VariableWidthBlock(batchSize, Slices.wrappedBuffer(content), offsets, Optional.of(scv.isNull)); | ||
| } else | ||
| { | ||
| DictionaryColumnVector dscv = (DictionaryColumnVector) vector; | ||
|
|
@@ -146,12 +184,12 @@ public Block load() | |
| case TIME: | ||
| // PIXELS-94: add time type. | ||
| TimeColumnVector tcv = (TimeColumnVector) vector; | ||
| /** | ||
| * In Presto, LongArrayBlock is used for time type. However, in Pixels, | ||
| * Time value is stored as int, so here we use TimeArrayBlock, which | ||
| * accepts int values but provides getLong method same as LongArrayBlock. | ||
| */ | ||
| block = new TimeArrayBlock(batchSize, tcv.times, !tcv.noNulls, tcv.isNull); | ||
| long[] timeValues = new long[batchSize]; | ||
| for (int i = 0; i < batchSize; ++i) | ||
| { | ||
| timeValues[i] = (long) tcv.times[i] * 1_000_000_000L; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More memory read is inefficient. |
||
| } | ||
| block = new LongArrayBlock(batchSize, Optional.ofNullable(tcv.isNull), timeValues); | ||
| break; | ||
| case TIMESTAMP: | ||
| TimestampColumnVector tscv = (TimestampColumnVector) vector; | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More memory allocation leads to higher GC pressure.