Skip to content

Commit

Permalink
chore(cubesql): Bump chrono and fix deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mcheshkov committed Feb 17, 2025
1 parent 2dd9a4a commit 4fd5acd
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 21 deletions.
6 changes: 3 additions & 3 deletions packages/cubejs-backend-native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust/cubenativeutils/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rust/cubesql/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/cubesql/cubesql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async-trait = "0.1.36"
regex = "1.5"
uuid = { version = "1", features = ["serde", "v4"] }
bincode = "1.3.1"
chrono = "0.4.31"
chrono = "0.4.39"
chrono-tz = "0.6"
tokio-util = { version = "0.7", features=["compat"] }
comfy-table = "7.1.0"
Expand Down
2 changes: 1 addition & 1 deletion rust/cubesql/cubesql/src/compile/engine/df/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ pub fn transform_response<V: ValueObject>(
// TODO switch parsing to microseconds
if timestamp.and_utc().timestamp_millis() > (((1i64) << 62) / 1_000_000) {
builder.append_null()?;
} else if let Some(nanos) = timestamp.timestamp_nanos_opt() {
} else if let Some(nanos) = timestamp.and_utc().timestamp_nanos_opt() {
builder.append_value(nanos)?;
} else {
log::error!(
Expand Down
11 changes: 7 additions & 4 deletions rust/cubesql/cubesql/src/compile/engine/udf/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,8 @@ pub fn create_to_char_udf() -> ScalarUDF {

let secs = duration.num_seconds();
let nanosecs = duration.num_nanoseconds().unwrap_or(0) - secs * 1_000_000_000;
let timestamp = NaiveDateTime::from_timestamp_opt(secs, nanosecs as u32)
let timestamp = ::chrono::DateTime::from_timestamp(secs, nanosecs as u32)
.map(|dt| dt.naive_utc())
.unwrap_or_else(|| panic!("Invalid secs {} nanosecs {}", secs, nanosecs));

// chrono's strftime is missing quarter format, as such a workaround is required
Expand Down Expand Up @@ -2316,24 +2317,26 @@ macro_rules! generate_series_udtf {

macro_rules! generate_series_helper_date32 {
($CURRENT:ident, $STEP:ident, $PRIMITIVE_TYPE: ident) => {
let current_dt = NaiveDateTime::from_timestamp_opt(($CURRENT as i64) * 86400, 0)
let current_dt = ::chrono::DateTime::from_timestamp(($CURRENT as i64) * 86400, 0)
.map(|dt| dt.naive_utc())
.ok_or_else(|| {
DataFusionError::Execution(format!(
"Cannot convert date to NaiveDateTime: {}",
$CURRENT
))
})?;
let res = date_addsub_month_day_nano(current_dt, $STEP, true)?;
$CURRENT = (res.timestamp() / 86400) as $PRIMITIVE_TYPE;
$CURRENT = (res.and_utc().timestamp() / 86400) as $PRIMITIVE_TYPE;
};
}

macro_rules! generate_series_helper_timestamp {
($CURRENT:ident, $STEP:ident, $PRIMITIVE_TYPE: ident) => {
let current_dt = NaiveDateTime::from_timestamp_opt(
let current_dt = ::chrono::DateTime::from_timestamp(
($CURRENT as i64) / 1_000_000_000,
($CURRENT % 1_000_000_000) as u32,
)
.map(|dt| dt.naive_utc())
.ok_or_else(|| {
DataFusionError::Execution(format!(
"Cannot convert timestamp to NaiveDateTime: {}",
Expand Down
4 changes: 2 additions & 2 deletions rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use chrono::{
Numeric::{Day, Hour, Minute, Month, Second, Year},
Pad::Zero,
},
Datelike, Days, Duration, Months, NaiveDate, NaiveDateTime, Timelike, Weekday,
DateTime, Datelike, Days, Duration, Months, NaiveDate, NaiveDateTime, Timelike, Weekday,
};
use cubeclient::models::V1CubeMeta;
use datafusion::{
Expand Down Expand Up @@ -4836,7 +4836,7 @@ impl FilterRules {
};
let ts_seconds = *ts / 1_000_000_000;
let ts_nanos = (*ts % 1_000_000_000) as u32;
let dt = NaiveDateTime::from_timestamp_opt(ts_seconds, ts_nanos).map(|dt| Some(dt));
let dt = DateTime::from_timestamp(ts_seconds, ts_nanos).map(|dt| Some(dt.naive_utc()));
return dt;
};

Expand Down
6 changes: 3 additions & 3 deletions rust/cubesql/cubesql/src/compile/rewrite/rules/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
sync::Arc,
};

use chrono::{Datelike, NaiveDateTime, Timelike};
use chrono::{DateTime, Datelike, Timelike, Utc};
use datafusion::{
arrow::datatypes::{ArrowPrimitiveType, IntervalDayTimeType, IntervalMonthDayNanoType},
error::DataFusionError,
Expand Down Expand Up @@ -457,9 +457,9 @@ pub fn is_literal_date_trunced(ns: i64, granularity: &str) -> Option<bool> {
return Some(false);
}
let seconds = ns / ns_in_seconds;
let dt = NaiveDateTime::from_timestamp_opt(seconds, 0)?;
let dt = DateTime::from_timestamp(seconds, 0)?;

Check warning on line 460 in rust/cubesql/cubesql/src/compile/rewrite/rules/utils.rs

View check run for this annotation

Codecov / codecov/patch

rust/cubesql/cubesql/src/compile/rewrite/rules/utils.rs#L460

Added line #L460 was not covered by tests

let is_minute_trunced = |dt: NaiveDateTime| dt.second() == 0;
let is_minute_trunced = |dt: DateTime<Utc>| dt.second() == 0;

Check warning on line 462 in rust/cubesql/cubesql/src/compile/rewrite/rules/utils.rs

View check run for this annotation

Codecov / codecov/patch

rust/cubesql/cubesql/src/compile/rewrite/rules/utils.rs#L462

Added line #L462 was not covered by tests
let is_hour_trunced = |dt| is_minute_trunced(dt) && dt.minute() == 0;
let is_day_trunced = |dt| is_hour_trunced(dt) && dt.hour() == 0;
let is_week_trunced = |dt| is_day_trunced(dt) && dt.weekday().num_days_from_monday() == 0;
Expand Down
4 changes: 2 additions & 2 deletions rust/cubesqlplanner/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fd5acd

Please sign in to comment.