Skip to content

Commit

Permalink
raw_batch: Fix RawBatchValuesIteratorAdapter length
Browse files Browse the repository at this point in the history
The length of this iterator should be equal to the length of its internal
`BatchValuesIter`. In other words, the amount of serialization contexts should
not affect this length. Otherwise, the caller is not able to detect
a situation when value count is different than statement count.
  • Loading branch information
Lorak-mmk committed Dec 6, 2024
1 parent 4b6ad84 commit f40c17e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scylla-cql/src/types/serialize/raw_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,26 @@ where
{
#[inline]
fn serialize_next(&mut self, writer: &mut RowWriter) -> Option<Result<(), SerializationError>> {
let ctx = self.contexts.next()?;
// We do `unwrap_or` because we want the iterator length to be the same
// as the amount of values. Limiting to length of the amount of
// statements (contexts) causes the caller to not be able to correctly
// detect that amount of statements and values is different.
let ctx = self
.contexts
.next()
.unwrap_or(RowSerializationContext::empty());
self.batch_values_iterator.serialize_next(&ctx, writer)
}

fn is_empty_next(&mut self) -> Option<bool> {
self.contexts.next()?;
let _ = self.contexts.next();
let ret = self.batch_values_iterator.is_empty_next()?;
Some(ret)
}

#[inline]
fn skip_next(&mut self) -> Option<()> {
self.contexts.next()?;
let _ = self.contexts.next();
self.batch_values_iterator.skip_next()?;
Some(())
}
Expand Down

0 comments on commit f40c17e

Please sign in to comment.