Skip to content

Support for 0 length dictionary copyRegion#20065

Merged
sopel39 merged 1 commit intotrinodb:masterfrom
starburstdata:ks/fix_copy
Dec 9, 2023
Merged

Support for 0 length dictionary copyRegion#20065
sopel39 merged 1 commit intotrinodb:masterfrom
starburstdata:ks/fix_copy

Conversation

@sopel39
Copy link
Copy Markdown
Member

@sopel39 sopel39 commented Dec 8, 2023

checkValidRegion already validates that
region is correct. Therefore copyRegion
for postiion 42 and length 0 shoudn't
fail for dictionary with 42 positions.

@pettyjamesm
Copy link
Copy Markdown
Member

I'm not sure that I follow the logic here, to be honest. checkValidPosition would reject accessing position 42 for a DictionaryBlock with 42 positions. The logic in checkValidRegion would allow it, but I think that's only because the special case where length == 0 was considered when it was written. Is there a reason to allow an out-of-bounds read as long as it's zero length? If so, why not allow all zero length reads regardless of the position?

@sopel39
Copy link
Copy Markdown
Member Author

sopel39 commented Dec 8, 2023

@pettyjamesm the error I saw was

java.lang.IllegalArgumentException: Invalid position 27 in block with 27 positions
    at io.trino.spi.block.BlockUtil.checkValidPosition(BlockUtil.java:70)
    at io.trino.spi.block.DictionaryBlock.getId(DictionaryBlock.java:602)
    at io.trino.spi.block.DictionaryBlock.copyRegion(DictionaryBlock.java:427)
    at io.trino.spi.block.RowBlock.copyRegion(RowBlock.java:348)
    at io.trino.spi.block.RowBlock.copyRegion(RowBlock.java:36)
    at io.trino.spi.block.ArrayBlock.copyRegion(ArrayBlock.java:353)
    at io.trino.spi.block.ArrayBlock.copyRegion(ArrayBlock.java:39)
    at io.trino.spi.block.DictionaryBlock.copyRegion(DictionaryBlock.java:427)
    at io.trino.spi.block.RowBlock.copyRegion(RowBlock.java:348)
    at io.trino.spi.block.RowBlock.copyRegion(RowBlock.java:36)
    at io.trino.spi.block.DictionaryBlock.createInternal(DictionaryBlock.java:71)
    at io.trino.spi.block.Block.getPositions(Block.java:187)
    at io.trino.spi.block.LazyBlock$PositionLazyBlockLoader.load(LazyBlock.java:298)

I guess it might be related to ArrayBlock maybe somehow

@pettyjamesm
Copy link
Copy Markdown
Member

I might suspect RowBlock (or some RowBlock/ArrayBlock interaction) because it recently changed from being null suppressed to not.

@sopel39
Copy link
Copy Markdown
Member Author

sopel39 commented Dec 8, 2023

@pettyjamesm which pr removed null suppression?

@pettyjamesm
Copy link
Copy Markdown
Member

@pettyjamesm which pr removed null suppression?

#19479

@sopel39
Copy link
Copy Markdown
Member Author

sopel39 commented Dec 8, 2023

@pettyjamesm do you think that PR could be related somehow to null/empty arrays which would trigger the issue here?

@pettyjamesm
Copy link
Copy Markdown
Member

@pettyjamesm do you think that PR could be related somehow to null/empty arrays which would trigger the issue here?

It seems like a plausible theory for how we might suddenly start seeing off by one, out of bounds position references.

@sopel39
Copy link
Copy Markdown
Member Author

sopel39 commented Dec 8, 2023

@pettyjamesm but would that be a bug or just a side effect?

@pettyjamesm
Copy link
Copy Markdown
Member

@pettyjamesm but would that be a bug or just a side effect?

As a starting assumption, I would consider referencing an out of bounds position (even with a zero length) to probably be a bug, but maybe a careful inspection of the related logic would show that zero length regions are actually a valid special special case and should be allowed.

@sopel39
Copy link
Copy Markdown
Member Author

sopel39 commented Dec 8, 2023

@dain wdyt?

@sopel39
Copy link
Copy Markdown
Member Author

sopel39 commented Dec 8, 2023

@pettyjamesm here is 0 length region doesn't exceed block boundary technically, but I'm not sure why it happens in the first place (maybe it worked like that always)

@sopel39
Copy link
Copy Markdown
Member Author

sopel39 commented Dec 8, 2023

Anyway this is a good change since it just makes dictionary support current contract

@sopel39 sopel39 requested a review from pettyjamesm December 8, 2023 22:30
Copy link
Copy Markdown
Member

@dain dain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a bug. Good fix.

@pettyjamesm
Copy link
Copy Markdown
Member

Definitely a bug. Good fix.

And definitely not a bug in RowBlock’s implementation? Asking for an out of bounds range seems fishy, but if it’s valid behavior then maybe we should allow any zero length range at any offset?

@electrum
Copy link
Copy Markdown
Member

electrum commented Dec 9, 2023

We don't need to wrap the description at 40 characters. Also, typo "postiion"

checkValidRegion already validates that region is correct.
Therefore copyRegion for position 42 and length 0 shoudn't
fail for dictionary with 42 positions.
@sopel39 sopel39 merged commit 89b43de into trinodb:master Dec 9, 2023
@sopel39 sopel39 deleted the ks/fix_copy branch December 9, 2023 07:45
@github-actions github-actions bot added this to the 435 milestone Dec 9, 2023
@sopel39 sopel39 mentioned this pull request Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants