Skip to content

Commit e13d29e

Browse files
committed
remove copy/paste
1 parent 9220bd2 commit e13d29e

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

rust/cubesql/cubesql/src/compile/engine/df/scan.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use std::{
2828
task::{Context, Poll},
2929
};
3030

31+
use crate::compile::date_parser::parse_date_str;
3132
use crate::{
3233
compile::{
3334
engine::df::wrapper::{CubeScanWrappedSqlNode, CubeScanWrapperNode, SqlQuery},
@@ -38,7 +39,7 @@ use crate::{
3839
transport::{CubeStreamReceiver, LoadRequestMeta, SpanId, TransportService},
3940
CubeError,
4041
};
41-
use chrono::{Datelike, NaiveDate, NaiveDateTime};
42+
use chrono::{Datelike, NaiveDate};
4243
use datafusion::{
4344
arrow::{
4445
array::{
@@ -917,15 +918,7 @@ pub fn transform_response<V: ValueObject>(
917918
field_name,
918919
{
919920
(FieldValue::String(s), builder) => {
920-
let timestamp = NaiveDateTime::parse_from_str(s.as_ref(), "%Y-%m-%dT%H:%M:%S%.f")
921-
.or_else(|_| NaiveDateTime::parse_from_str(s.as_ref(), "%Y-%m-%d %H:%M:%S%.f"))
922-
.or_else(|_| NaiveDateTime::parse_from_str(s.as_ref(), "%Y-%m-%dT%H:%M:%S"))
923-
.or_else(|_| NaiveDateTime::parse_from_str(s.as_ref(), "%Y-%m-%dT%H:%M:%S%.fZ"))
924-
.or_else(|_| {
925-
NaiveDate::parse_from_str(s.as_ref(), "%Y-%m-%d").map(|date| {
926-
date.and_hms_opt(0, 0, 0).unwrap()
927-
})
928-
})
921+
let timestamp = parse_date_str(s.as_ref())
929922
.map_err(|e| {
930923
DataFusionError::Execution(format!(
931924
"Can't parse timestamp: '{}': {}",
@@ -959,15 +952,7 @@ pub fn transform_response<V: ValueObject>(
959952
field_name,
960953
{
961954
(FieldValue::String(s), builder) => {
962-
let timestamp = NaiveDateTime::parse_from_str(s.as_ref(), "%Y-%m-%dT%H:%M:%S%.f")
963-
.or_else(|_| NaiveDateTime::parse_from_str(s.as_ref(), "%Y-%m-%d %H:%M:%S%.f"))
964-
.or_else(|_| NaiveDateTime::parse_from_str(s.as_ref(), "%Y-%m-%dT%H:%M:%S"))
965-
.or_else(|_| NaiveDateTime::parse_from_str(s.as_ref(), "%Y-%m-%dT%H:%M:%S%.fZ"))
966-
.or_else(|_| {
967-
NaiveDate::parse_from_str(s.as_ref(), "%Y-%m-%d").map(|date| {
968-
date.and_hms_opt(0, 0, 0).unwrap()
969-
})
970-
})
955+
let timestamp = parse_date_str(s.as_ref())
971956
.map_err(|e| {
972957
DataFusionError::Execution(format!(
973958
"Can't parse timestamp: '{}': {}",

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod service;
1414
pub mod session;
1515

1616
// Internal API
17+
mod date_parser;
1718
pub mod test;
1819

1920
// Re-export for Public API

rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use chrono::{
3737
Numeric::{Day, Hour, Minute, Month, Second, Year},
3838
Pad::Zero,
3939
},
40-
DateTime, Datelike, Days, Duration, Months, NaiveDate, NaiveDateTime, Timelike, Weekday,
40+
DateTime, Datelike, Days, Duration, Months, NaiveDateTime, Timelike, Weekday,
4141
};
4242
use cubeclient::models::V1CubeMeta;
4343
use datafusion::{

0 commit comments

Comments
 (0)