Skip to content

Commit f61d475

Browse files
fix: Remove deprecated methods to pass ci (#234)
1 parent 0fc0b0f commit f61d475

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

crates/iceberg/src/spec/values.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::fmt::{Display, Formatter};
2323
use std::str::FromStr;
2424
use std::{any::Any, collections::BTreeMap};
2525

26-
use crate::error::Result;
2726
use bitvec::vec::BitVec;
2827
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
2928
use ordered_float::OrderedFloat;
@@ -32,16 +31,17 @@ use serde_bytes::ByteBuf;
3231
use serde_json::{Map as JsonMap, Number, Value as JsonValue};
3332
use uuid::Uuid;
3433

35-
use crate::{ensure_data_valid, Error, ErrorKind};
36-
37-
use super::datatypes::{PrimitiveType, Type};
34+
pub use _serde::RawLiteral;
3835

36+
use crate::error::Result;
3937
use crate::spec::values::date::{date_from_naive_date, days_to_date, unix_epoch};
4038
use crate::spec::values::time::microseconds_to_time;
4139
use crate::spec::values::timestamp::microseconds_to_datetime;
4240
use crate::spec::values::timestamptz::microseconds_to_datetimetz;
4341
use crate::spec::MAX_DECIMAL_PRECISION;
44-
pub use _serde::RawLiteral;
42+
use crate::{ensure_data_valid, Error, ErrorKind};
43+
44+
use super::datatypes::{PrimitiveType, Type};
4545

4646
/// Maximum value for [`PrimitiveType::Time`] type in microseconds, e.g. 23 hours 59 minutes 59 seconds 999999 microseconds.
4747
const MAX_TIME_VALUE: i64 = 24 * 60 * 60 * 1_000_000i64 - 1;
@@ -443,7 +443,7 @@ impl Datum {
443443
/// assert_eq!(&format!("{t}"), "1992-03-01 01:02:03.000088");
444444
/// ```
445445
pub fn timestamp_from_datetime(dt: NaiveDateTime) -> Self {
446-
Self::timestamp_micros(dt.timestamp_micros())
446+
Self::timestamp_micros(dt.and_utc().timestamp_micros())
447447
}
448448

449449
/// Parse a timestamp in [`%Y-%m-%dT%H:%M:%S%.f`] format.
@@ -1530,7 +1530,7 @@ impl Literal {
15301530
}
15311531

15321532
mod date {
1533-
use chrono::{DateTime, NaiveDate, NaiveDateTime, TimeZone, Utc};
1533+
use chrono::{DateTime, NaiveDate, TimeDelta, TimeZone, Utc};
15341534

15351535
pub(crate) fn date_to_days(date: &NaiveDate) -> i32 {
15361536
date.signed_duration_since(
@@ -1542,8 +1542,8 @@ mod date {
15421542

15431543
pub(crate) fn days_to_date(days: i32) -> NaiveDate {
15441544
// This shouldn't fail until the year 262000
1545-
NaiveDateTime::from_timestamp_opt(days as i64 * 86_400, 0)
1546-
.unwrap()
1545+
(chrono::DateTime::UNIX_EPOCH + TimeDelta::try_days(days as i64).unwrap())
1546+
.naive_utc()
15471547
.date()
15481548
}
15491549

@@ -1578,22 +1578,21 @@ mod time {
15781578
}
15791579

15801580
mod timestamp {
1581-
use chrono::NaiveDateTime;
1581+
use chrono::{DateTime, NaiveDateTime};
15821582

15831583
pub(crate) fn datetime_to_microseconds(time: &NaiveDateTime) -> i64 {
1584-
time.timestamp_micros()
1584+
time.and_utc().timestamp_micros()
15851585
}
15861586

15871587
pub(crate) fn microseconds_to_datetime(micros: i64) -> NaiveDateTime {
1588-
let (secs, rem) = (micros / 1_000_000, micros % 1_000_000);
1589-
15901588
// This shouldn't fail until the year 262000
1591-
NaiveDateTime::from_timestamp_opt(secs, rem as u32 * 1_000).unwrap()
1589+
DateTime::from_timestamp_micros(micros).unwrap().naive_utc()
15921590
}
15931591
}
15941592

15951593
mod timestamptz {
1596-
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
1594+
use chrono::DateTime;
1595+
use chrono::Utc;
15971596

15981597
pub(crate) fn datetimetz_to_microseconds(time: &DateTime<Utc>) -> i64 {
15991598
time.timestamp_micros()
@@ -1602,22 +1601,13 @@ mod timestamptz {
16021601
pub(crate) fn microseconds_to_datetimetz(micros: i64) -> DateTime<Utc> {
16031602
let (secs, rem) = (micros / 1_000_000, micros % 1_000_000);
16041603

1605-
Utc.from_utc_datetime(
1606-
// This shouldn't fail until the year 262000
1607-
&NaiveDateTime::from_timestamp_opt(secs, rem as u32 * 1_000).unwrap(),
1608-
)
1604+
DateTime::from_timestamp(secs, rem as u32 * 1_000).unwrap()
16091605
}
16101606
}
16111607

16121608
mod _serde {
16131609
use std::collections::BTreeMap;
16141610

1615-
use crate::{
1616-
spec::{PrimitiveType, Type, MAP_KEY_FIELD_NAME, MAP_VALUE_FIELD_NAME},
1617-
Error, ErrorKind,
1618-
};
1619-
1620-
use super::{Literal, PrimitiveLiteral};
16211611
use serde::{
16221612
de::Visitor,
16231613
ser::{SerializeMap, SerializeSeq, SerializeStruct},
@@ -1627,6 +1617,13 @@ mod _serde {
16271617
use serde_derive::Deserialize as DeserializeDerive;
16281618
use serde_derive::Serialize as SerializeDerive;
16291619

1620+
use crate::{
1621+
spec::{PrimitiveType, Type, MAP_KEY_FIELD_NAME, MAP_VALUE_FIELD_NAME},
1622+
Error, ErrorKind,
1623+
};
1624+
1625+
use super::{Literal, PrimitiveLiteral};
1626+
16301627
#[derive(SerializeDerive, DeserializeDerive, Debug)]
16311628
#[serde(transparent)]
16321629
/// Raw literal representation used for serde. The serialize way is used for Avro serializer.
@@ -2186,7 +2183,6 @@ mod _serde {
21862183

21872184
#[cfg(test)]
21882185
mod tests {
2189-
21902186
use apache_avro::{to_value, types::Value};
21912187

21922188
use crate::{

0 commit comments

Comments
 (0)