Skip to content

Commit

Permalink
Allow expr_to_sql unparsing with no quotes (apache#10198)
Browse files Browse the repository at this point in the history
* Allow expr_to_sql unparsing with no quotes

* Add test
  • Loading branch information
phillipleblanc authored Apr 23, 2024
1 parent 767bbca commit 0689515
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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<()> {
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(())
}
}

0 comments on commit 0689515

Please sign in to comment.