Skip to content

Conversation

@phillipleblanc
Copy link
Contributor

Which issue does this PR close?

Closes #10197

Rationale for this change

I'm using the Unparser.expr_to_sql function to translate a DataFusion Expr into an expression for Spark Connect. Unlike most SQL engines, Spark doesn't like quoting the column identifiers. I want to be able to generate an expression like a > 4 but currently I can only get "a" > 4

I believe this might be useful beyond Spark for other database systems that can handle unquoted column identifiers.

What changes are included in this PR?

Changes the DefaultDialect for the Unparser to return Some('"') for identifier_quote_style, and then changes the usage of identifier_quote_style to not unwrap to " if it is None, but pass the Option through.

Are these changes tested?

Yes

Are there any user-facing changes?

No, this change is backwards-compatible.

}

#[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.

👍

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks good to me -- thanks @phillipleblanc

Copy link
Contributor

@devinjdangelo devinjdangelo left a comment

Choose a reason for hiding this comment

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

Thank you for this enhancement @phillipleblanc ! Makes sense to me.

@alamb alamb merged commit 0689515 into apache:main Apr 23, 2024
@phillipleblanc phillipleblanc deleted the phillip/240423-unparser branch April 25, 2024 05:03
ccciudatu pushed a commit to hstack/datafusion that referenced this pull request Apr 26, 2024
* Allow expr_to_sql unparsing with no quotes

* Add test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow expr_to_sql unparsing with no quotes

3 participants