Skip to content

Allow expr_to_sql unparsing with no quotes #10197

@phillipleblanc

Description

@phillipleblanc

Describe the bug

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.

To Reproduce

use datafusion_expr::{col, lit};
use datafusion_sql::unparser::Unparser;

let expr = col("a").gt(lit(4));
let spark_dialect = CustomDialect::new(None);
let unparser = Unparser::new(&spark_dialect);
let sql = unparser.expr_to_sql(&expr).unwrap();

assert_eq!(format!("{}", sql), "(\"a\" > 4)")

Expected behavior

use datafusion_expr::{col, lit};
use datafusion_sql::unparser::Unparser;

let expr = col("a").gt(lit(4));
let spark_dialect = CustomDialect::new(None);
let unparser = Unparser::new(&spark_dialect);
let sql = unparser.expr_to_sql(&expr).unwrap();

assert_eq!(format!("{}", sql), "(a > 4)")

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions