[
https://issues.apache.org/jira/browse/CALCITE-7264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18035528#comment-18035528
]
Thomas Rebele commented on CALCITE-7264:
----------------------------------------
There is some code in RexSimplify.SafeRexVisitor to determine the safeness of
RexCalls. It has some [custom
code|https://github.com/apache/calcite/blob/8b5c17e51e0c9c3f8e3db17c8d449e67e4e2974a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L1551]
for handling division. For standard SQL the division is safe except if the
divisor may be zero. Other DBMS might want to change that behavior. E.g., in
Hive division is always safe, as x/0 evaluates to NULL. So the dialect needs a
way to override the safeness in RexSimplify. It basically aims to make it
possible to provide a custom SafeRexVisitor.
> New API for determining if an operator may throw
> ------------------------------------------------
>
> Key: CALCITE-7264
> URL: https://issues.apache.org/jira/browse/CALCITE-7264
> Project: Calcite
> Issue Type: New Feature
> Reporter: Thomas Rebele
> Priority: Major
>
> The SQL standard defines that 1/0 throws an exception. Calcite follows the
> standard here. However, some projects that use Calcite (e.g., Hive) define
> the result of 1/0 as NULL. This may lead to different results in RexSimplify:
> E.g., IS NULL(1/0) would throw for the SQL standard semantics, but would
> return TRUE for the Hive semantics.
> RexSimplify handles this with a concept called "safe" defined in
> [RexSimplify#isSafeExpression|https://github.com/apache/calcite/blob/34989b0ed7793cedf713c2f159de6247a730458c/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L1631].
> The safe operators are defined in
> [RexSimplify.SafeRexVisitor|https://github.com/apache/calcite/blob/34989b0ed7793cedf713c2f159de6247a730458c/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L1490].
> The goal of this ticket is to make the behavior configurable. The API would
> need to provide a method that accepts at least RexCall nodes. Maybe a more
> general approach is favorable, e.g., {{{}isSafeExpression(RexNode r){}}}.
> This ticket aims to provide a refinement of
> {{{}org.apache.calcite.sql.SqlOperator#isSafeOperator{}}}, which only takes
> the operator but not the arguments into account. To be discussed whether the
> new API replaces or supplements {{{}SqlOperator#isSafeOperator{}}}.
> The safeness information would be useful for other parts of the code as well,
> e.g., CALCITE-5315.
> See the related discussions:
> *
> https://issues.apache.org/jira/browse/CALCITE-7145?focusedCommentId=18016030#comment-18016030
> * [http://lists.apache.org/thread/cp7h28k1yfxv421q12y1wopbwgrzdzrx]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)