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

feat(core): use MySQL interval style for output format #961

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 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