Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions native/core/src/execution/delta_dv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ pub fn deserialize_dv_bitmap(data: &[u8]) -> Result<RoaringTreemap, ExecutionErr
)));
}
let mut pos = 4usize;
let mut treemap = RoaringTreemap::new();
for key in 0..count as u64 {
let mut bitmaps = Vec::new();
for key in 0..count as u32 {
if rest.len() < pos + 4 {
return Err(GeneralError(
"Native deletion vector bitmap truncated".to_string(),
Expand All @@ -148,11 +148,11 @@ pub fn deserialize_dv_bitmap(data: &[u8]) -> Result<RoaringTreemap, ExecutionErr
GeneralError(format!("Invalid deletion vector sub-bitmap: {e}"))
})?;
pos += size as usize;
for value in bitmap {
treemap.insert((key << 32) | value as u64);
if !bitmap.is_empty() {
bitmaps.push((key, bitmap));
}
}
Ok(treemap)
Ok(RoaringTreemap::from_bitmaps(bitmaps))
}
other => Err(GeneralError(format!(
"Unexpected RoaringBitmapArray magic number {other}"
Expand Down Expand Up @@ -1120,10 +1120,50 @@ mod tests {

#[test]
fn native_format_decodes() {
let values = [0u64, 2, 3, 100, (1u64 << 32) + 7];
let values = [0u64, 2, 3, 100, (2u64 << 32) + 7];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth making the intent visible here, since this value is what guards the empty-partition skip. Either a short comment ("key 1 is an empty partition, key 2 must keep its index") or an assertion on decoded.bitmaps() yielding keys [0, 2].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the assertion as suggested: native_format_decodes now checks decoded.bitmaps() keys are [0, 2] and names the empty partition in a comment, so the skip is asserted where it is guarded. Pushed as 263ad46c8.

let decoded = deserialize_dv_bitmap(&native_bytes(&values)).unwrap();
let expected: RoaringTreemap = values.into_iter().collect();
assert_eq!(decoded, expected);
// `native_bytes` emits an entry for every key up to the maximum, so key 1 is an empty
// partition. The decoder must omit it without shifting key 2's partition index.
let keys: Vec<u32> = decoded.bitmaps().map(|(key, _)| key).collect();
assert_eq!(keys, vec![0, 2]);
}

#[test]
fn native_decode_preserves_dense_bitmap_compression() {
let mut bitmap = RoaringBitmap::new();
bitmap.insert_range(0..1_000_000);
let compressed_size = bitmap.serialized_size();
let mut bitmap_bytes = Vec::new();
bitmap.serialize_into(&mut bitmap_bytes).unwrap();

let mut data = NATIVE_MAGIC.to_le_bytes().to_vec();
data.extend(1i32.to_le_bytes());
data.extend((bitmap_bytes.len() as i32).to_le_bytes());
data.extend(bitmap_bytes);

let decoded = deserialize_dv_bitmap(&data).unwrap();
let (_, decoded_bitmap) = decoded.bitmaps().next().unwrap();
assert_eq!(decoded_bitmap.serialized_size(), compressed_size);
Comment on lines +1134 to +1148

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This pins the container type, which is the point of the PR. Could it also push the decoded treemap through build_access_plan? Something like full_file_access_plan(&[600_000, 600_000], &decoded) with group 0 expected as Skip and group 1 as skip 400_000 then select 200_000, plus assert_eq!(decoded.len(), 1_000_000). Nothing in this file currently drives a run container through the plan builder, and after this change dense native DVs will.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Extended the test with the plan-builder push: full_file_access_plan(&[600_000, 600_000], &decoded) asserts group 0 is Skip, group 1 is skip 400_000 then select 200_000, and decoded.len() == 1_000_000. That is the first case in the file that drives a run container through build_access_plan. Pushed as 263ad46c8.


// Dense native DVs now reach `build_access_plan`, so the same container must survive
// plan construction. Group 0 (rows 0..600_000) is fully deleted and must be skipped;
// group 1 (rows 600_000..1_200_000) has its first 400_000 rows deleted, leaving a
// trailing run of 200_000 live rows to select.
assert_eq!(decoded.len(), 1_000_000);
let plan = full_file_access_plan(&[600_000, 600_000], &decoded).unwrap();
assert_eq!(&plan.inner()[0], &RowGroupAccess::Skip);
match &plan.inner()[1] {
RowGroupAccess::Selection(sel) => {
let selectors: Vec<RowSelector> = sel.clone().into();
assert_eq!(
selectors,
vec![RowSelector::skip(400_000), RowSelector::select(200_000)]
);
}
other => panic!("expected selection, got {other:?}"),
}
}

#[test]
Expand Down