Skip to content
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

test(stream): add unit test for normalizing unmatched updates + fix typo #20366

Merged
merged 1 commit into from
Feb 4, 2025
Merged
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
113 changes: 112 additions & 1 deletion src/stream/src/executor/backfill/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ fn mark_chunk_inner(
);
}
let (columns, _) = data.into_parts();
StreamChunk::with_visibility(ops, columns, new_visibility.finish())
StreamChunk::with_visibility(new_ops, columns, new_visibility.finish())
}

/// We will rewrite unmatched U-/U+ into +/- ops.
Expand Down Expand Up @@ -856,3 +856,114 @@ pub fn create_builder(
};
DataChunkBuilder::new(data_types, batch_size)
}

#[cfg(test)]
mod tests {
use std::sync::Arc;

use super::*;

#[test]
fn test_normalizing_unmatched_updates() {
let ops = vec![
Op::UpdateDelete,
Op::UpdateInsert,
Op::UpdateDelete,
Op::UpdateInsert,
];
let ops: Arc<[Op]> = ops.into();

{
let mut new_ops: Cow<'_, [Op]> = Cow::Borrowed(ops.as_ref());
let mut unmatched_update_delete = true;
let mut visible_update_delete = true;
let current_visibility = true;
normalize_unmatched_updates(
&mut new_ops,
&mut unmatched_update_delete,
&mut visible_update_delete,
current_visibility,
1,
&Op::UpdateInsert,
);
assert_eq!(
&new_ops[..],
vec![
Op::UpdateDelete,
Op::UpdateInsert,
Op::UpdateDelete,
Op::UpdateInsert
]
);
}
{
let mut new_ops: Cow<'_, [Op]> = Cow::Borrowed(ops.as_ref());
let mut unmatched_update_delete = true;
let mut visible_update_delete = false;
let current_visibility = false;
normalize_unmatched_updates(
&mut new_ops,
&mut unmatched_update_delete,
&mut visible_update_delete,
current_visibility,
1,
&Op::UpdateInsert,
);
assert_eq!(
&new_ops[..],
vec![
Op::UpdateDelete,
Op::UpdateInsert,
Op::UpdateDelete,
Op::UpdateInsert
]
);
}
{
let mut new_ops: Cow<'_, [Op]> = Cow::Borrowed(ops.as_ref());
let mut unmatched_update_delete = true;
let mut visible_update_delete = true;
let current_visibility = false;
normalize_unmatched_updates(
&mut new_ops,
&mut unmatched_update_delete,
&mut visible_update_delete,
current_visibility,
1,
&Op::UpdateInsert,
);
assert_eq!(
&new_ops[..],
vec![
Op::Delete,
Op::UpdateInsert,
Op::UpdateDelete,
Op::UpdateInsert
]
);
}
{
let mut new_ops: Cow<'_, [Op]> = Cow::Borrowed(ops.as_ref());
let mut unmatched_update_delete = true;
let mut visible_update_delete = false;
let current_visibility = true;
normalize_unmatched_updates(
&mut new_ops,
&mut unmatched_update_delete,
&mut visible_update_delete,
current_visibility,
1,
&Op::UpdateInsert,
);
assert_eq!(
&new_ops[..],
vec![
Op::UpdateDelete,
Op::Insert,
Op::UpdateDelete,
Op::UpdateInsert
]
);
}
}
}
Loading