Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use // for unparsing DuckDB division operator #13509

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sevenannn
Copy link
Contributor

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?

  • Add division_operator method in Dialect trait to return the division operator for a specific Dialect
  • Use BinaryOperator::DuckIntegerDivide as the division operator for DuckDB Dialect
  • Use the division_operator of dialect to unparse Operator::Divide in Unparser op_to_sql method

Are these changes tested?

Yes

Are there any user-facing changes?

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

@Sevenannn Sevenannn marked this pull request as ready for review November 21, 2024 02:05
@github-actions github-actions bot added the sql SQL Planner label Nov 21, 2024
@alamb
Copy link
Contributor

alamb commented Nov 23, 2024

CI appears to be failing. Marking as a draft

@alamb alamb marked this pull request as draft November 23, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants