Skip to content

Commit dcca23c

Browse files
committed
check if column mapping is enabled
1 parent da58838 commit dcca23c

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

crates/core/src/operations/drop_column.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Drop a column from the table
22
3+
use delta_kernel::column_mapping::ColumnMappingMode;
34
use delta_kernel::schema::DataType;
45
use delta_kernel::schema::StructType;
56
use futures::future::BoxFuture;
@@ -9,9 +10,10 @@ use itertools::Itertools;
910
use sqlparser::dialect::GenericDialect;
1011
use sqlparser::parser::Parser;
1112

12-
use super::transaction::{CommitBuilder, CommitProperties};
13+
use super::transaction::TransactionError;
14+
use super::transaction::{CommitBuilder, CommitProperties, PROTOCOL};
1315

14-
use crate::kernel::StructField;
16+
use crate::kernel::{StructField, WriterFeatures};
1517
use crate::logstore::LogStoreRef;
1618
use crate::protocol::DeltaOperation;
1719
use crate::table::state::DeltaTableState;
@@ -72,6 +74,32 @@ impl std::future::IntoFuture for DropColumnBuilder {
7274
let this = self;
7375

7476
Box::pin(async move {
77+
let protocol = this.snapshot.protocol();
78+
79+
// Check if column mapping is enabled
80+
if vec![5, 6].contains(&protocol.min_writer_version)
81+
&& this.snapshot.table_config().column_mapping_mode() == ColumnMappingMode::None
82+
{
83+
return Err(DeltaTableError::Generic(
84+
"Column mapping mode shouldn't be None".to_string(),
85+
));
86+
} else if protocol.min_writer_version == 7
87+
&& !protocol
88+
.writer_features
89+
.as_ref()
90+
.map(|v| v.contains(&crate::kernel::WriterFeatures::ColumnMapping))
91+
.unwrap_or_default()
92+
{
93+
return Err(DeltaTableError::Transaction {
94+
source: TransactionError::WriterFeaturesRequired(WriterFeatures::ColumnMapping),
95+
});
96+
} else if protocol.min_writer_version < 5 {
97+
return Err(DeltaTableError::Generic(format!(
98+
"Min writer >= 5, current version is ({})",
99+
protocol.min_writer_version
100+
)));
101+
};
102+
75103
let dialect = GenericDialect {};
76104
let mut metadata = this.snapshot.metadata().clone();
77105
let fields = match this.fields {
@@ -138,7 +166,9 @@ impl std::future::IntoFuture for DropColumnBuilder {
138166
.collect_vec(),
139167
);
140168

141-
if !not_found.is_empty() && this.raise_if_not_exists {
169+
if (!not_found.is_empty() || table_schema.ne(&new_table_schema))
170+
&& this.raise_if_not_exists
171+
{
142172
return Err(DeltaTableError::Generic(format!(
143173
"Column(s) with name: {:#?} doesn't exist",
144174
&not_found

0 commit comments

Comments
 (0)