Shuo Cheng created CALCITE-4118:
-----------------------------------
Summary: RexSimplify might remove CAST from RexNode incorrectly
Key: CALCITE-4118
URL: https://issues.apache.org/jira/browse/CALCITE-4118
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.23.0
Reporter: Shuo Cheng
Fix For: 1.24.0
{code:java}
@Test void testCastError() {
final String sql = "select cast(cast(count(distinct empno) as varchar(65536))
as varbinary)\n"
+ "from emp group by deptno";
sql(sql).ok();
}
{code}
Consider the above test case, we get the following plan after SqlToRel.
{code:java}
LogicalProject(EXPR$0=[CAST($1):VARBINARY NOT NULL])
LogicalAggregate(group=[{0}], agg#0=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code}
As it is shown, `cast(* as varchar)` is removed (by RexSimplify#SimplifyCast),
which is obviously wrong, because BIGINT can not cast to VARBINARY.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)