[
https://issues.apache.org/jira/browse/CALCITE-7270?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18043275#comment-18043275
]
Mihai Budiu commented on CALCITE-7270:
--------------------------------------
I think that [~zabetak] is right, the quest to precisely emulate the operators
present in all SQL dialects is probably not worthwhile pursuing: it will only
increase the code complexity without clear gains. Each project that relies on
Calcite should introduce custom operators and implement the custom semantics in
their runtime.
This is a bit more difficult for "standard" operators like division, which have
fixed typing rules in Calcite. From this discussion the conclusion is that
there isn't much standard about the behavior division in SQL, except that it
exists in some form in all dialects. This issue was originated by CALCITE-7145,
which noticed that nullability for division is not the same in all dialects. So
my goal was initially to provide an example division operator which has
different nullability than the existing one, which could provide a blueprint
for project that need such an operator. Unfortunately, this new operator did
not behave like any of the division operators in any of the dialects either...
I can see two reasonable solutions: (1) just drop this issue and PR and provide
guidance for people who need custom division operators; (2) add a new nullable
division operator as a blueprint, but with the understanding that it is not
sufficient to make Calcite behave like any of the other SQL dialects.
> Add support for the DuckDB integer division operator //
> -------------------------------------------------------
>
> 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
> Labels: pull-request-available
>
> 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)