Skip to content

Commit 437a15c

Browse files
JustinRush80ion-elgreco
authored andcommitted
fix the schema evolution collisions
Signed-off-by: JustinRush80 <[email protected]>
1 parent 48bf089 commit 437a15c

File tree

1 file changed

+13
-9
lines changed
  • crates/core/src/operations/merge

1 file changed

+13
-9
lines changed

crates/core/src/operations/merge/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,16 +1501,19 @@ fn modify_schema(
15011501
let error = arrow::error::ArrowError::SchemaError("Schema evolved fields cannot have generated expressions. Recreate the table to achieve this.".to_string());
15021502
return Err(DeltaTableError::Arrow { source: error });
15031503
}
1504-
1505-
if let Ok(target_field) = target_schema.field_from_column(columns) {
1506-
// for nested data types we need to first merge then see if there a change then replace the pre-existing field
1507-
let new_field = merge_arrow_field(target_field, source_field, true)?;
1508-
if &new_field == target_field {
1509-
continue;
1504+
//Check if the columns in the source schema exist in the target schema
1505+
match target_schema.field_from_column(columns) {
1506+
Ok(target_field) => {
1507+
// This case is when there is an added column in an nested datatype
1508+
let new_field = merge_arrow_field(target_field, source_field, true)?;
1509+
if &new_field != target_field {
1510+
ending_schema.try_merge(&Arc::new(new_field))?;
1511+
}
1512+
}
1513+
Err(_) => {
1514+
// This function is called multiple time with different operations so this handle any collisions
1515+
ending_schema.try_merge(&Arc::new(source_field.to_owned().with_nullable(true)))?;
15101516
}
1511-
ending_schema.try_merge(&Arc::new(new_field))?;
1512-
} else {
1513-
ending_schema.push(source_field.to_owned().with_nullable(true));
15141517
}
15151518
}
15161519
Ok(())
@@ -2338,6 +2341,7 @@ mod tests {
23382341
"| B | 51 | 2021-02-02 | B1 |",
23392342
"| C | 201 | 2023-07-04 | C1 |",
23402343
"| D | 100 | 2021-02-02 | |",
2344+
"| X | 30 | 2023-07-04 | X1 |",
23412345
"+----+-------+------------+-------------+",
23422346
];
23432347
let actual = get_data(&table).await;

0 commit comments

Comments
 (0)