Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI build] fix chrono suggestions #9486

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafusion-examples/examples/to_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async fn main() -> Result<()> {
.collect()
.await;

let expected = "Error parsing timestamp from '01-14-2023 01/01/30' using format '%d-%m-%Y %H:%M:%S': input contains invalid characters";
let expected = "Execution error: Error parsing timestamp from '01-14-2023 01/01/30' using format '%d-%m-%Y %H:%M:%S': input is out of range";
assert_contains!(result.unwrap_err().to_string(), expected);

// note that using arrays for the chrono formats is not supported
Expand Down
4 changes: 4 additions & 0 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5826,6 +5826,7 @@ mod tests {
.unwrap()
.and_hms_opt(hour, minute, second)
.unwrap()
.and_utc()
.timestamp(),
),
None,
Expand All @@ -5838,6 +5839,7 @@ mod tests {
.unwrap()
.and_hms_milli_opt(hour, minute, second, millisec)
.unwrap()
.and_utc()
.timestamp_millis(),
),
None,
Expand All @@ -5850,6 +5852,7 @@ mod tests {
.unwrap()
.and_hms_micro_opt(hour, minute, second, microsec)
.unwrap()
.and_utc()
.timestamp_micros(),
),
None,
Expand All @@ -5862,6 +5865,7 @@ mod tests {
.unwrap()
.and_hms_nano_opt(hour, minute, second, nanosec)
.unwrap()
.and_utc()
.timestamp_nanos_opt()
.unwrap(),
),
Expand Down
21 changes: 11 additions & 10 deletions datafusion/core/tests/parquet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use arrow::{
record_batch::RecordBatch,
util::pretty::pretty_format_batches,
};
use chrono::{Datelike, Duration};
use chrono::{Datelike, Duration, TimeDelta};
use datafusion::{
datasource::{physical_plan::ParquetExec, provider_as_source, TableProvider},
physical_plan::{accept, metrics::MetricsSet, ExecutionPlan, ExecutionPlanVisitor},
Expand Down Expand Up @@ -310,6 +310,7 @@ fn make_timestamp_batch(offset: Duration) -> RecordBatch {
offset_nanos
+ t.parse::<chrono::NaiveDateTime>()
.unwrap()
.and_utc()
.timestamp_nanos_opt()
.unwrap()
})
Expand Down Expand Up @@ -459,7 +460,7 @@ fn make_date_batch(offset: Duration) -> RecordBatch {
.unwrap()
.and_time(chrono::NaiveTime::from_hms_opt(0, 0, 0).unwrap());
let t = t + offset;
t.timestamp_millis()
t.and_utc().timestamp_millis()
})
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -511,18 +512,18 @@ fn create_data_batch(scenario: Scenario) -> Vec<RecordBatch> {
match scenario {
Scenario::Timestamps => {
vec![
make_timestamp_batch(Duration::seconds(0)),
make_timestamp_batch(Duration::seconds(10)),
make_timestamp_batch(Duration::minutes(10)),
make_timestamp_batch(Duration::days(10)),
make_timestamp_batch(TimeDelta::try_seconds(0).unwrap()),
make_timestamp_batch(TimeDelta::try_seconds(10).unwrap()),
make_timestamp_batch(TimeDelta::try_minutes(10).unwrap()),
make_timestamp_batch(TimeDelta::try_days(10).unwrap()),
]
}
Scenario::Dates => {
vec![
make_date_batch(Duration::days(0)),
make_date_batch(Duration::days(10)),
make_date_batch(Duration::days(300)),
make_date_batch(Duration::days(3600)),
make_date_batch(TimeDelta::try_days(0).unwrap()),
make_date_batch(TimeDelta::try_days(10).unwrap()),
make_date_batch(TimeDelta::try_days(300).unwrap()),
make_date_batch(TimeDelta::try_days(3600).unwrap()),
]
}
Scenario::Int32 => {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/parquet/page_pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ async fn prune_date64() {
.parse::<chrono::NaiveDate>()
.unwrap()
.and_time(chrono::NaiveTime::from_hms_opt(0, 0, 0).unwrap());
let date = ScalarValue::Date64(Some(date.timestamp_millis()));
let date = ScalarValue::Date64(Some(date.and_utc().timestamp_millis()));

let output = ContextWithParquet::new(Scenario::Dates, Page)
.await
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/parquet/row_group_pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async fn prune_date64() {
.parse::<chrono::NaiveDate>()
.unwrap()
.and_time(chrono::NaiveTime::from_hms_opt(0, 0, 0).unwrap());
let date = ScalarValue::Date64(Some(date.timestamp_millis()));
let date = ScalarValue::Date64(Some(date.and_utc().timestamp_millis()));

let output = ContextWithParquet::new(Scenario::Dates, RowGroup)
.await
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/src/datetime/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pub(crate) fn string_to_timestamp_nanos_formatted(
) -> Result<i64, DataFusionError> {
string_to_datetime_formatted(&Utc, s, format)?
.naive_utc()
.and_utc()
.timestamp_nanos_opt()
.ok_or_else(|| {
DataFusionError::Execution(ERR_NANOSECONDS_NOT_SUPPORTED.to_string())
Expand Down
5 changes: 2 additions & 3 deletions datafusion/optimizer/tests/optimizer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use datafusion_sql::sqlparser::dialect::GenericDialect;
use datafusion_sql::sqlparser::parser::Parser;
use datafusion_sql::TableReference;

use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::DateTime;

#[cfg(test)]
#[ctor::ctor]
Expand Down Expand Up @@ -347,8 +347,7 @@ fn test_sql(sql: &str) -> Result<LogicalPlan> {
let plan = sql_to_rel.sql_statement_to_plan(statement.clone()).unwrap();

// hard code the return value of now()
let ts = NaiveDateTime::from_timestamp_opt(1666615693, 0).unwrap();
let now_time = DateTime::<Utc>::from_naive_utc_and_offset(ts, Utc);
let now_time = DateTime::from_timestamp(1666615693, 0).unwrap();
let config = OptimizerContext::new()
.with_skip_failing_rules(false)
.with_query_execution_start_time(now_time);
Expand Down
5 changes: 3 additions & 2 deletions datafusion/physical-expr/benches/to_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::sync::Arc;

use arrow_array::{ArrayRef, Date32Array, StringArray};
use chrono::prelude::*;
use chrono::Duration;
use chrono::TimeDelta;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand::rngs::ThreadRng;
use rand::seq::SliceRandom;
Expand All @@ -39,7 +39,7 @@ fn random_date_in_range(
) -> NaiveDate {
let days_in_range = (end_date - start_date).num_days();
let random_days: i64 = rng.gen_range(0..days_in_range);
start_date + Duration::days(random_days)
start_date + TimeDelta::try_days(random_days).unwrap()
}

fn data(rng: &mut ThreadRng) -> Date32Array {
Expand Down Expand Up @@ -113,6 +113,7 @@ fn criterion_benchmark(c: &mut Criterion) {
.unwrap()
.with_nanosecond(56789)
.unwrap()
.and_utc()
.timestamp_nanos_opt()
.unwrap();
let data = ColumnarValue::Scalar(TimestampNanosecond(Some(timestamp), None));
Expand Down
Loading
Loading