Skip to content

Commit

Permalink
Fix chrono dependency version mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Jan 6, 2024
1 parent f40e411 commit a8efbe6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
18 changes: 3 additions & 15 deletions rust/cubesql/Cargo.lock

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

24 changes: 16 additions & 8 deletions rust/cubesql/cubesql/src/compile/legacy_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use crate::{
sql::ColumnType,
transport::{V1CubeMetaDimensionExt, V1CubeMetaMeasureExt, V1CubeMetaSegmentExt},
};
use chrono::{DateTime, Datelike, Duration, NaiveDate, SecondsFormat, TimeZone, Utc};
use chrono::{
DateTime, Datelike, Duration, NaiveDate, NaiveDateTime, SecondsFormat, TimeZone, Utc,
};
use cubeclient::models::{V1LoadRequestQueryFilterItem, V1LoadRequestQueryTimeDimension};
use log::{debug, trace};
use serde_json::json;
Expand Down Expand Up @@ -122,8 +124,10 @@ impl CompiledExpression {
match self {
CompiledExpression::DateLiteral(date) => Some(*date),
CompiledExpression::StringLiteral(s) => {
if let Ok(datetime) = DateTime::parse_from_str(s.as_str(), "%Y-%m-%d %H:%M:%S.%f") {
return Some(datetime.into());
if let Ok(datetime) =
NaiveDateTime::parse_from_str(s.as_str(), "%Y-%m-%d %H:%M:%S.%f")
{
return Some(Utc.from_utc_datetime(&datetime));
};

if let Ok(datetime) = DateTime::parse_from_rfc3339(s.as_str()) {
Expand Down Expand Up @@ -227,12 +231,14 @@ fn str_to_date_function(f: &ast::Function) -> CompilationResult<CompiledExpressi
)));
}

let parsed_date =
DateTime::parse_from_str(date.as_str(), "%Y-%m-%d %H:%M:%S.%f").map_err(|e| {
let parsed_date = NaiveDateTime::parse_from_str(date.as_str(), "%Y-%m-%d %H:%M:%S.%f")
.map_err(|e| {
CompilationError::user(format!("Unable to parse {}, err: {}", date, e.to_string(),))
})?;

Ok(CompiledExpression::DateLiteral(parsed_date.into()))
Ok(CompiledExpression::DateLiteral(
Utc.from_utc_datetime(&parsed_date),
))
}

// DATE(expr)
Expand All @@ -252,7 +258,7 @@ fn date_function(f: &ast::Function, ctx: &QueryContext) -> CompilationResult<Com
match compiled {
date @ CompiledExpression::DateLiteral(_) => Ok(date),
CompiledExpression::StringLiteral(ref input) => {
let parsed_date = DateTime::parse_from_str(input.as_str(), "%Y-%m-%d %H:%M:%S.%f")
let parsed_date = NaiveDateTime::parse_from_str(input.as_str(), "%Y-%m-%d %H:%M:%S.%f")
.map_err(|e| {
CompilationError::user(format!(
"Unable to parse {}, err: {}",
Expand All @@ -261,7 +267,9 @@ fn date_function(f: &ast::Function, ctx: &QueryContext) -> CompilationResult<Com
))
})?;

Ok(CompiledExpression::DateLiteral(parsed_date.into()))
Ok(CompiledExpression::DateLiteral(
Utc.from_utc_datetime(&parsed_date),
))
}
_ => {
return Err(CompilationError::user(format!(
Expand Down

0 comments on commit a8efbe6

Please sign in to comment.