Use // for unparsing DuckDB division operator #13509
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.