Skip to content

Commit

Permalink
feat(core): use MySQL interval style for output format (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmedal authored and grieve54706 committed Dec 11, 2024
1 parent 7985d9a commit 7140b58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion wren-core/core/src/mdl/dialect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Dialect for WrenDialect {
}

fn interval_style(&self) -> IntervalStyle {
IntervalStyle::SQLStandard
IntervalStyle::MySQL
}

fn scalar_function_to_sql_overrides(
Expand Down
24 changes: 24 additions & 0 deletions wren-core/core/src/mdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,30 @@ mod test {
}
}

#[tokio::test]
async fn test_mysql_style_interval() -> Result<()> {
let ctx = SessionContext::new();
let analyzed_mdl = Arc::new(AnalyzedWrenMDL::default());
let sql = "select interval 1 day";
let actual =
transform_sql_with_ctx(&ctx, Arc::clone(&analyzed_mdl), &[], sql).await?;
assert_eq!(actual, "SELECT INTERVAL 1 DAY");

let sql = "SELECT INTERVAL '1 YEAR 1 MONTH'";
let actual =
transform_sql_with_ctx(&ctx, Arc::clone(&analyzed_mdl), &[], sql).await?;
assert_eq!(actual, "SELECT INTERVAL 13 MONTH");

let sql = "SELECT INTERVAL '1' YEAR + INTERVAL '2' MONTH + INTERVAL '3' DAY";
let actual =
transform_sql_with_ctx(&ctx, Arc::clone(&analyzed_mdl), &[], sql).await?;
assert_eq!(
actual,
"SELECT INTERVAL 12 MONTH + INTERVAL 2 MONTH + INTERVAL 3 DAY"
);
Ok(())
}

#[tokio::test]
async fn test_simplify_timestamp() -> Result<()> {
let ctx = SessionContext::new();
Expand Down

0 comments on commit 7140b58

Please sign in to comment.