apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
6.37k stars 1.2k forks source link

Fix Binary & Binary View Unparsing #13427

Closed Sevenannn closed 6 days ago

Sevenannn commented 1 week ago

Which issue does this PR close?

N/A

Rationale for this change

Datafusion enforces an eager cast of value to Binary / BinaryView value in the logical plan where a comparison with binary value is presented. For example, in the following plan

Filter: value = CAST(Utf8("binary_value") AS Binary However, when using unparser to convert the plan back to sql, where the sql will be sent to various query engine (e.g. DuckDB). the cast is not needed for the value, in the example above the value "binary_value", since the raw value can be directly used in SQL engines without casting to an engine specific dictionary type. Therefore, the plan can simply be rewritten into where value = 'binary_value'

What changes are included in this PR?

Are these changes tested?

Yes

Are there any user-facing changes?

No

alamb commented 6 days ago

🚀

alamb commented 6 days ago

Thanks @Sevenannn @phillipleblanc and @Jeadie