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

Allow expr_to_sql unparsing with no quotes #10198

Merged
merged 2 commits into from
Apr 23, 2024
Merged
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 datafusion/sql/src/unparser/dialect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct DefaultDialect {}

impl Dialect for DefaultDialect {
fn identifier_quote_style(&self) -> Option<char> {
None
Some('"')
}
}

Expand Down
18 changes: 17 additions & 1 deletion datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl Unparser<'_> {
pub(super) fn new_ident(&self, str: String) -> ast::Ident {
ast::Ident {
value: str,
quote_style: Some(self.dialect.identifier_quote_style().unwrap_or('"')),
quote_style: self.dialect.identifier_quote_style(),
}
}

Expand Down Expand Up @@ -965,4 +965,20 @@ mod tests {

Ok(())
}

#[test]
fn custom_dialect_none() -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let dialect = CustomDialect::new(None);
let unparser = Unparser::new(&dialect);

let expr = col("a").gt(lit(4));
let ast = unparser.expr_to_sql(&expr)?;

let actual = format!("{}", ast);

let expected = r#"(a > 4)"#;
assert_eq!(actual, expected);

Ok(())
}
}