Skip to content

Commit 01e7cb1

Browse files
refactor!: Snapshot should not expose delta implementation details (delta-io#1339)
Fixes delta-io#648 ## Why this is a breaking change: This PR removes `Snapshot::metadata`, `Snapshot::protocol`, and `Snapshot::column_mapping_mode`. These are now all accessed through `snapshot.table_configuration`
1 parent e1faff7 commit 01e7cb1

8 files changed

Lines changed: 53 additions & 39 deletions

File tree

acceptance/src/meta.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ impl TestCaseInfo {
8383
assert_eq!(snapshot.version(), case.version);
8484

8585
// assert correct metadata is read
86-
let metadata = snapshot.metadata();
87-
let protocol = snapshot.protocol();
86+
let metadata = snapshot.table_configuration().metadata();
87+
let protocol = snapshot.table_configuration().protocol();
8888
let tvm = TableVersionMetaData {
8989
version: snapshot.version(),
9090
properties: metadata

ffi/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,11 @@ pub unsafe extern "C" fn snapshot_table_root(
675675
#[no_mangle]
676676
pub unsafe extern "C" fn get_partition_column_count(snapshot: Handle<SharedSnapshot>) -> usize {
677677
let snapshot = unsafe { snapshot.as_ref() };
678-
snapshot.metadata().partition_columns().len()
678+
snapshot
679+
.table_configuration()
680+
.metadata()
681+
.partition_columns()
682+
.len()
679683
}
680684

681685
/// Get an iterator of the list of partition columns for this snapshot.
@@ -687,8 +691,14 @@ pub unsafe extern "C" fn get_partition_columns(
687691
snapshot: Handle<SharedSnapshot>,
688692
) -> Handle<StringSliceIterator> {
689693
let snapshot = unsafe { snapshot.as_ref() };
690-
let iter: Box<StringIter> =
691-
Box::new(snapshot.metadata().partition_columns().clone().into_iter());
694+
let iter: Box<StringIter> = Box::new(
695+
snapshot
696+
.table_configuration()
697+
.metadata()
698+
.partition_columns()
699+
.clone()
700+
.into_iter(),
701+
);
692702
iter.into()
693703
}
694704

kernel/examples/inspect-table/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn try_main() -> DeltaResult<()> {
191191
println!("Latest table version: {}", snapshot.version());
192192
}
193193
Commands::Metadata => {
194-
println!("{:#?}", snapshot.metadata());
194+
println!("{:#?}", snapshot.table_configuration().metadata());
195195
}
196196
Commands::Schema => {
197197
println!("{:#?}", snapshot.schema());

kernel/src/scan/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,17 @@ impl ScanBuilder {
116116
pub fn build(self) -> DeltaResult<Scan> {
117117
// if no schema is provided, use snapshot's entire schema (e.g. SELECT *)
118118
let logical_schema = self.schema.unwrap_or_else(|| self.snapshot.schema());
119+
let partition_columns = self
120+
.snapshot
121+
.table_configuration()
122+
.metadata()
123+
.partition_columns();
124+
let column_mapping_mode = self.snapshot.table_configuration().column_mapping_mode();
125+
119126
let state_info = StateInfo::try_new(
120127
logical_schema,
121-
self.snapshot.metadata().partition_columns(),
122-
self.snapshot.table_configuration().column_mapping_mode(),
128+
partition_columns,
129+
column_mapping_mode,
123130
self.predicate,
124131
)?;
125132

kernel/src/snapshot.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use std::sync::Arc;
66
use crate::action_reconciliation::calculate_transaction_expiration_timestamp;
77
use crate::actions::domain_metadata::domain_metadata_configuration;
88
use crate::actions::set_transaction::SetTransactionScanner;
9-
use crate::actions::{Metadata, Protocol, INTERNAL_DOMAIN_PREFIX};
9+
use crate::actions::INTERNAL_DOMAIN_PREFIX;
1010
use crate::checkpoint::CheckpointWriter;
1111
use crate::listed_log_files::ListedLogFiles;
1212
use crate::log_segment::LogSegment;
1313
use crate::scan::ScanBuilder;
1414
use crate::schema::SchemaRef;
1515
use crate::table_configuration::TableConfiguration;
16-
use crate::table_features::ColumnMappingMode;
1716
use crate::table_properties::TableProperties;
1817
use crate::transaction::Transaction;
1918
use crate::LogCompactionWriter;
@@ -50,7 +49,7 @@ impl std::fmt::Debug for Snapshot {
5049
f.debug_struct("Snapshot")
5150
.field("path", &self.log_segment.log_root.as_str())
5251
.field("version", &self.version())
53-
.field("metadata", &self.metadata())
52+
.field("metadata", &self.table_configuration().metadata())
5453
.finish()
5554
}
5655
}
@@ -311,19 +310,6 @@ impl Snapshot {
311310
self.table_configuration.schema()
312311
}
313312

314-
/// Table [`Metadata`] at this `Snapshot`s version.
315-
#[internal_api]
316-
pub(crate) fn metadata(&self) -> &Metadata {
317-
self.table_configuration.metadata()
318-
}
319-
320-
/// Table [`Protocol`] at this `Snapshot`s version.
321-
#[allow(dead_code)]
322-
#[internal_api]
323-
pub(crate) fn protocol(&self) -> &Protocol {
324-
self.table_configuration.protocol()
325-
}
326-
327313
/// Get the [`TableProperties`] for this [`Snapshot`].
328314
pub fn table_properties(&self) -> &TableProperties {
329315
self.table_configuration().table_properties()
@@ -335,13 +321,6 @@ impl Snapshot {
335321
&self.table_configuration
336322
}
337323

338-
/// Get the [column mapping
339-
/// mode](https://github.com/delta-io/delta/blob/master/PROTOCOL.md#column-mapping) at this
340-
/// `Snapshot`s version.
341-
pub fn column_mapping_mode(&self) -> ColumnMappingMode {
342-
self.table_configuration.column_mapping_mode()
343-
}
344-
345324
/// Create a [`ScanBuilder`] for an `SnapshotRef`.
346325
pub fn scan_builder(self: Arc<Self>) -> ScanBuilder {
347326
ScanBuilder::new(self)
@@ -408,6 +387,7 @@ mod tests {
408387
use crate::arrow::record_batch::RecordBatch;
409388
use crate::parquet::arrow::ArrowWriter;
410389

390+
use crate::actions::Protocol;
411391
use crate::engine::arrow_data::ArrowEngineData;
412392
use crate::engine::default::executor::tokio::TokioBackgroundExecutor;
413393
use crate::engine::default::filesystem::ObjectStoreStorageHandler;
@@ -432,7 +412,7 @@ mod tests {
432412

433413
let expected =
434414
Protocol::try_new(3, 7, Some(["deletionVectors"]), Some(["deletionVectors"])).unwrap();
435-
assert_eq!(snapshot.protocol(), &expected);
415+
assert_eq!(snapshot.table_configuration().protocol(), &expected);
436416

437417
let schema_string = r#"{"type":"struct","fields":[{"name":"value","type":"integer","nullable":true,"metadata":{}}]}"#;
438418
let expected: SchemaRef = serde_json::from_str(schema_string).unwrap();
@@ -450,7 +430,7 @@ mod tests {
450430

451431
let expected =
452432
Protocol::try_new(3, 7, Some(["deletionVectors"]), Some(["deletionVectors"])).unwrap();
453-
assert_eq!(snapshot.protocol(), &expected);
433+
assert_eq!(snapshot.table_configuration().protocol(), &expected);
454434

455435
let schema_string = r#"{"type":"struct","fields":[{"name":"value","type":"integer","nullable":true,"metadata":{}}]}"#;
456436
let expected: SchemaRef = serde_json::from_str(schema_string).unwrap();

kernel/src/table_changes/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,14 @@ impl TableChanges {
166166
// TODO: link issue
167167
#[cfg(feature = "catalog-managed")]
168168
require!(
169-
!start_snapshot.protocol().is_catalog_managed()
170-
&& !end_snapshot.protocol().is_catalog_managed(),
169+
!start_snapshot
170+
.table_configuration()
171+
.protocol()
172+
.is_catalog_managed()
173+
&& !end_snapshot
174+
.table_configuration()
175+
.protocol()
176+
.is_catalog_managed(),
171177
Error::unsupported("Change data feed is not supported for catalog-managed tables")
172178
);
173179

@@ -236,7 +242,10 @@ impl TableChanges {
236242
}
237243
/// The partition columns that will be read.
238244
pub(crate) fn partition_columns(&self) -> &Vec<String> {
239-
self.end_snapshot.metadata().partition_columns()
245+
self.end_snapshot
246+
.table_configuration()
247+
.metadata()
248+
.partition_columns()
240249
}
241250

242251
/// Create a [`TableChangesScanBuilder`] for an `Arc<TableChanges>`.

kernel/src/table_changes/scan.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,12 @@ impl TableChangesScanBuilder {
159159
} else {
160160
// Add to read schema, store field so we can build a `Column` expression later
161161
// if needed (i.e. if we have partition columns)
162-
let physical_field = logical_field
163-
.make_physical(self.table_changes.end_snapshot.column_mapping_mode());
162+
let physical_field = logical_field.make_physical(
163+
self.table_changes
164+
.end_snapshot
165+
.table_configuration()
166+
.column_mapping_mode(),
167+
);
164168
debug!("\n\n{logical_field:#?}\nAfter mapping: {physical_field:#?}\n\n");
165169
let physical_name = physical_field.name.clone();
166170
read_fields.push(physical_field);

kernel/src/transaction/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,11 @@ impl Transaction {
336336
fn generate_logical_to_physical(&self) -> Expression {
337337
// for now, we just pass through all the columns except partition columns.
338338
// note this is _incorrect_ if table config deems we need partition columns.
339-
let partition_columns = self.read_snapshot.metadata().partition_columns();
339+
let partition_columns = self
340+
.read_snapshot
341+
.table_configuration()
342+
.metadata()
343+
.partition_columns();
340344
let schema = self.read_snapshot.schema();
341345
let fields = schema
342346
.fields()

0 commit comments

Comments
 (0)