Skip to content

Commit

Permalink
feat(cubesql): Improve support (formats) for TO_TIMESTAMP function (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Sep 1, 2022
1 parent 3c6ff7d commit 044c3e1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rust/cubesql/cubesql/src/compile/engine/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,10 +1164,14 @@ fn postgres_datetime_format_to_iso(format: String) -> String {
.replace("%s", "%S")
.replace(".%f", "%.f")
.replace("YYYY", "%Y")
.replace("yyyy", "%Y")
.replace("DD", "%d")
.replace("dd", "%d")
.replace("HH24", "%H")
.replace("MI", "%M")
.replace("mi", "%M")
.replace("SS", "%S")
.replace("ss", "%S")
.replace(".US", "%.f")
.replace("MM", "%m")
.replace(".MS", "%.3f")
Expand Down
47 changes: 47 additions & 0 deletions rust/cubesql/cubesql/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10849,6 +10849,53 @@ ORDER BY \"COUNT(count)\" DESC"
Ok(())
}

#[tokio::test]
async fn test_quicksight_to_timestamp_format() -> Result<(), CubeError> {
let query_plan = convert_select_to_query_plan(
r#"
SELECT
date_trunc('day', "order_date") AS "uuid.order_date_tg",
COUNT(*) AS "count"
FROM "public"."KibanaSampleDataEcommerce"
WHERE
"order_date" >= date_trunc('second', TO_TIMESTAMP('2019-01-01 00:00:00', 'yyyy-MM-dd HH24:mi:ss')) AND
"order_date" < date_trunc('second', TO_TIMESTAMP('2020-01-01 00:00:00', 'yyyy-MM-dd HH24:mi:ss'))
GROUP BY date_trunc('day', "order_date")
ORDER BY date_trunc('day', "order_date") DESC NULLS LAST
LIMIT 2500
;"#.to_string(),
DatabaseProtocol::PostgreSQL,
).await;

let logical_plan = query_plan.as_logical_plan();

assert_eq!(
logical_plan.find_cube_scan().request,
V1LoadRequestQuery {
measures: Some(vec!["KibanaSampleDataEcommerce.count".to_string()]),
segments: Some(vec![]),
dimensions: Some(vec![]),
time_dimensions: Some(vec![V1LoadRequestQueryTimeDimension {
dimension: "KibanaSampleDataEcommerce.order_date".to_string(),
granularity: Some("day".to_string()),
date_range: Some(json!(vec![
"2019-01-01T00:00:00.000Z".to_string(),
"2019-12-31T23:59:59.999Z".to_string()
])),
}]),
order: Some(vec![vec![
"KibanaSampleDataEcommerce.order_date".to_string(),
"desc".to_string()
]]),
limit: Some(2500),
offset: None,
filters: None,
}
);

Ok(())
}

#[tokio::test]
async fn test_localtimestamp() -> Result<(), CubeError> {
// TODO: the value will be different with the introduction of TZ support
Expand Down

0 comments on commit 044c3e1

Please sign in to comment.