You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mihai Budiu (Jira)" <ji...@apache.org> on 2025/11/27 18:37:00 UTC
[jira] [Commented] (CALCITE-7270) Add support for a DIVIDE_0_NULL operation
[ https://issues.apache.org/jira/browse/CALCITE-7270?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18041146#comment-18041146 ]
Mihai Budiu commented on CALCITE-7270:
--------------------------------------
I have renamed the issue to introduce a DIVIDE_0_NULL operator.
The implementation is trickier than I expected, because DIVIDE has to be replaced by DIVIDE_0_NULL before type inference, because the two operators have different type inference rules.
I think there should exist a general opportunity to rewrite expressions before validation – this is just one instance of a possible transformation.
> Add support for a DIVIDE_0_NULL operation
> -----------------------------------------
>
> Key: CALCITE-7270
> URL: https://issues.apache.org/jira/browse/CALCITE-7270
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.41.0
> Reporter: Mihai Budiu
> Priority: Minor
>
> SQL dialects treat DIVISION in different ways: in some dialects division by 0 produces an exception, while in other dialects (e.q. sqlite) it produces NULL.
> These are really two different operators with the same name. I think they should be represented by different operations in the IR: e.g., DIVIDE and SAFE_DIVIDE.
> This is reminiscent to the CHECKED arithmetic operations introduced in [CALCITE-6685], and the solution could be similar: in that issue whether an ADD operation is checked or unchecked is a property of SqlConformance. Similarly, we could add a boolean flag to SqlConformance indicating whether division is safe or not and a visitor that will rewrite DIVIDE to SAFE_DIVIDE when necessary.
> Spawn from [CALCITE-7145]
> I am happy to assign this to myself if people agree.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)