Uploaded image for project: 'Tajo'
  1. Tajo
  2. TAJO-979

Dividing float value by zero should throw "Divide by zero Exception"

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.9.0
    • Component/s: None
    • Labels:
      None

      Description

      See the title. Currently Tajo returns "Infinity".

      This is a result of Tajo.

      default> select 10.0/0;
      ?divide
      -------------------------------
      Infinity
      (1 rows, 0.003 sec, 0 B selected)
      default> select 10/0;
      ERROR: / by zero
      

      This is a result of Postgresql.

      babokim=# select 10.0/0.0;
      ERROR:  division by zero
      babokim=# select 10.0/0;
      ERROR:  division by zero
      

        Activity

        Hide
        hyunsik Hyunsik Choi added a comment - - edited

        In my view, most of uses may not want to abort queries which faces 'divide by zero'. Of course, it can be avoided if users use conditional expression like CASE WHEN. However, It does not make sense to force users to make use of some condition expression for all divide expressions. So, 'divide by zero' exception should return NULL.

        In addition, we can show some warning about how many 'divide by zero' occurs. Also, we could add some session variable to control query behavior to abort or ignore.

        Show
        hyunsik Hyunsik Choi added a comment - - edited In my view, most of uses may not want to abort queries which faces 'divide by zero'. Of course, it can be avoided if users use conditional expression like CASE WHEN. However, It does not make sense to force users to make use of some condition expression for all divide expressions. So, 'divide by zero' exception should return NULL. In addition, we can show some warning about how many 'divide by zero' occurs. Also, we could add some session variable to control query behavior to abort or ignore.
        Hide
        hjkim Hyoungjun Kim added a comment -

        Datum and Function object should be accessible to TaskAttemptContext object for reporting how many 'divide by zero' occurs. For this I I propose that a Task object set TaskAttemptContext object in a ThreadLocal and Datum and Function object uses TaskAttemptContext from ThreadLocal.
        If Datum and Function object can access TaskAttemptContext object, Throwing 'divide by zero' exception or returning NullDatum is selectable by user's session property.

        Show
        hjkim Hyoungjun Kim added a comment - Datum and Function object should be accessible to TaskAttemptContext object for reporting how many 'divide by zero' occurs. For this I I propose that a Task object set TaskAttemptContext object in a ThreadLocal and Datum and Function object uses TaskAttemptContext from ThreadLocal. If Datum and Function object can access TaskAttemptContext object, Throwing 'divide by zero' exception or returning NullDatum is selectable by user's session property.
        Hide
        hyunsik Hyunsik Choi added a comment -

        You are right. I didn't expect the limitation in the current design of TaskAttemptContext, Datum, and EvalNode. Currently, it is hard to implement controllable behaviors of expression evaluations. Your suggestion using ThreadLocal looks reasonable. BTW, it would be nice if we have more time to think about the approach.

        Now, If you are ok, we can choose the approach to return just NULL when divided by zero exception occurs. Later, we can do controllable behaviors in additional issues. As far as I know, Hive also returns NULL in the case. So, this choice will satisfy many users who are familiar with Hive and Impala.

        Show
        hyunsik Hyunsik Choi added a comment - You are right. I didn't expect the limitation in the current design of TaskAttemptContext, Datum, and EvalNode. Currently, it is hard to implement controllable behaviors of expression evaluations. Your suggestion using ThreadLocal looks reasonable. BTW, it would be nice if we have more time to think about the approach. Now, If you are ok, we can choose the approach to return just NULL when divided by zero exception occurs. Later, we can do controllable behaviors in additional issues. As far as I know, Hive also returns NULL in the case. So, this choice will satisfy many users who are familiar with Hive and Impala.
        Hide
        githubbot ASF GitHub Bot added a comment -

        GitHub user babokim opened a pull request:

        https://github.com/apache/tajo/pull/100

        TAJO-979: Dividing float value by zero should throw "Divide by zero Exception"

        You can merge this pull request into a Git repository by running:

        $ git pull https://github.com/babokim/tajo TAJO-979

        Alternatively you can review and apply these changes as the patch at:

        https://github.com/apache/tajo/pull/100.patch

        To close this pull request, make a commit to your master/trunk branch
        with (at least) the following in the commit message:

        This closes #100


        commit fe26b88ceeb30b11fd8b0e222a602de504a8f7cf
        Author: 김형준 <babokim@babokim-mbp.server.gruter.com>
        Date: 2014-08-01T03:23:19Z

        TAJO-979: Dividing float value by zero should throw "Divide by zero Exception"


        Show
        githubbot ASF GitHub Bot added a comment - GitHub user babokim opened a pull request: https://github.com/apache/tajo/pull/100 TAJO-979 : Dividing float value by zero should throw "Divide by zero Exception" You can merge this pull request into a Git repository by running: $ git pull https://github.com/babokim/tajo TAJO-979 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/tajo/pull/100.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #100 commit fe26b88ceeb30b11fd8b0e222a602de504a8f7cf Author: 김형준 <babokim@babokim-mbp.server.gruter.com> Date: 2014-08-01T03:23:19Z TAJO-979 : Dividing float value by zero should throw "Divide by zero Exception"
        Hide
        githubbot ASF GitHub Bot added a comment -

        Github user hyunsik commented on the pull request:

        https://github.com/apache/tajo/pull/100#issuecomment-50860041

        +1
        The patch looks good to me.

        Show
        githubbot ASF GitHub Bot added a comment - Github user hyunsik commented on the pull request: https://github.com/apache/tajo/pull/100#issuecomment-50860041 +1 The patch looks good to me.
        Hide
        hyunsik Hyunsik Choi added a comment -

        committed it to master branch.

        Show
        hyunsik Hyunsik Choi added a comment - committed it to master branch.
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Tajo-master-build #321 (See https://builds.apache.org/job/Tajo-master-build/321/)
        TAJO-979: Dividing float value by zero should throw "Divide by zero Exception" (Hyoungjun Kim via hyunsik) (hyunsik: rev 072b5a3ad2f21189ab3bdf159e666086957401d6)

        • tajo-common/src/main/java/org/apache/tajo/datum/Int4Datum.java
        • tajo-common/src/main/java/org/apache/tajo/datum/Float4Datum.java
        • tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
        • tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
        • tajo-common/src/main/java/org/apache/tajo/datum/Int8Datum.java
        • tajo-common/src/test/java/org/apache/tajo/datum/TestArithmeticOperator.java
        • tajo-common/src/main/java/org/apache/tajo/datum/IntervalDatum.java
        • tajo-common/src/main/java/org/apache/tajo/datum/Int2Datum.java
        • CHANGES
        • tajo-common/src/main/java/org/apache/tajo/datum/Float8Datum.java
        • tajo-common/src/main/java/org/apache/tajo/datum/Datum.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Tajo-master-build #321 (See https://builds.apache.org/job/Tajo-master-build/321/ ) TAJO-979 : Dividing float value by zero should throw "Divide by zero Exception" (Hyoungjun Kim via hyunsik) (hyunsik: rev 072b5a3ad2f21189ab3bdf159e666086957401d6) tajo-common/src/main/java/org/apache/tajo/datum/Int4Datum.java tajo-common/src/main/java/org/apache/tajo/datum/Float4Datum.java tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java tajo-common/src/main/java/org/apache/tajo/datum/Int8Datum.java tajo-common/src/test/java/org/apache/tajo/datum/TestArithmeticOperator.java tajo-common/src/main/java/org/apache/tajo/datum/IntervalDatum.java tajo-common/src/main/java/org/apache/tajo/datum/Int2Datum.java CHANGES tajo-common/src/main/java/org/apache/tajo/datum/Float8Datum.java tajo-common/src/main/java/org/apache/tajo/datum/Datum.java
        Hide
        githubbot ASF GitHub Bot added a comment -

        Github user asfgit closed the pull request at:

        https://github.com/apache/tajo/pull/100

        Show
        githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/tajo/pull/100

          People

          • Assignee:
            hjkim Hyoungjun Kim
            Reporter:
            hjkim Hyoungjun Kim
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development