#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct PlanOptions {
pub string_policy: StringPolicy,
pub binary_policy: BinaryPolicy,
pub timezone_policy: TimezonePolicy,
pub nanosecond_policy: NanosecondPolicy,
pub uint64_policy: UInt64Policy,
pub decimal_policy: DecimalPolicy,
pub decimal256_policy: Decimal256Policy,
pub float_policy: FloatPolicy,
pub date64_policy: Date64Policy,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum StringPolicy {
#[default]
NVarCharMax,
NVarChar(usize),
ObservedNVarChar,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum BinaryPolicy {
#[default]
VarBinaryMax,
VarBinary(usize),
ObservedVarBinary,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum TimezonePolicy {
#[default]
Reject,
DateTimeOffset,
NormalizeUtcDateTime2,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum NanosecondPolicy {
#[default]
RejectNon100ns,
RoundTo100ns,
TruncateTo100ns,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum UInt64Policy {
#[default]
Reject,
Decimal20_0,
CheckedBigInt,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum DecimalPolicy {
#[default]
RejectNegativeScale,
NormalizeNegativeScale,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Decimal256Policy {
#[default]
CheckedDowncast,
Reject,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum FloatPolicy {
#[default]
RejectNonFinite,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Date64Policy {
#[default]
RejectNonMidnight,
TimestampDateTime2,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum SchemaCheck {
#[default]
Strict,
}
#[cfg(test)]
mod tests {
use super::{
BinaryPolicy, Date64Policy, Decimal256Policy, DecimalPolicy, FloatPolicy, NanosecondPolicy,
PlanOptions, SchemaCheck, StringPolicy, TimezonePolicy, UInt64Policy,
};
#[test]
fn defaults_match_v0_1_policy_decisions() {
let options = PlanOptions::default();
assert_eq!(options.string_policy, StringPolicy::NVarCharMax);
assert_eq!(options.binary_policy, BinaryPolicy::VarBinaryMax);
assert_eq!(options.timezone_policy, TimezonePolicy::Reject);
assert_eq!(options.nanosecond_policy, NanosecondPolicy::RejectNon100ns);
assert_eq!(options.uint64_policy, UInt64Policy::Reject);
assert_eq!(options.decimal_policy, DecimalPolicy::RejectNegativeScale);
assert_eq!(options.decimal256_policy, Decimal256Policy::CheckedDowncast);
assert_eq!(options.float_policy, FloatPolicy::RejectNonFinite);
assert_eq!(options.date64_policy, Date64Policy::RejectNonMidnight);
}
#[test]
fn individual_policy_defaults_match_plan_options() {
assert_eq!(StringPolicy::default(), StringPolicy::NVarCharMax);
assert_eq!(BinaryPolicy::default(), BinaryPolicy::VarBinaryMax);
assert_eq!(TimezonePolicy::default(), TimezonePolicy::Reject);
assert_eq!(
NanosecondPolicy::default(),
NanosecondPolicy::RejectNon100ns
);
assert_eq!(UInt64Policy::default(), UInt64Policy::Reject);
assert_eq!(DecimalPolicy::default(), DecimalPolicy::RejectNegativeScale);
assert_eq!(
Decimal256Policy::default(),
Decimal256Policy::CheckedDowncast
);
assert_eq!(FloatPolicy::default(), FloatPolicy::RejectNonFinite);
assert_eq!(Date64Policy::default(), Date64Policy::RejectNonMidnight);
assert_eq!(SchemaCheck::default(), SchemaCheck::Strict);
}
#[test]
fn supports_explicit_non_default_policy_overrides() {
let options = PlanOptions {
string_policy: StringPolicy::NVarChar(128),
binary_policy: BinaryPolicy::VarBinary(256),
timezone_policy: TimezonePolicy::DateTimeOffset,
nanosecond_policy: NanosecondPolicy::RoundTo100ns,
uint64_policy: UInt64Policy::Decimal20_0,
decimal_policy: DecimalPolicy::NormalizeNegativeScale,
decimal256_policy: Decimal256Policy::Reject,
float_policy: FloatPolicy::RejectNonFinite,
date64_policy: Date64Policy::TimestampDateTime2,
};
assert_eq!(options.string_policy, StringPolicy::NVarChar(128));
assert_eq!(options.binary_policy, BinaryPolicy::VarBinary(256));
assert_eq!(options.timezone_policy, TimezonePolicy::DateTimeOffset);
assert_eq!(options.nanosecond_policy, NanosecondPolicy::RoundTo100ns);
assert_eq!(options.uint64_policy, UInt64Policy::Decimal20_0);
assert_eq!(
options.decimal_policy,
DecimalPolicy::NormalizeNegativeScale
);
assert_eq!(options.decimal256_policy, Decimal256Policy::Reject);
assert_eq!(options.float_policy, FloatPolicy::RejectNonFinite);
assert_eq!(options.date64_policy, Date64Policy::TimestampDateTime2);
}
}