Skip to content

Commit 4408dd7

Browse files
committed
fix: always include the Invariants writerFeature when upgrading to v7
The presence of a timestampntz column in CreateBuilder results in the reader/writer being set to 3/7. The protocol reaquires that if the table is writer v7, that `invariants` "must exist in the table protocl's writerFeatures. Sponsored-by: Scribd Inc Signed-off-by: R. Tyler Croy <[email protected]>
1 parent 10c6b5c commit 4408dd7

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ impl Protocol {
372372
/// Enable timestamp_ntz in the protocol
373373
pub fn enable_timestamp_ntz(mut self) -> Protocol {
374374
self = self.with_reader_features(vec![ReaderFeatures::TimestampWithoutTimezone]);
375-
self = self.with_writer_features(vec![WriterFeatures::TimestampWithoutTimezone]);
375+
self = self.with_writer_features(vec![
376+
WriterFeatures::TimestampWithoutTimezone,
377+
WriterFeatures::Invariants,
378+
]);
376379
self
377380
}
378381
}

crates/core/src/operations/create.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ impl CreateBuilder {
274274
Protocol {
275275
min_reader_version: 3,
276276
min_writer_version: 7,
277-
writer_features: Some(hashset! {WriterFeatures::TimestampWithoutTimezone}),
277+
writer_features: Some(
278+
hashset! {WriterFeatures::TimestampWithoutTimezone, WriterFeatures::Invariants},
279+
),
278280
reader_features: Some(hashset! {ReaderFeatures::TimestampWithoutTimezone}),
279281
}
280282
} else {
@@ -630,4 +632,43 @@ mod tests {
630632
.clone();
631633
assert_eq!(String::from("value"), value);
632634
}
635+
636+
#[tokio::test]
637+
async fn test_invariants_when_timestampntz_exists() {
638+
use crate::kernel::*;
639+
640+
let columns: Vec<StructField> = vec![
641+
StructField::new("id", DataType::Primitive(PrimitiveType::Integer), false),
642+
StructField::new(
643+
"sunrise",
644+
DataType::Primitive(PrimitiveType::TimestampNtz),
645+
false,
646+
),
647+
];
648+
649+
let table = CreateBuilder::new()
650+
.with_location("memory://")
651+
.with_columns(columns)
652+
.await
653+
.expect("Failed to create the table");
654+
655+
// Ensure that the table can be created properly with the timestmapntz
656+
assert_eq!(table.version(), 0);
657+
let protocol = table.protocol().expect("Failed to load the protocol");
658+
659+
assert_eq!(protocol.min_reader_version, 3);
660+
assert_eq!(protocol.min_writer_version, 7);
661+
662+
let writer_features = protocol.writer_features.as_ref().unwrap();
663+
assert!(
664+
writer_features.contains(&WriterFeatures::TimestampWithoutTimezone),
665+
"The writer features must have TimestampeWithoutTimezone at writer:v7: {:#?}",
666+
writer_features
667+
);
668+
assert!(
669+
writer_features.contains(&WriterFeatures::Invariants),
670+
"The writer features must have Invariants at writer:v7: {:#?}",
671+
writer_features
672+
);
673+
}
633674
}

0 commit comments

Comments
 (0)