You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Sevenannn (via GitHub)" <gi...@apache.org> on 2024/11/21 02:05:08 UTC

[PR] Use // for unparsing DuckDB division operator [datafusion]

Sevenannn opened a new pull request, #13509:
URL: https://github.com/apache/datafusion/pull/13509

   ## 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](https://github.com/user-attachments/assets/9af0c7c9-188c-48e0-9c04-1193218e7188)
   
   ## 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Use // for unparsing DuckDB division operator [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #13509:
URL: https://github.com/apache/datafusion/pull/13509#issuecomment-2508949732

   Thanks again @Sevenannn 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Use // for unparsing DuckDB division operator [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #13509:
URL: https://github.com/apache/datafusion/pull/13509#issuecomment-2495475836

   CI appears to be failing. Marking as a draft


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Use // for unparsing DuckDB division operator [datafusion]

Posted by "Sevenannn (via GitHub)" <gi...@apache.org>.
Sevenannn commented on PR #13509:
URL: https://github.com/apache/datafusion/pull/13509#issuecomment-2518692620

   Thanks for reviewing @alamb 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Use // for unparsing DuckDB division operator [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #13509:
URL: https://github.com/apache/datafusion/pull/13509


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org