-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Avoid direct usage of DictionaryBlock constructor #17842
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import io.trino.spi.block.Block; | ||
| import io.trino.spi.block.BlockBuilder; | ||
| import io.trino.spi.block.DictionaryBlock; | ||
| import io.trino.spi.block.LongArrayBlock; | ||
| import io.trino.spi.type.Type; | ||
| import org.testng.annotations.Test; | ||
|
|
||
|
|
@@ -100,7 +101,7 @@ public void testDifferentPositions() | |
| JoinProbe probe = joinProbeFactory.createJoinProbe(page); | ||
| Page output = lookupJoinPageBuilder.build(probe); | ||
| assertEquals(output.getChannelCount(), 2); | ||
| assertTrue(output.getBlock(0) instanceof DictionaryBlock); | ||
|
Member
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. why type changed here? |
||
| assertTrue(output.getBlock(0) instanceof LongArrayBlock); | ||
|
Member
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. do we need this assert? |
||
| assertEquals(output.getPositionCount(), 0); | ||
| lookupJoinPageBuilder.reset(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,24 +54,29 @@ public class DictionaryBlock | |
|
|
||
| public static Block create(int positionCount, Block dictionary, int[] ids) | ||
| { | ||
| return createInternal(positionCount, dictionary, ids, randomDictionaryId()); | ||
| return create(0, positionCount, dictionary, ids); | ||
| } | ||
|
|
||
| public static Block create(int idsOffset, int positionCount, Block dictionary, int[] ids) | ||
| { | ||
| return createInternal(idsOffset, positionCount, dictionary, ids, randomDictionaryId()); | ||
| } | ||
|
|
||
| /** | ||
| * This should not only be used when creating a projection of another dictionary block. | ||
| */ | ||
| public static Block createProjectedDictionaryBlock(int positionCount, Block dictionary, int[] ids, DictionaryId dictionarySourceId) | ||
| { | ||
| return createInternal(positionCount, dictionary, ids, dictionarySourceId); | ||
| return createInternal(0, positionCount, dictionary, ids, dictionarySourceId); | ||
| } | ||
|
|
||
| private static Block createInternal(int positionCount, Block dictionary, int[] ids, DictionaryId dictionarySourceId) | ||
| private static Block createInternal(int idsOffset, int positionCount, Block dictionary, int[] ids, DictionaryId dictionarySourceId) | ||
| { | ||
| if (positionCount == 0) { | ||
| return dictionary.copyRegion(0, 0); | ||
| } | ||
| if (positionCount == 1) { | ||
| return dictionary.getRegion(ids[0], 1); | ||
| return dictionary.getRegion(ids[idsOffset], 1); | ||
| } | ||
|
|
||
| // if dictionary is an RLE then this can just be a new RLE | ||
|
|
@@ -83,18 +88,14 @@ private static Block createInternal(int positionCount, Block dictionary, int[] i | |
| if (dictionary instanceof DictionaryBlock dictionaryBlock) { | ||
| int[] newIds = new int[positionCount]; | ||
| for (int position = 0; position < positionCount; position++) { | ||
| newIds[position] = dictionaryBlock.getId(ids[position]); | ||
| newIds[position] = dictionaryBlock.getId(ids[idsOffset + position]); | ||
| } | ||
| dictionary = dictionaryBlock.getDictionary(); | ||
| dictionarySourceId = randomDictionaryId(); | ||
| ids = newIds; | ||
| idsOffset = 0; | ||
| } | ||
| return new DictionaryBlock(0, positionCount, dictionary, ids, false, false, dictionarySourceId); | ||
| } | ||
|
|
||
| DictionaryBlock(int idsOffset, int positionCount, Block dictionary, int[] ids) | ||
| { | ||
| this(idsOffset, positionCount, dictionary, ids, false, false, randomDictionaryId()); | ||
| return new DictionaryBlock(idsOffset, positionCount, dictionary, ids, false, false, dictionarySourceId); | ||
| } | ||
|
|
||
| private DictionaryBlock(int idsOffset, int positionCount, Block dictionary, int[] ids, boolean dictionaryIsCompacted, boolean isSequentialIds, DictionaryId dictionarySourceId) | ||
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,8 @@ | |
| public class MergeFileWriter | ||
| implements FileWriter | ||
| { | ||
| private static final Page EMPTY_PAGE = new Page(0); | ||
|
|
||
| // The bucketPath looks like this: /root/dir/delta_nnnnnnn_mmmmmmm_ssss/bucket_bbbbb(_aaaa)? | ||
| private static final Pattern BUCKET_PATH_MATCHER = Pattern.compile("(?s)(?<rootDir>.*)/(?<dirStart>delta_\\d+_\\d+)_(?<statementId>\\d+)/(?<filenameBase>bucket_(?<bucketNumber>\\d+))(?<attemptId>_\\d+)?$"); | ||
|
|
||
|
|
@@ -228,8 +230,11 @@ public PartitionUpdateAndMergeResults getPartitionUpdateAndMergeResults(Partitio | |
| private Page buildDeletePage(Block rowIds, long writeId) | ||
| { | ||
| ColumnarRow columnarRow = toColumnarRow(rowIds); | ||
| checkArgument(!columnarRow.mayHaveNull(), "The rowIdsRowBlock may not have null rows"); | ||
| int positionCount = rowIds.getPositionCount(); | ||
| if (positionCount == 0) { | ||
|
Member
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. move before |
||
| return EMPTY_PAGE; | ||
| } | ||
| checkArgument(!columnarRow.mayHaveNull(), "The rowIdsRowBlock may not have null rows"); | ||
|
Member
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. undelated change? |
||
| // We've verified that the rowIds block has no null rows, so it's okay to get the field blocks | ||
| Block[] blockArray = { | ||
| RunLengthEncodedBlock.create(DELETE_OPERATION_BLOCK, positionCount), | ||
|
|
||
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.
assertBlock?