Skip to content

Commit

Permalink
Part5/N: Handle zero mysql datetime better
Browse files Browse the repository at this point in the history
Summary:
We have mysql tables using timestamp with this value in several places, which cannot be parsed into NaiveDateTime directly - The effect of this is that cannot us row_struct macro to "generate" structs for these tables. Introducing MysqlNaiveDateTime type to let this happen (more easily; otherwise we need to expand the full rowfield impl for the whole struct just to handle the 0000 timestamp properly).

See https://dev.mysql.com/doc/refman/8.4/en/date-and-time-types.html
```
(scriptrw:[email protected])> select UNIX_TIMESTAMP("0000-00-01 00:00:00");
+---------------------------------------+
| UNIX_TIMESTAMP("0000-00-01 00:00:00") |
+---------------------------------------+
|                                     0 |
+---------------------------------------+
1 row in set (0.00 sec)
```

This is a valid "zero" for mysqld. but not convertible to NDT.

Reviewed By: xiw-org

Differential Revision: D63570026

fbshipit-source-id: 5c1058a19220e44b7f6479bdf557be2ef67a0b7e
  • Loading branch information
Srinivasan Mohan authored and facebook-github-bot committed Oct 2, 2024
1 parent 4246f81 commit 9a54154
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions shed/sql/mysql_client_traits/row_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ mod test {
#[test]
fn test_naive_date_time() -> Result<(), ValueError> {
assert_eq!(
NaiveDateTime::parse_from_str("2022-05-30T13:39:58.012345Z", "%+").unwrap(),
NaiveDateTime::parse_from_str("2022-05-30 13:39:58", "%Y-%m-%d %H:%M:%S").unwrap(),
<NaiveDateTime as TryFromRowField>::try_from(RowField::Bytes(
"2022-05-30 13:39:58.012345".as_bytes().to_vec()
"2022-05-30 13:39:58".as_bytes().to_vec()
))
.unwrap()
);
println!("ok");
Ok(())
}
}

0 comments on commit 9a54154

Please sign in to comment.