Skip to content

Commit

Permalink
fix: always include the Invariants writerFeature when upgrading to v7
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rtyler committed Oct 23, 2024
1 parent 10c6b5c commit 4408dd7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
5 changes: 4 additions & 1 deletion crates/core/src/kernel/models/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,10 @@ impl Protocol {
/// Enable timestamp_ntz in the protocol
pub fn enable_timestamp_ntz(mut self) -> Protocol {
self = self.with_reader_features(vec![ReaderFeatures::TimestampWithoutTimezone]);
self = self.with_writer_features(vec![WriterFeatures::TimestampWithoutTimezone]);
self = self.with_writer_features(vec![
WriterFeatures::TimestampWithoutTimezone,
WriterFeatures::Invariants,
]);
self
}
}
Expand Down
43 changes: 42 additions & 1 deletion crates/core/src/operations/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ impl CreateBuilder {
Protocol {
min_reader_version: 3,
min_writer_version: 7,
writer_features: Some(hashset! {WriterFeatures::TimestampWithoutTimezone}),
writer_features: Some(
hashset! {WriterFeatures::TimestampWithoutTimezone, WriterFeatures::Invariants},
),
reader_features: Some(hashset! {ReaderFeatures::TimestampWithoutTimezone}),
}
} else {
Expand Down Expand Up @@ -630,4 +632,43 @@ mod tests {
.clone();
assert_eq!(String::from("value"), value);
}

#[tokio::test]
async fn test_invariants_when_timestampntz_exists() {
use crate::kernel::*;

let columns: Vec<StructField> = vec![
StructField::new("id", DataType::Primitive(PrimitiveType::Integer), false),
StructField::new(
"sunrise",
DataType::Primitive(PrimitiveType::TimestampNtz),
false,
),
];

let table = CreateBuilder::new()
.with_location("memory://")
.with_columns(columns)
.await
.expect("Failed to create the table");

// Ensure that the table can be created properly with the timestmapntz
assert_eq!(table.version(), 0);
let protocol = table.protocol().expect("Failed to load the protocol");

assert_eq!(protocol.min_reader_version, 3);
assert_eq!(protocol.min_writer_version, 7);

let writer_features = protocol.writer_features.as_ref().unwrap();
assert!(
writer_features.contains(&WriterFeatures::TimestampWithoutTimezone),
"The writer features must have TimestampeWithoutTimezone at writer:v7: {:#?}",
writer_features
);
assert!(
writer_features.contains(&WriterFeatures::Invariants),
"The writer features must have Invariants at writer:v7: {:#?}",
writer_features
);
}
}

0 comments on commit 4408dd7

Please sign in to comment.