Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5474769

Browse files
committedJan 17, 2025
addressed more pr comments
1 parent a12e7ed commit 5474769

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed
 

‎kernel/src/table_changes/log_replay.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::schema::{ArrayType, ColumnNamesAndTypes, DataType, MapType, SchemaRef
1919
use crate::table_changes::scan_file::{cdf_scan_row_expression, cdf_scan_row_schema};
2020
use crate::table_configuration::TableConfiguration;
2121
use crate::utils::require;
22-
use crate::{DeltaResult, Engine, EngineData, Error, ExpressionRef, RowVisitor};
22+
use crate::{table, DeltaResult, Engine, EngineData, Error, ExpressionRef, RowVisitor};
2323

2424
use itertools::Itertools;
2525

@@ -181,30 +181,31 @@ fn process_cdf_commit(
181181
protocol: None,
182182
metadata: None,
183183
};
184-
visitor.visit_rows_of(actions.as_ref())?;
185184

186-
//table_configuration.with_protocol(visitor.protocol)?;
187-
//if let Some(metadata) = visitor.metadata {
188-
// table_configuration.with_metadata(metadata)?;
189-
// // Currently, schema compatibility is defined as having equal schema types. In the
190-
// // future, more permisive schema evolution will be supported.
191-
// // See: https://github.com/delta-io/delta-kernel-rs/issues/523
192-
// require!(
193-
// table_schema.as_ref() == table_configuration.schema(),
194-
// Error::change_data_feed_incompatible_schema(
195-
// table_schema,
196-
// table_configuration.schema()
197-
// )
198-
// );
199-
//}
200-
if !table_configuration.is_cdf_read_supported() {
201-
return Err(Error::change_data_feed_unsupported(commit_file.version));
185+
visitor.visit_rows_of(actions.as_ref())?;
186+
let has_metadata = visitor.metadata.is_some();
187+
match (visitor.protocol, visitor.metadata) {
188+
(None, None) => {}
189+
(p, m) => {
190+
let p = p.unwrap_or_else(|| table_configuration.protocol().clone());
191+
let m = m.unwrap_or_else(|| table_configuration.metadata().clone());
192+
*table_configuration = TableConfiguration::try_new(m, p)?;
193+
if !table_configuration.is_cdf_read_supported() {
194+
return Err(Error::change_data_feed_unsupported(commit_file.version));
195+
}
196+
}
197+
}
198+
if has_metadata {
199+
require!(
200+
table_schema.as_ref() == table_configuration.schema(),
201+
Error::change_data_feed_incompatible_schema(
202+
table_schema,
203+
table_configuration.schema()
204+
)
205+
);
202206
}
203207
}
204208

205-
table_configuration
206-
.can_read_cdf()
207-
.map_err(|_| Error::change_data_feed_unsupported(commit_file.version))?;
208209
// We resolve the remove deletion vector map after visiting the entire commit.
209210
if has_cdc_action {
210211
remove_dvs.clear();

‎kernel/src/table_changes/log_replay/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn table_config() -> TableConfiguration {
4949
Some([WriterFeatures::ColumnMapping]),
5050
)
5151
.unwrap();
52-
TableConfiguration::new(metadata, protocol).unwrap()
52+
TableConfiguration::try_new(metadata, protocol).unwrap()
5353
}
5454

5555
fn get_segment(

‎kernel/src/table_changes/scan_file.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ mod tests {
251251
use crate::schema::{DataType, StructField, StructType};
252252
use crate::table_changes::log_replay::table_changes_action_iter;
253253
use crate::table_configuration::TableConfiguration;
254-
use crate::table_features::ReaderFeatures;
254+
use crate::table_features::{ReaderFeatures, WriterFeatures};
255255
use crate::utils::test_utils::{Action, LocalMockTable};
256256
use crate::Engine;
257257

@@ -357,11 +357,11 @@ mod tests {
357357
let protocol = Protocol::try_new(
358358
3,
359359
7,
360-
Some([ReaderFeatures::DeletionVectors]),
361-
Some([ReaderFeatures::ColumnMapping]),
360+
Some::<Vec<String>>(vec![]),
361+
Some::<Vec<String>>(vec![]),
362362
)
363363
.unwrap();
364-
let table_config = TableConfiguration::new(metadata, protocol).unwrap();
364+
let table_config = TableConfiguration::try_new(metadata, protocol).unwrap();
365365

366366
let scan_data = table_changes_action_iter(
367367
Arc::new(engine),

0 commit comments

Comments
 (0)