You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2023/02/27 20:49:00 UTC

[jira] [Commented] (CALCITE-5547) Join using returns incorrect column names

    [ https://issues.apache.org/jira/browse/CALCITE-5547?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17694180#comment-17694180 ] 

Julian Hyde commented on CALCITE-5547:
--------------------------------------

Here's a more straightforward use case:
{noformat}
> !connect jdbc:calcite:model=core/src/test/resources/hsqldb-model.json sa sa
> select 2 as two, * from emp natural join dept;
+---------+-----+-------+--------+-----------+------+------------+---------+---------+------------+
|  COMM   | TWO | EMPNO | ENAME  |    JOB    | MGR  |  HIREDATE  |   SAL   | DEPTNO0 |   DNAME    |
+---------+-----+-------+--------+-----------+------+------------+---------+---------+------------+
| 20.00   | 2   | 7369  | SMITH  | CLERK     | 7902 | 1980-12-17 | 800.00  | 20      | RESEARCH   |
| 300.00  | 2   | 7499  | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 | 30      | SALES      |
| 500.00  | 2   | 7521  | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 | 30      | SALES      |
| 20.00   | 2   | 7566  | JONES  | MANAGER   | 7839 | 1981-02-04 | 2975.00 | 20      | RESEARCH   |
| 1400.00 | 2   | 7654  | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 30      | SALES      |
| 30.00   | 2   | 7698  | BLAKE  | MANAGER   | 7839 | 1981-01-05 | 2850.00 | 30      | SALES      |
| 10.00   | 2   | 7782  | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 | 10      | ACCOUNTING |
| 20.00   | 2   | 7788  | SCOTT  | ANALYST   | 7566 | 1987-04-19 | 3000.00 | 20      | RESEARCH   |
| 10.00   | 2   | 7839  | KING   | PRESIDENT | null | 1981-11-17 | 5000.00 | 10      | ACCOUNTING |
| 0.00    | 2   | 7844  | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 | 30      | SALES      |
| 20.00   | 2   | 7876  | ADAMS  | CLERK     | 7788 | 1987-05-23 | 1100.00 | 20      | RESEARCH   |
| 30.00   | 2   | 7900  | JAMES  | CLERK     | 7698 | 1981-12-03 | 950.00  | 30      | SALES      |
| 20.00   | 2   | 7902  | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 | 20      | RESEARCH   |
| 10.00   | 2   | 7934  | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 | 10      | ACCOUNTING |
+---------+-----+-------+--------+-----------+------+------------+---------+---------+------------+
14 rows selected (0.082 seconds)

> select *, 2 as two from emp natural join dept;
+--------+-------+--------+-----------+------+------------+---------+---------+------------+----------+-----+
| DEPTNO | EMPNO | ENAME  |    JOB    | MGR  |  HIREDATE  |   SAL   |  COMM   |   DNAME    |   LOC    | TWO |
+--------+-------+--------+-----------+------+------------+---------+---------+------------+----------+-----+
| 20     | 7369  | SMITH  | CLERK     | 7902 | 1980-12-17 | 800.00  | null    | RESEARCH   | DALLAS   | 2   |
| 30     | 7499  | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 | 300.00  | SALES      | CHICAGO  | 2   |
| 30     | 7521  | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 | 500.00  | SALES      | CHICAGO  | 2   |
| 20     | 7566  | JONES  | MANAGER   | 7839 | 1981-02-04 | 2975.00 | null    | RESEARCH   | DALLAS   | 2   |
| 30     | 7654  | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 | SALES      | CHICAGO  | 2   |
| 30     | 7698  | BLAKE  | MANAGER   | 7839 | 1981-01-05 | 2850.00 | null    | SALES      | CHICAGO  | 2   |
| 10     | 7782  | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 | null    | ACCOUNTING | NEW YORK | 2   |
| 20     | 7788  | SCOTT  | ANALYST   | 7566 | 1987-04-19 | 3000.00 | null    | RESEARCH   | DALLAS   | 2   |
| 10     | 7839  | KING   | PRESIDENT | null | 1981-11-17 | 5000.00 | null    | ACCOUNTING | NEW YORK | 2   |
| 30     | 7844  | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 | 0.00    | SALES      | CHICAGO  | 2   |
| 20     | 7876  | ADAMS  | CLERK     | 7788 | 1987-05-23 | 1100.00 | null    | RESEARCH   | DALLAS   | 2   |
| 30     | 7900  | JAMES  | CLERK     | 7698 | 1981-12-03 | 950.00  | null    | SALES      | CHICAGO  | 2   |
| 20     | 7902  | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 | null    | RESEARCH   | DALLAS   | 2   |
| 10     | 7934  | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 | null    | ACCOUNTING | NEW YORK | 2   |
+--------+-------+--------+-----------+------+------------+---------+---------+------------+----------+-----+
{noformat}
The second query has the correct number of columns. In the first query, the names and orderings of columns are messed up. I suspect that the expansion of "*" has clashed with the machinery trying to move the DEPTNO column to the front and make it unique.

> Join using returns incorrect column names
> -----------------------------------------
>
>                 Key: CALCITE-5547
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5547
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.33.0
>            Reporter: Sean Broeder
>            Priority: Major
>
> The query SELECT '' as \"xxx\", * 
> FROM (values (1, 4, 'one')) as t1(i ,j ,t )
> LEFT JOIN (values (1, -1)) as t2(i ,k )
> USING (i)
> returns columns (xxx, i, j, i0), 
> but should return columns (xxx, i, j, t, k)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)