1
1
//! Drop a column from the table
2
2
3
+ use delta_kernel:: column_mapping:: ColumnMappingMode ;
3
4
use delta_kernel:: schema:: DataType ;
4
5
use delta_kernel:: schema:: StructType ;
5
6
use futures:: future:: BoxFuture ;
@@ -9,9 +10,10 @@ use itertools::Itertools;
9
10
use sqlparser:: dialect:: GenericDialect ;
10
11
use sqlparser:: parser:: Parser ;
11
12
12
- use super :: transaction:: { CommitBuilder , CommitProperties } ;
13
+ use super :: transaction:: TransactionError ;
14
+ use super :: transaction:: { CommitBuilder , CommitProperties , PROTOCOL } ;
13
15
14
- use crate :: kernel:: StructField ;
16
+ use crate :: kernel:: { StructField , WriterFeatures } ;
15
17
use crate :: logstore:: LogStoreRef ;
16
18
use crate :: protocol:: DeltaOperation ;
17
19
use crate :: table:: state:: DeltaTableState ;
@@ -72,6 +74,32 @@ impl std::future::IntoFuture for DropColumnBuilder {
72
74
let this = self ;
73
75
74
76
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
+
75
103
let dialect = GenericDialect { } ;
76
104
let mut metadata = this. snapshot . metadata ( ) . clone ( ) ;
77
105
let fields = match this. fields {
@@ -138,7 +166,9 @@ impl std::future::IntoFuture for DropColumnBuilder {
138
166
. collect_vec ( ) ,
139
167
) ;
140
168
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
+ {
142
172
return Err ( DeltaTableError :: Generic ( format ! (
143
173
"Column(s) with name: {:#?} doesn't exist" ,
144
174
& not_found
0 commit comments