|
37 | 37 | // attempt to parse a key-value pair into a `TableProperties` struct. Returns Some(()) if the key |
38 | 38 | // was successfully parsed, and None otherwise. |
39 | 39 | fn try_parse(props: &mut TableProperties, k: &str, v: &str) -> Option<()> { |
| 40 | + // NOTE!! we do Some(parse(v)?) instead of just parse(v) because we want to return None if the |
| 41 | + // parsing fails. If we simply call 'parse(v)', then we would (incorrectly) return Some(()) and |
| 42 | + // just set the property to None. |
40 | 43 | match k { |
41 | 44 | "delta.appendOnly" => props.append_only = Some(parse_bool(v)?), |
42 | 45 | "delta.autoOptimize.autoCompact" => props.auto_compact = Some(parse_bool(v)?), |
@@ -76,17 +79,36 @@ fn try_parse(props: &mut TableProperties, k: &str, v: &str) -> Option<()> { |
76 | 79 | } |
77 | 80 | "delta.checkpointPolicy" => props.checkpoint_policy = CheckpointPolicy::try_from(v).ok(), |
78 | 81 | "delta.enableRowTracking" => props.enable_row_tracking = Some(parse_bool(v)?), |
| 82 | + "delta.enableInCommitTimestamps" => { |
| 83 | + props.enable_in_commit_timestamps = Some(parse_bool(v)?) |
| 84 | + } |
| 85 | + "delta.inCommitTimestampEnablementVersion" => { |
| 86 | + props.in_commit_timestamp_enablement_version = Some(parse_non_negative(v)?) |
| 87 | + } |
| 88 | + "delta.inCommitTimestampEnablementTimestamp" => { |
| 89 | + props.in_commit_timestamp_enablement_timestamp = Some(parse_non_negative(v)?) |
| 90 | + } |
79 | 91 | _ => return None, |
80 | 92 | } |
81 | 93 | Some(()) |
82 | 94 | } |
83 | 95 |
|
84 | | -/// Deserialize a string representing a positive integer into an `Option<u64>`. Returns `Some` if |
85 | | -/// successfully parses, and `None` otherwise. |
| 96 | +/// Deserialize a string representing a positive (> 0) integer into an `Option<u64>`. Returns `Some` |
| 97 | +/// if successfully parses, and `None` otherwise. |
86 | 98 | pub(crate) fn parse_positive_int(s: &str) -> Option<NonZero<u64>> { |
87 | | - // parse to i64 (then check n > 0) since java doesn't even allow u64 |
88 | | - let n: i64 = s.parse().ok()?; |
89 | | - NonZero::new(n.try_into().ok()?) |
| 99 | + // parse as non-negative and verify the result is non-zero |
| 100 | + NonZero::new(parse_non_negative(s)?) |
| 101 | +} |
| 102 | + |
| 103 | +/// Deserialize a string representing a non-negative integer into an `Option<u64>`. Returns `Some` if |
| 104 | +/// successfully parses, and `None` otherwise. |
| 105 | +pub(crate) fn parse_non_negative<T>(s: &str) -> Option<T> |
| 106 | +where |
| 107 | + i64: TryInto<T>, |
| 108 | +{ |
| 109 | + // parse to i64 since java doesn't even allow u64 |
| 110 | + let n: i64 = s.parse().ok().filter(|&i| i >= 0)?; |
| 111 | + n.try_into().ok() |
90 | 112 | } |
91 | 113 |
|
92 | 114 | /// Deserialize a string representing a boolean into an `Option<bool>`. Returns `Some` if |
@@ -199,10 +221,16 @@ mod tests { |
199 | 221 | } |
200 | 222 |
|
201 | 223 | #[test] |
202 | | - fn test_parse_positive_int() { |
203 | | - assert_eq!(parse_positive_int("123").unwrap().get(), 123); |
| 224 | + fn test_parse_int() { |
| 225 | + assert_eq!(parse_positive_int("12").unwrap().get(), 12); |
204 | 226 | assert_eq!(parse_positive_int("0"), None); |
205 | | - assert_eq!(parse_positive_int("-123"), None); |
| 227 | + assert_eq!(parse_positive_int("-12"), None); |
| 228 | + assert_eq!(parse_non_negative::<u64>("12").unwrap(), 12); |
| 229 | + assert_eq!(parse_non_negative::<u64>("0").unwrap(), 0); |
| 230 | + assert_eq!(parse_non_negative::<u64>("-12"), None); |
| 231 | + assert_eq!(parse_non_negative::<i64>("12").unwrap(), 12); |
| 232 | + assert_eq!(parse_non_negative::<i64>("0").unwrap(), 0); |
| 233 | + assert_eq!(parse_non_negative::<i64>("-12"), None); |
206 | 234 | } |
207 | 235 |
|
208 | 236 | #[test] |
|
0 commit comments