Details
Description
This query:
SELECT count(*) FROM (SELECT count(emp.empno) `Count Emp`, dept.dname `Department Name` FROM Calcite.emp emp JOIN Calcite.dept dept ON emp.deptno = dept.deptno JOIN Calcite.salgrade salgrade ON emp.comm = salgrade.hisal WHERE dept.dname LIKE '%O%' GROUP BY emp.deptno, dept.dname)
generates a ClassCastException: "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcJoin cannot be cast to org.apache.calcite.adapter.enumerable.EnumerableRel".
The plan is the following:
[TABLE, #ID {PLAN=EnumerableAggregate(group=[{}], EXPR$0=[COUNT()]) EnumerableAggregate(group=[{2, 4}]) JdbcJoin(condition=[=($1, $0)], joinType=[inner]) JdbcProject(hisal=[$2]) JdbcTableScan(table=[[Calcite, salgrade]]) JdbcJoin(condition=[=($1, $2)], joinType=[inner]) JdbcProject(comm=[$6], deptno=[$7]) JdbcTableScan(table=[[Calcite, emp]]) JdbcProject(deptno=[$0], dname=[$1]) JdbcFilter(condition=[LIKE($1, '%O%')]) JdbcTableScan(table=[[Calcite, dept]]) , }]
Runnable test:
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-1382">[CALCITE-1382] * ClassCastException in JDBC adapter</a>. */ @org.junit.Test public void testJoinPlan3() throws DataSourceManagerException { final String sql = "SELECT count(*) FROM (SELECT count(emp.empno) `Count Emp`, dept.dname `Department Name`\n" + "FROM emp emp JOIN dept dept ON emp.deptno = dept.deptno\n" + "JOIN salgrade salgrade ON emp.comm = salgrade.hisal\n" + "WHERE dept.dname LIKE '%A%' GROUP BY emp.deptno, dept.dname)"; final String expected = "SELECT COUNT(*) FROM (\n" + "SELECT count(\"emp\".empno) AS \"Count Emp\", \"dept\".dname AS \"Department Name\"\n" + "FROM emp AS \"emp\"\n" + "INNER JOIN (\n" + "SELECT deptno, dname\n" + "FROM dept\n" + "WHERE dname LIKE '%A%'\n" + ") AS \"dept\" ON \"emp\".deptno = \"dept\".deptno\n" + "INNER JOIN (\n" + "SELECT hisal \n" + "FROM salgrade \n" + ") AS \"salgrade\" ON \"emp\".comm = \"salgrade\".hisal " + "GROUP BY \"emp\".deptno, \"dept\".dname" + ") AS \"t\""; sql(sql) .schema(CalciteAssert.SchemaSpec.JDBC_SCOTT) .ok(expected); }
Attachments
Issue Links
- is duplicated by
-
CALCITE-2015 Planner generates incompatible plan
- Open