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.
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, theOperator::Divide
needs to be unparsed toBinaryOperator::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/
operatorWhat changes are included in this PR?
division_operator
method in Dialect trait to return the division operator for a specific DialectBinaryOperator::DuckIntegerDivide
as the division operator for DuckDB Dialectdivision_operator
of dialect to unparseOperator::Divide
in Unparserop_to_sql
methodAre these changes tested?
Yes
Are there any user-facing changes?
All division will be unparsed to
//
instead of/
for DuckDB Dialect.