apache / datafusion

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

Use // for unparsing DuckDB division operator #13509

Open Sevenannn opened 1 day ago

Sevenannn commented 1 day ago

Which issue does this PR close?

N/A

Rationale for this change

In Datafusion, the / operator is semantically integer division. When both a & b are integer, a/b result is a integer rounded down to 0. When unparsing Datafusion logical plan to DuckDB SQL query, the query needs to follow the same semantic meaning of integer division. Therefore, the Operator::Divide needs to be unparsed to BinaryOperator::DuckIntegerDivide, which is // in DuckDB.

Reference to DuckDB division operator: https://duckdb.org/docs/sql/functions/numeric.html#division-and-modulo-operators. The // operator has the same semantic meaning to Datafusion / operator image

What changes are included in this PR?

Are these changes tested?

Yes

Are there any user-facing changes?

All division will be unparsed to // instead of / for DuckDB Dialect.