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

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.

@@ -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.

👍

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
23 checks passed
@phillipleblanc phillipleblanc deleted the phillip/240423-unparser branch April 25, 2024 05:03
ccciudatu pushed a commit to hstack/arrow-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