|
| 1 | +use crate::type_system::main::normalize_type::normalize_type; |
| 2 | +use crate::type_system::main::same_type::same_type; |
| 3 | +use crate::type_system::tests::test_types::SameTypeTestCase; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn given_two_types_when_comparing_then_an_unstated_snowflake_temporal_precision_matches() { |
| 7 | + let test_cases = [ |
| 8 | + SameTypeTestCase { |
| 9 | + description: "a declared millisecond time matches metadata's precision-less time", |
| 10 | + dialect: "snowflake", |
| 11 | + types: ("TIME(3)", "TIME"), |
| 12 | + expected_same: true, |
| 13 | + }, |
| 14 | + SameTypeTestCase { |
| 15 | + description: "a declared nanosecond time matches metadata's precision-less time", |
| 16 | + dialect: "snowflake", |
| 17 | + types: ("TIME", "TIME(9)"), |
| 18 | + expected_same: true, |
| 19 | + }, |
| 20 | + SameTypeTestCase { |
| 21 | + description: "two stated time precisions must agree", |
| 22 | + dialect: "snowflake", |
| 23 | + types: ("TIME(3)", "TIME(9)"), |
| 24 | + expected_same: false, |
| 25 | + }, |
| 26 | + SameTypeTestCase { |
| 27 | + description: "a declared offset timestamp precision matches metadata's spelling", |
| 28 | + dialect: "snowflake", |
| 29 | + types: ("TIMESTAMP_TZ(9)", "TIMESTAMP_TZ"), |
| 30 | + expected_same: true, |
| 31 | + }, |
| 32 | + SameTypeTestCase { |
| 33 | + description: "two stated offset timestamp precisions must agree", |
| 34 | + dialect: "snowflake", |
| 35 | + types: ("TIMESTAMP_TZ(3)", "TIMESTAMP_TZ(9)"), |
| 36 | + expected_same: false, |
| 37 | + }, |
| 38 | + SameTypeTestCase { |
| 39 | + description: "local time zone timestamps with and without precision", |
| 40 | + dialect: "snowflake", |
| 41 | + types: ("TIMESTAMP_LTZ(6)", "TIMESTAMP_LTZ"), |
| 42 | + expected_same: true, |
| 43 | + }, |
| 44 | + SameTypeTestCase { |
| 45 | + description: "an offset timestamp is not a local time zone timestamp", |
| 46 | + dialect: "snowflake", |
| 47 | + types: ("TIMESTAMP_TZ", "TIMESTAMP_LTZ(9)"), |
| 48 | + expected_same: false, |
| 49 | + }, |
| 50 | + SameTypeTestCase { |
| 51 | + description: "time is not a timestamp", |
| 52 | + dialect: "snowflake", |
| 53 | + types: ("TIME(9)", "TIMESTAMP_NTZ"), |
| 54 | + expected_same: false, |
| 55 | + }, |
| 56 | + SameTypeTestCase { |
| 57 | + description: "other dialects keep exact comparison", |
| 58 | + dialect: "duckdb", |
| 59 | + types: ("TIME(3)", "TIME"), |
| 60 | + expected_same: false, |
| 61 | + }, |
| 62 | + SameTypeTestCase { |
| 63 | + description: "an unstated text length is still a different type", |
| 64 | + dialect: "snowflake", |
| 65 | + types: ("VARCHAR(10)", "VARCHAR(20)"), |
| 66 | + expected_same: false, |
| 67 | + }, |
| 68 | + ]; |
| 69 | + for test_case in test_cases { |
| 70 | + let (left, right) = test_case.types; |
| 71 | + let left = normalize_type(left, test_case.dialect) |
| 72 | + .expect("the type normalizes") |
| 73 | + .normalized; |
| 74 | + let right = normalize_type(right, test_case.dialect) |
| 75 | + .expect("the type normalizes") |
| 76 | + .normalized; |
| 77 | + assert_eq!( |
| 78 | + same_type(&left, &right, test_case.dialect), |
| 79 | + test_case.expected_same, |
| 80 | + "{}", |
| 81 | + test_case.description |
| 82 | + ); |
| 83 | + } |
| 84 | +} |
0 commit comments