Skip to content

Commit 97ede33

Browse files
authored
Merge branch 'main' into release-gil
2 parents ddcda30 + 507c3a3 commit 97ede33

File tree

12 files changed

+686
-47
lines changed

12 files changed

+686
-47
lines changed

crates/core/src/kernel/models/actions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ impl From<&str> for WriterFeatures {
284284
fn from(value: &str) -> Self {
285285
match value {
286286
"appendOnly" | "delta.appendOnly" => WriterFeatures::AppendOnly,
287-
"invariants" | "delta.invariants" => WriterFeatures::Invariants,
288-
"checkConstraints" | "delta.checkConstraints" => WriterFeatures::CheckConstraints,
287+
"invariants" => WriterFeatures::Invariants,
288+
"checkConstraints" => WriterFeatures::CheckConstraints,
289289
"changeDataFeed" | "delta.enableChangeDataFeed" => WriterFeatures::ChangeDataFeed,
290290
"generatedColumns" => WriterFeatures::GeneratedColumns,
291291
"columnMapping" => WriterFeatures::ColumnMapping,

crates/core/src/operations/create.rs

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Command for creating a new delta table
22
// https://github.com/delta-io/delta/blob/master/core/src/main/scala/org/apache/spark/sql/delta/commands/CreateDeltaTableCommand.scala
33

4-
use std::collections::{HashMap, HashSet};
4+
use std::collections::HashMap;
55
use std::sync::Arc;
66

77
use futures::future::BoxFuture;
8+
use maplit::hashset;
89
use serde_json::Value;
910

1011
use super::transaction::{CommitBuilder, TableReference, PROTOCOL};
@@ -13,6 +14,9 @@ use crate::kernel::{
1314
Action, DataType, Metadata, Protocol, ReaderFeatures, StructField, StructType, WriterFeatures,
1415
};
1516
use crate::logstore::{LogStore, LogStoreRef};
17+
use crate::operations::set_tbl_properties::{
18+
apply_properties_to_protocol, convert_properties_to_features,
19+
};
1620
use crate::protocol::{DeltaOperation, SaveMode};
1721
use crate::table::builder::ensure_table_uri;
1822
use crate::table::config::DeltaConfigKey;
@@ -237,41 +241,28 @@ impl CreateBuilder {
237241
)
238242
};
239243

244+
let configuration = self.configuration;
240245
let contains_timestampntz = PROTOCOL.contains_timestampntz(&self.columns);
246+
241247
// TODO configure more permissive versions based on configuration. Also how should this ideally be handled?
242248
// We set the lowest protocol we can, and if subsequent writes use newer features we update metadata?
243249

244-
let (min_reader_version, min_writer_version, writer_features, reader_features) =
245-
if contains_timestampntz {
246-
let mut converted_writer_features = self
247-
.configuration
248-
.keys()
249-
.map(|key| key.clone().into())
250-
.filter(|v| !matches!(v, WriterFeatures::Other(_)))
251-
.collect::<HashSet<WriterFeatures>>();
252-
253-
let mut converted_reader_features = self
254-
.configuration
255-
.keys()
256-
.map(|key| key.clone().into())
257-
.filter(|v| !matches!(v, ReaderFeatures::Other(_)))
258-
.collect::<HashSet<ReaderFeatures>>();
259-
converted_writer_features.insert(WriterFeatures::TimestampWithoutTimezone);
260-
converted_reader_features.insert(ReaderFeatures::TimestampWithoutTimezone);
261-
(
262-
3,
263-
7,
264-
Some(converted_writer_features),
265-
Some(converted_reader_features),
266-
)
267-
} else {
268-
(
269-
PROTOCOL.default_reader_version(),
270-
PROTOCOL.default_writer_version(),
271-
None,
272-
None,
273-
)
274-
};
250+
let current_protocol = if contains_timestampntz {
251+
Protocol {
252+
min_reader_version: 3,
253+
min_writer_version: 7,
254+
writer_features: Some(hashset! {WriterFeatures::TimestampWithoutTimezone}),
255+
reader_features: Some(hashset! {ReaderFeatures::TimestampWithoutTimezone}),
256+
}
257+
} else {
258+
Protocol {
259+
min_reader_version: PROTOCOL.default_reader_version(),
260+
min_writer_version: PROTOCOL.default_writer_version(),
261+
reader_features: None,
262+
writer_features: None,
263+
}
264+
};
265+
275266
let protocol = self
276267
.actions
277268
.iter()
@@ -280,17 +271,23 @@ impl CreateBuilder {
280271
Action::Protocol(p) => p.clone(),
281272
_ => unreachable!(),
282273
})
283-
.unwrap_or_else(|| Protocol {
284-
min_reader_version,
285-
min_writer_version,
286-
writer_features,
287-
reader_features,
288-
});
274+
.unwrap_or_else(|| current_protocol);
275+
276+
let protocol = apply_properties_to_protocol(
277+
&protocol,
278+
&configuration
279+
.iter()
280+
.map(|(k, v)| (k.clone(), v.clone().unwrap()))
281+
.collect::<HashMap<String, String>>(),
282+
true,
283+
)?;
284+
285+
let protocol = convert_properties_to_features(protocol, &configuration);
289286

290287
let mut metadata = Metadata::try_new(
291288
StructType::new(self.columns),
292289
self.partition_columns.unwrap_or_default(),
293-
self.configuration,
290+
configuration,
294291
)?
295292
.with_created_time(chrono::Utc::now().timestamp_millis());
296293
if let Some(name) = self.name {

crates/core/src/operations/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub use ::datafusion::physical_plan::common::collect as collect_sendable_stream;
3737
use arrow::record_batch::RecordBatch;
3838
use optimize::OptimizeBuilder;
3939
use restore::RestoreBuilder;
40+
use set_tbl_properties::SetTablePropertiesBuilder;
4041

4142
#[cfg(feature = "datafusion")]
4243
pub mod constraints;
@@ -48,6 +49,7 @@ mod load;
4849
pub mod load_cdf;
4950
#[cfg(feature = "datafusion")]
5051
pub mod merge;
52+
pub mod set_tbl_properties;
5153
#[cfg(feature = "datafusion")]
5254
pub mod update;
5355
#[cfg(feature = "datafusion")]
@@ -219,6 +221,11 @@ impl DeltaOps {
219221
pub fn drop_constraints(self) -> DropConstraintBuilder {
220222
DropConstraintBuilder::new(self.0.log_store, self.0.state.unwrap())
221223
}
224+
225+
/// Set table properties
226+
pub fn set_tbl_properties(self) -> SetTablePropertiesBuilder {
227+
SetTablePropertiesBuilder::new(self.0.log_store, self.0.state.unwrap())
228+
}
222229
}
223230

224231
impl From<DeltaTable> for DeltaOps {

0 commit comments

Comments
 (0)