Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5934

calcite avatica calculation error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • None
    • None
    • None
    • None

    Description

      Here's the raw data.

      > +-------+--------+-----------+------+------------+---------+---------+--------+
      > | EMPNO | ENAME  | JOB       | MGR  | HIREDATE   | SAL     | COMM    | DEPTNO |
      > +-------+--------+-----------+------+------------+---------+---------+--------+
      > |  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800.00 |         |     20 |
      > |  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30 |
      > |  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30 |
      > |  7566 | JONES  | MANAGER   | 7839 | 1981-02-04 | 2975.00 |         |     20 |
      > |  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30 |
      > |  7698 | BLAKE  | MANAGER   | 7839 | 1981-01-05 | 2850.00 |         |     30 |
      > |  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 |         |     10 |
      > |  7788 | SCOTT  | ANALYST   | 7566 | 1987-04-19 | 3000.00 |         |     20 |
      > |  7839 | KING   | PRESIDENT |      | 1981-11-17 | 5000.00 |         |     10 |
      > |  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30 |
      > |  7876 | ADAMS  | CLERK     | 7788 | 1987-05-23 | 1100.00 |         |     20 |
      > |  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |         |     30 |
      > |  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 |         |     20 |
      > |  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |         |     10 |
      > +-------+--------+-----------+------+------------+---------+---------+--------+ 

       

      select e1.*
      from "scott".emp e1
      inner join "scott".emp e2 on e1.COMM=e2.COMM and ((e1.COMM is null) = (e2.COMM is null))
      WHERE e1.MGR is null;
      +-------+-------+-----------+-----+------------+---------+------+--------+
      | EMPNO | ENAME | JOB       | MGR | HIREDATE   | SAL     | COMM | DEPTNO |
      +-------+-------+-----------+-----+------------+---------+------+--------+
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      |  7839 | KING  | PRESIDENT |     | 1981-11-17 | 5000.00 |      |     10 |
      +-------+-------+-----------+-----+------------+---------+------+--------+

      The above sql executes the above result is wrong, 'MGR is null' has only one line of data, and the 'comm' of this line is also null, the correct result is to return empty data.

      But the following sql execution results are correct.

      select e1.*
      from "scott".emp e1
      inner join "scott".emp e2 on e1.COMM=e2.COMM   <-- Here reduce the condition 
      WHERE e1.MGR is null; 
      +-------+-------+-----+-----+----------+-----+------+--------+
      | EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
      +-------+-------+-----+-----+----------+-----+------+--------+
      +-------+-------+-----+-----+----------+-----+------+--------+

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              leepb libopeng
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: