Skip to content

Commit

Permalink
fix: disallow new generated columns
Browse files Browse the repository at this point in the history
Signed-off-by: Ion Koutsouris <[email protected]>
  • Loading branch information
ion-elgreco committed Jan 12, 2025
1 parent 173659c commit 5db1970
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 12 additions & 1 deletion crates/core/src/operations/add_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use itertools::Itertools;

use super::transaction::{CommitBuilder, CommitProperties, PROTOCOL};
use super::{CustomExecuteHandler, Operation};
use crate::kernel::StructField;
use crate::kernel::{StructField, StructTypeExt};
use crate::logstore::LogStoreRef;
use crate::operations::cast::merge_schema::merge_delta_struct;
use crate::protocol::DeltaOperation;
Expand Down Expand Up @@ -85,6 +85,17 @@ impl std::future::IntoFuture for AddColumnBuilder {
this.pre_execute(operation_id).await?;

let fields_right = &StructType::new(fields.clone());

if !fields_right
.get_generated_columns()
.unwrap_or_default()
.is_empty()
{
return Err(DeltaTableError::Generic(
"New columns cannot be a generated column".to_string(),
));
}

let table_schema = this.snapshot.schema();
let new_table_schema = merge_delta_struct(table_schema, fields_right)?;

Expand Down
1 change: 0 additions & 1 deletion crates/core/src/operations/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::protocol::{DeltaOperation, SaveMode};
use crate::table::builder::ensure_table_uri;
use crate::table::config::TableProperty;
use crate::{DeltaTable, DeltaTableBuilder};
use delta_kernel::table_features::{ReaderFeatures, WriterFeatures};

#[derive(thiserror::Error, Debug)]
enum CreateError {
Expand Down

0 comments on commit 5db1970

Please sign in to comment.