Skip to content

Commit cb70e58

Browse files
fix!: make actions types pub(crate) instead of pub (#405)
We don't want to just have all `action` types pub. This moves everything to `pub(crate)` but turns them `pub` with dev-visibility. Breaking change: actions types are now all private (`Metadata`, `Protocol`, `Add`, etc.)
1 parent fff0052 commit cb70e58

File tree

6 files changed

+81
-50
lines changed

6 files changed

+81
-50
lines changed

acceptance/src/meta.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl TestCaseInfo {
8989
let tvm = TableVersionMetaData {
9090
version: snapshot.version(),
9191
properties: metadata
92-
.configuration
92+
.configuration()
9393
.iter()
9494
.map(|(k, v)| (k.clone(), v.clone()))
9595
.collect(),

ffi/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ pub unsafe extern "C" fn snapshot_table_root(
661661
#[no_mangle]
662662
pub unsafe extern "C" fn get_partition_column_count(snapshot: Handle<SharedSnapshot>) -> usize {
663663
let snapshot = unsafe { snapshot.as_ref() };
664-
snapshot.metadata().partition_columns.len()
664+
snapshot.metadata().partition_columns().len()
665665
}
666666

667667
/// Get an iterator of the list of partition columns for this snapshot.
@@ -673,7 +673,8 @@ pub unsafe extern "C" fn get_partition_columns(
673673
snapshot: Handle<SharedSnapshot>,
674674
) -> Handle<StringSliceIterator> {
675675
let snapshot = unsafe { snapshot.as_ref() };
676-
let iter: Box<StringIter> = Box::new(snapshot.metadata().partition_columns.clone().into_iter());
676+
let iter: Box<StringIter> =
677+
Box::new(snapshot.metadata().partition_columns().clone().into_iter());
677678
iter.into()
678679
}
679680

kernel/src/actions/mod.rs

+60-39
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ pub(crate) fn get_log_commit_info_schema() -> &'static SchemaRef {
8989
}
9090

9191
#[derive(Debug, Clone, PartialEq, Eq, Schema)]
92+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
9293
#[cfg_attr(test, derive(Serialize), serde(rename_all = "camelCase"))]
93-
pub struct Format {
94+
pub(crate) struct Format {
9495
/// Name of the encoding for files in this table
95-
pub provider: String,
96+
pub(crate) provider: String,
9697
/// A map containing configuration options for the format
97-
pub options: HashMap<String, String>,
98+
pub(crate) options: HashMap<String, String>,
9899
}
99100

100101
impl Default for Format {
@@ -108,49 +109,63 @@ impl Default for Format {
108109

109110
#[derive(Debug, Default, Clone, PartialEq, Eq, Schema)]
110111
#[cfg_attr(test, derive(Serialize), serde(rename_all = "camelCase"))]
111-
pub struct Metadata {
112+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
113+
pub(crate) struct Metadata {
112114
/// Unique identifier for this table
113-
pub id: String,
115+
pub(crate) id: String,
114116
/// User-provided identifier for this table
115-
pub name: Option<String>,
117+
pub(crate) name: Option<String>,
116118
/// User-provided description for this table
117-
pub description: Option<String>,
119+
pub(crate) description: Option<String>,
118120
/// Specification of the encoding for the files stored in the table
119-
pub format: Format,
121+
pub(crate) format: Format,
120122
/// Schema of the table
121-
pub schema_string: String,
123+
pub(crate) schema_string: String,
122124
/// Column names by which the data should be partitioned
123-
pub partition_columns: Vec<String>,
125+
pub(crate) partition_columns: Vec<String>,
124126
/// The time when this metadata action is created, in milliseconds since the Unix epoch
125-
pub created_time: Option<i64>,
127+
pub(crate) created_time: Option<i64>,
126128
/// Configuration options for the metadata action. These are parsed into [`TableProperties`].
127-
pub configuration: HashMap<String, String>,
129+
pub(crate) configuration: HashMap<String, String>,
128130
}
129131

130132
impl Metadata {
131-
pub fn try_new_from_data(data: &dyn EngineData) -> DeltaResult<Option<Metadata>> {
133+
pub(crate) fn try_new_from_data(data: &dyn EngineData) -> DeltaResult<Option<Metadata>> {
132134
let mut visitor = MetadataVisitor::default();
133135
visitor.visit_rows_of(data)?;
134136
Ok(visitor.metadata)
135137
}
136138

137-
pub fn parse_schema(&self) -> DeltaResult<StructType> {
139+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
140+
#[allow(dead_code)]
141+
pub(crate) fn configuration(&self) -> &HashMap<String, String> {
142+
&self.configuration
143+
}
144+
145+
pub(crate) fn parse_schema(&self) -> DeltaResult<StructType> {
138146
Ok(serde_json::from_str(&self.schema_string)?)
139147
}
140148

149+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
150+
#[allow(dead_code)]
151+
pub(crate) fn partition_columns(&self) -> &Vec<String> {
152+
&self.partition_columns
153+
}
154+
141155
/// Parse the metadata configuration HashMap<String, String> into a TableProperties struct.
142156
/// Note that parsing is infallible -- any items that fail to parse are simply propagated
143157
/// through to the `TableProperties.unknown_properties` field.
144-
pub fn parse_table_properties(&self) -> TableProperties {
158+
pub(crate) fn parse_table_properties(&self) -> TableProperties {
145159
TableProperties::from(self.configuration.iter())
146160
}
147161
}
148162

149163
#[derive(Default, Debug, Clone, PartialEq, Eq, Schema, Serialize, Deserialize)]
150164
#[serde(rename_all = "camelCase")]
165+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
151166
// TODO move to another module so that we disallow constructing this struct without using the
152167
// try_new function.
153-
pub struct Protocol {
168+
pub(crate) struct Protocol {
154169
/// The minimum version of the Delta read protocol that a client must implement
155170
/// in order to correctly read this table
156171
min_reader_version: i32,
@@ -160,17 +175,17 @@ pub struct Protocol {
160175
/// A collection of features that a client must implement in order to correctly
161176
/// read this table (exist only when minReaderVersion is set to 3)
162177
#[serde(skip_serializing_if = "Option::is_none")]
163-
reader_features: Option<Vec<String>>,
178+
pub(crate) reader_features: Option<Vec<String>>,
164179
/// A collection of features that a client must implement in order to correctly
165180
/// write this table (exist only when minWriterVersion is set to 7)
166181
#[serde(skip_serializing_if = "Option::is_none")]
167-
writer_features: Option<Vec<String>>,
182+
pub(crate) writer_features: Option<Vec<String>>,
168183
}
169184

170185
impl Protocol {
171186
/// Try to create a new Protocol instance from reader/writer versions and table features. This
172187
/// can fail if the protocol is invalid.
173-
pub fn try_new(
188+
pub(crate) fn try_new(
174189
min_reader_version: i32,
175190
min_writer_version: i32,
176191
reader_features: Option<impl IntoIterator<Item = impl Into<String>>>,
@@ -204,48 +219,50 @@ impl Protocol {
204219

205220
/// Create a new Protocol by visiting the EngineData and extracting the first protocol row into
206221
/// a Protocol instance. If no protocol row is found, returns Ok(None).
207-
pub fn try_new_from_data(data: &dyn EngineData) -> DeltaResult<Option<Protocol>> {
222+
pub(crate) fn try_new_from_data(data: &dyn EngineData) -> DeltaResult<Option<Protocol>> {
208223
let mut visitor = ProtocolVisitor::default();
209224
visitor.visit_rows_of(data)?;
210225
Ok(visitor.protocol)
211226
}
212227

213228
/// This protocol's minimum reader version
214-
pub fn min_reader_version(&self) -> i32 {
229+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
230+
pub(crate) fn min_reader_version(&self) -> i32 {
215231
self.min_reader_version
216232
}
217233

218234
/// This protocol's minimum writer version
219-
pub fn min_writer_version(&self) -> i32 {
235+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
236+
pub(crate) fn min_writer_version(&self) -> i32 {
220237
self.min_writer_version
221238
}
222239

223240
/// Get the reader features for the protocol
224-
pub fn reader_features(&self) -> Option<&[String]> {
241+
pub(crate) fn reader_features(&self) -> Option<&[String]> {
225242
self.reader_features.as_deref()
226243
}
227244

228245
/// Get the writer features for the protocol
229-
pub fn writer_features(&self) -> Option<&[String]> {
246+
pub(crate) fn writer_features(&self) -> Option<&[String]> {
230247
self.writer_features.as_deref()
231248
}
232249

233250
/// True if this protocol has the requested reader feature
234-
pub fn has_reader_feature(&self, feature: &ReaderFeatures) -> bool {
251+
pub(crate) fn has_reader_feature(&self, feature: &ReaderFeatures) -> bool {
235252
self.reader_features()
236253
.is_some_and(|features| features.iter().any(|f| f == feature.as_ref()))
237254
}
238255

239256
/// True if this protocol has the requested writer feature
240-
pub fn has_writer_feature(&self, feature: &WriterFeatures) -> bool {
257+
pub(crate) fn has_writer_feature(&self, feature: &WriterFeatures) -> bool {
241258
self.writer_features()
242259
.is_some_and(|features| features.iter().any(|f| f == feature.as_ref()))
243260
}
244261

245262
/// Check if reading a table with this protocol is supported. That is: does the kernel support
246263
/// the specified protocol reader version and all enabled reader features? If yes, returns unit
247264
/// type, otherwise will return an error.
248-
pub fn ensure_read_supported(&self) -> DeltaResult<()> {
265+
pub(crate) fn ensure_read_supported(&self) -> DeltaResult<()> {
249266
match &self.reader_features {
250267
// if min_reader_version = 3 and all reader features are subset of supported => OK
251268
Some(reader_features) if self.min_reader_version == 3 => {
@@ -275,7 +292,7 @@ impl Protocol {
275292

276293
/// Check if writing to a table with this protocol is supported. That is: does the kernel
277294
/// support the specified protocol writer version and all enabled writer features?
278-
pub fn ensure_write_supported(&self) -> DeltaResult<()> {
295+
pub(crate) fn ensure_write_supported(&self) -> DeltaResult<()> {
279296
match &self.writer_features {
280297
Some(writer_features) if self.min_writer_version == 7 => {
281298
// if we're on version 7, make sure we support all the specified features
@@ -369,30 +386,31 @@ pub(crate) struct CommitInfo {
369386

370387
#[derive(Debug, Clone, PartialEq, Eq, Schema)]
371388
#[cfg_attr(test, derive(Serialize, Default), serde(rename_all = "camelCase"))]
372-
pub struct Add {
389+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
390+
pub(crate) struct Add {
373391
/// A relative path to a data file from the root of the table or an absolute path to a file
374392
/// that should be added to the table. The path is a URI as specified by
375393
/// [RFC 2396 URI Generic Syntax], which needs to be decoded to get the data file path.
376394
///
377395
/// [RFC 2396 URI Generic Syntax]: https://www.ietf.org/rfc/rfc2396.txt
378-
pub path: String,
396+
pub(crate) path: String,
379397

380398
/// A map from partition column to value for this logical file. This map can contain null in the
381399
/// values meaning a partition is null. We drop those values from this map, due to the
382400
/// `drop_null_container_values` annotation. This means an engine can assume that if a partition
383401
/// is found in [`Metadata`] `partition_columns`, but not in this map, its value is null.
384402
#[drop_null_container_values]
385-
pub partition_values: HashMap<String, String>,
403+
pub(crate) partition_values: HashMap<String, String>,
386404

387405
/// The size of this data file in bytes
388-
pub size: i64,
406+
pub(crate) size: i64,
389407

390408
/// The time this logical file was created, as milliseconds since the epoch.
391-
pub modification_time: i64,
409+
pub(crate) modification_time: i64,
392410

393411
/// When `false` the logical file must already be present in the table or the records
394412
/// in the added file must be contained in one or more remove actions in the same version.
395-
pub data_change: bool,
413+
pub(crate) data_change: bool,
396414

397415
/// Contains [statistics] (e.g., count, min/max values for columns) about the data in this logical file encoded as a JSON string.
398416
///
@@ -424,7 +442,9 @@ pub struct Add {
424442
}
425443

426444
impl Add {
427-
pub fn dv_unique_id(&self) -> Option<String> {
445+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
446+
#[allow(dead_code)]
447+
pub(crate) fn dv_unique_id(&self) -> Option<String> {
428448
self.deletion_vector.as_ref().map(|dv| dv.unique_id())
429449
}
430450
}
@@ -512,15 +532,16 @@ pub(crate) struct Cdc {
512532
}
513533

514534
#[derive(Debug, Clone, PartialEq, Eq, Schema)]
515-
pub struct SetTransaction {
535+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
536+
pub(crate) struct SetTransaction {
516537
/// A unique identifier for the application performing the transaction.
517-
pub app_id: String,
538+
pub(crate) app_id: String,
518539

519540
/// An application-specific numeric identifier for this transaction.
520-
pub version: i64,
541+
pub(crate) version: i64,
521542

522543
/// The time when this transaction action was created in milliseconds since the Unix epoch.
523-
pub last_updated: Option<i64>,
544+
pub(crate) last_updated: Option<i64>,
524545
}
525546

526547
/// The sidecar action references a sidecar file which provides some of the checkpoint's

kernel/src/actions/set_transaction.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ use crate::{
77
DeltaResult, Engine, EngineData, Expression as Expr, ExpressionRef, RowVisitor as _, SchemaRef,
88
};
99

10-
pub use crate::actions::visitors::SetTransactionMap;
11-
pub struct SetTransactionScanner {
10+
pub(crate) use crate::actions::visitors::SetTransactionMap;
11+
12+
#[allow(dead_code)]
13+
pub(crate) struct SetTransactionScanner {
1214
snapshot: Arc<Snapshot>,
1315
}
1416

17+
#[allow(dead_code)]
1518
impl SetTransactionScanner {
16-
pub fn new(snapshot: Arc<Snapshot>) -> Self {
19+
pub(crate) fn new(snapshot: Arc<Snapshot>) -> Self {
1720
SetTransactionScanner { snapshot }
1821
}
1922

@@ -68,7 +71,7 @@ impl SetTransactionScanner {
6871
}
6972

7073
/// Scan the Delta Log for the latest transaction entry of an application
71-
pub fn application_transaction(
74+
pub(crate) fn application_transaction(
7275
&self,
7376
engine: &dyn Engine,
7477
application_id: &str,
@@ -78,7 +81,10 @@ impl SetTransactionScanner {
7881
}
7982

8083
/// Scan the Delta Log to obtain the latest transaction for all applications
81-
pub fn application_transactions(&self, engine: &dyn Engine) -> DeltaResult<SetTransactionMap> {
84+
pub(crate) fn application_transactions(
85+
&self,
86+
engine: &dyn Engine,
87+
) -> DeltaResult<SetTransactionMap> {
8288
self.scan_application_transactions(engine, None)
8389
}
8490
}

kernel/src/actions/visitors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl RowVisitor for CdcVisitor {
361361
}
362362
}
363363

364-
pub type SetTransactionMap = HashMap<String, SetTransaction>;
364+
pub(crate) type SetTransactionMap = HashMap<String, SetTransaction>;
365365

366366
/// Extract application transaction actions from the log into a map
367367
///

kernel/src/snapshot.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,15 @@ impl Snapshot {
103103
}
104104

105105
/// Table [`Metadata`] at this `Snapshot`s version.
106-
pub fn metadata(&self) -> &Metadata {
106+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
107+
pub(crate) fn metadata(&self) -> &Metadata {
107108
self.table_configuration.metadata()
108109
}
109110

110111
/// Table [`Protocol`] at this `Snapshot`s version.
111-
pub fn protocol(&self) -> &Protocol {
112+
#[allow(dead_code)]
113+
#[cfg_attr(feature = "developer-visibility", visibility::make(pub))]
114+
pub(crate) fn protocol(&self) -> &Protocol {
112115
self.table_configuration.protocol()
113116
}
114117

0 commit comments

Comments
 (0)