Repository navigation
fix: cast nested columns during schema evolution - #8379
Conversation
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
The nested single-column fix is sound, but the new positional mapper breaks the existing multi-column cast contract: request order can now determine which values are written to which field.
Align source and target projections from the same field-ID order, then cover reversed multi-column casts in both storage versions.
| let columns = batch | ||
| .columns() | ||
| .iter() | ||
| .zip(output_schema.fields()) |
There was a problem hiding this comment.
These columns are paired positionally, but read_columns follows alteration order (Schema::project preserves request order) while new_col_schema.project_by_ids emits dataset schema order. Reversing two casts therefore silently swaps values. On this head, a Legacy/Stable regression using a=[1,2], b=[10,20], and alterations [cast b→Int64, cast a→Int64] produced a=[10,20].
Please derive both projections from the same field-ID order (or align arrays by field identity) and retain a reversed-order regression.
Executed reproducer
#[rstest]
#[tokio::test]
async fn test_cast_columns_reversed_order(
#[values(LanceFileVersion::Legacy, LanceFileVersion::Stable)]
version: LanceFileVersion,
) -> Result<()> {
let schema = Arc::new(ArrowSchema::new(vec![
ArrowField::new("a", DataType::Int32, false),
ArrowField::new("b", DataType::Int32, false),
]));
let batch = RecordBatch::try_new(
schema.clone(),
vec![
Arc::new(Int32Array::from(vec![1, 2])),
Arc::new(Int32Array::from(vec![10, 20])),
],
)?;
let dir = TempStrDir::default();
let mut ds = Dataset::write(
RecordBatchIterator::new(vec![Ok(batch)], schema),
&dir,
Some(WriteParams {
data_storage_version: Some(version),
..Default::default()
}),
).await?;
ds.alter_columns(&[
ColumnAlteration::new("b".into()).cast_to(DataType::Int64),
ColumnAlteration::new("a".into()).cast_to(DataType::Int64),
]).await?;
let data = ds.scan().try_into_batch().await?;
assert_eq!(data["a"].as_ref(), &Int64Array::from(vec![1, 2]));
Ok(())
}Executed with CARGO_TARGET_DIR=/home/agent/tmp/gate-8379-impl-target cargo test -p lance --lib test_cast_columns_reversed_order -- --nocapture. Both storage versions failed: expected a=[1,2], observed a=[10,20].
There was a problem hiding this comment.
Addressed in 25dc290: source paths and target field IDs now share dataset schema order, and the reversed b/a regression passes for Legacy and Stable across two fragments.
There was a problem hiding this comment.
Confirmed on acdd863e: source paths and target IDs remain schema-ordered, and the reversed-order regression passes for Legacy and Stable. This ordering finding is resolved.
There was a problem hiding this comment.
No code change was needed on 921df7e: source paths and target field IDs remain in dataset schema order, and the reversed-order regression still covers Legacy and Stable across multiple fragments.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…er/fix-6926-1 # Conflicts: # rust/lance/src/dataset/schema_evolution.rs
| /// Recasting a nullable nested field still claims when its top-level parent is | ||
| /// required: a stale append omits the new child id, and the reader cannot | ||
| /// synthesize that child under a required parent. A nullable parent can mask | ||
| /// the missing nullable child, so that append remains compatible. |
There was a problem hiding this comment.
nitpick: This first sentence is completely unreadable. Please rewrite for clarity.
There was a problem hiding this comment.
Addressed in 8034834: the test documentation now begins with the direct field-ID consequence and states the required- and nullable-parent outcomes plainly.
| let result = CommitBuilder::new(Arc::new(dataset)).execute(append).await; | ||
| assert_eq!( | ||
| result.is_err(), | ||
| expect_conflict, | ||
| "parent_nullable={parent_nullable}: got {result:?}" | ||
| ); |
There was a problem hiding this comment.
question(blocking): why should this ever fail? Is this a temporary issue? Or unsolvable without a format change?
There was a problem hiding this comment.
Addressed in 8034834: the comment now explains that the conflict prevents unreadable staged rows because transaction rebasing does not apply the cast to them; supporting that case requires smarter rebasing, not a file-format change.
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The clarified regression makes the concurrency contract explicit: a cast assigns a new child field ID, and transaction rebasing does not transform staged append data. Rejecting stale appends under required parents therefore prevents unreadable rows, while nullable parents remain compatible. Allowing the required-parent append would require smarter rebasing, not a file-format change.
Summary
int32toint64casts across multiple fragments and both storage formatsRoot cause
The cast mapper looked up each field by its leaf name in a batch whose projected nested column remained under its parent struct. That lookup panicked, and legacy files also needed their duplicated ancestor field IDs tombstoned when the child was rewritten.
Validation
cargo test -p lance test_cast_nested_column -- --nocapturecargo test -p lance dataset::schema_evolution::test::test_cast_column -- --nocapturecargo fmt --all -- --checkcargo clippy --all --tests --benches -- -D warningsFixes #6926