From 7ac2c6eb50d08c112d7a599169aa48766de221dc Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Thu, 30 May 2024 23:38:35 +0800 Subject: [PATCH] chore(rust): resolve deprecate warnings (#1662) ## What does this PR do? - Resolve deprecate warnings from `chrono` dep - Remove patch version in Cargo.toml ## Related issues N/A ## Does this PR introduce any user-facing change? - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? No ## Benchmark Signed-off-by: Ruihang Xia --- rust/fury-derive/Cargo.toml | 13 +++++++++---- rust/fury/Cargo.toml | 16 ++++++++-------- rust/fury/src/deserializer.rs | 2 +- rust/fury/src/row/row.rs | 6 +++--- rust/fury/src/serializer.rs | 4 +++- rust/tests/Cargo.toml | 4 ++-- rust/tests/tests/test_complex_struct.rs | 4 ++-- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/rust/fury-derive/Cargo.toml b/rust/fury-derive/Cargo.toml index 1034fe267c..ced3734351 100644 --- a/rust/fury-derive/Cargo.toml +++ b/rust/fury-derive/Cargo.toml @@ -25,7 +25,12 @@ rust-version.workspace = true proc-macro = true [dependencies] -proc-macro2 = { default-features = false, version = "1.0.66" } -syn = { default-features = false, version = "2.0.26", features = ["parsing", "proc-macro", "derive", "printing"] } -quote = { default-features = false, version = "1.0.31" } -thiserror = { default-features = false, version = "1.0.43" } +proc-macro2 = { default-features = false, version = "1.0" } +syn = { default-features = false, version = "2.0", features = [ + "parsing", + "proc-macro", + "derive", + "printing", +] } +quote = { default-features = false, version = "1.0" } +thiserror = { default-features = false, version = "1.0" } diff --git a/rust/fury/Cargo.toml b/rust/fury/Cargo.toml index ed24f0cda2..d39d537572 100644 --- a/rust/fury/Cargo.toml +++ b/rust/fury/Cargo.toml @@ -22,11 +22,11 @@ edition.workspace = true rust-version.workspace = true [dependencies] -proc-macro2 = { default-features = false, version = "1.0.66" } -syn = { default-features = false, version = "2.0.26", features = ["full", "fold"] } -quote = { default-features = false, version = "1.0.31" } -fury-derive = { path="../fury-derive"} -lazy_static = { version = "1.4.0" } -byteorder = { version = "1.4.3" } -chrono = "0.4.26" -thiserror = { default-features = false, version = "1.0.43" } \ No newline at end of file +proc-macro2 = { default-features = false, version = "1.0" } +syn = { default-features = false, version = "2.0", features = ["full", "fold"] } +quote = { default-features = false, version = "1.0" } +fury-derive = { path = "../fury-derive" } +lazy_static = { version = "1.4" } +byteorder = { version = "1.4" } +chrono = "0.4" +thiserror = { default-features = false, version = "1.0" } diff --git a/rust/fury/src/deserializer.rs b/rust/fury/src/deserializer.rs index ac443ea3d4..764f55953d 100644 --- a/rust/fury/src/deserializer.rs +++ b/rust/fury/src/deserializer.rs @@ -166,7 +166,7 @@ impl Deserialize for HashSet { impl Deserialize for NaiveDateTime { fn read(deserializer: &mut DeserializerState) -> Result { let timestamp = deserializer.reader.u64(); - let ret = NaiveDateTime::from_timestamp_millis(timestamp as i64); + let ret = DateTime::from_timestamp_millis(timestamp as i64).map(|dt| dt.naive_utc()); match ret { Some(r) => Ok(r), None => Err(Error::NaiveDateTime), diff --git a/rust/fury/src/row/row.rs b/rust/fury/src/row/row.rs index 28c32e6bcd..be0f6591dc 100644 --- a/rust/fury/src/row/row.rs +++ b/rust/fury/src/row/row.rs @@ -17,7 +17,7 @@ use crate::{buffer::Writer, Error}; use byteorder::{ByteOrder, LittleEndian}; -use chrono::{Days, NaiveDate, NaiveDateTime}; +use chrono::{DateTime, Days, NaiveDate, NaiveDateTime}; use std::collections::BTreeMap; use std::marker::PhantomData; @@ -109,12 +109,12 @@ impl<'a> Row<'a> for NaiveDateTime { type ReadResult = Result; fn write(v: &Self, writer: &mut Writer) { - writer.i64(v.timestamp_millis()); + writer.i64(v.and_utc().timestamp_millis()); } fn cast(bytes: &[u8]) -> Self::ReadResult { let timestamp = LittleEndian::read_u64(bytes); - let ret = NaiveDateTime::from_timestamp_millis(timestamp as i64); + let ret = DateTime::from_timestamp_millis(timestamp as i64).map(|dt| dt.naive_utc()); match ret { Some(r) => Ok(r), None => Err(Error::NaiveDateTime), diff --git a/rust/fury/src/serializer.rs b/rust/fury/src/serializer.rs index fe5c7e75eb..f22c16361f 100644 --- a/rust/fury/src/serializer.rs +++ b/rust/fury/src/serializer.rs @@ -236,7 +236,9 @@ impl Serialize for HashSet { impl Serialize for NaiveDateTime { fn write(&self, serializer: &mut SerializerState) { - serializer.writer.u64(self.timestamp_millis() as u64); + serializer + .writer + .u64(self.and_utc().timestamp_millis() as u64); } fn reserved_space() -> usize { diff --git a/rust/tests/Cargo.toml b/rust/tests/Cargo.toml index 1b35ee12ad..340411c1ee 100644 --- a/rust/tests/Cargo.toml +++ b/rust/tests/Cargo.toml @@ -26,5 +26,5 @@ publish = false fury = { path = "../fury" } fury-derive = { path = "../fury-derive" } -chrono = "0.4.26" -lazy_static = { version = "1.4.0" } +chrono = "0.4" +lazy_static = { version = "1.4" } diff --git a/rust/tests/tests/test_complex_struct.rs b/rust/tests/tests/test_complex_struct.rs index cc4a5b925f..b114db4220 100644 --- a/rust/tests/tests/test_complex_struct.rs +++ b/rust/tests/tests/test_complex_struct.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -use chrono::{NaiveDate, NaiveDateTime}; +use chrono::{DateTime, NaiveDate, NaiveDateTime}; use fury::{from_buffer, to_buffer, Fury}; use std::collections::HashMap; @@ -60,7 +60,7 @@ fn complex_struct() { op: Some("option".to_string()), op2: None, date: NaiveDate::from_ymd_opt(2025, 12, 12).unwrap(), - time: NaiveDateTime::from_timestamp_opt(1689912359, 0).unwrap(), + time: DateTime::from_timestamp(1689912359, 0).unwrap().naive_utc(), c5: 2.0, c6: 4.0, };