prepared_statement: fix deserialization of compound partition keys #795
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.
When PartitionKeyDeserializer wants to deserialize i-th column of the partition key, it needs to know the type of that column. It has access to PreparedMetadata of the prepared query the partition key was constructed from, which has a mapping between bind markers and types. Hence, it needs to learn to which bind marker the i-th pk column corresponds to.
The
self.pk_indexes
of typeVec<PartitionKeyIndex>
is supposed to help with that. The PartitionKeyIndex structure looks like this:So, we need to find an entry
pki
withpki.sequence == i
andpki.index
will be the desired bind marker index.Currently, we naively look at the
self.pk_indexes[i]
entry - which is wrong. Thepk_indexes
vec is actually ordered byindex
, so we might accidentally obtain an index of the wrong partition key column this way. Although there was a test that was supposed to check this scenario, it constructedPreparedMetadata
manually and didn't sort thepk_indexes
byindex
field, which resulted in it accidentally passing.In order to fix this, the
PartitionKeyIndex
is now doing a linear lookup in order to find apki
withpki.sequence == i
. This lookup should be fine as partition keys usually have a little number of fields.Fixes: #793
Pre-review checklist
I have provided docstrings for the public items that I want to introduce.I have adjusted the documentation in./docs/source/
.Fixes:
annotations to PR description.