[
https://issues.apache.org/jira/browse/CALCITE-2551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16611830#comment-16611830
]
pengzhiwei edited comment on CALCITE-2551 at 9/12/18 9:41 AM:
--------------------------------------------------------------
Thank [~julianhyde] for you review. Firstly,I have handled all forms of
case-when expression.I handle all the Then-Branches and then I handle the else
branch as the code shown below:
{code:java}
+884 if (childNode instanceof SqlCase) {
+885 SqlCase sqlCase = (SqlCase) childNode;
+886 SqlNodeList thenOperands = sqlCase.getThenOperands();
+887 for (int i = 0; i < thenOperands.size(); i++) { //Firstly, handle
all then-branches
+888 SqlNode newThenOperand = reg(scope,
+889 SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO,
thenOperands.get(i)));
newThenOperand = pushDownNotForIn(scope, newThenOperand);
thenOperands.set(i, newThenOperand);
}
SqlNode elseNode = sqlCase.getElseOperand();
if (elseNode != null) { //Secondly,handle else-branch
elseNode = reg(scope,
SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO, elseNode));
elseNode = pushDownNotForIn(scope, elseNode);
sqlCase.setOperand(3, elseNode);//elseNode is the thirty element in
the SqlCase
}
return sqlCase;
{code}
I agree with you that create a new SqlCase and refactoring the code using
switch.I will do the work later.
was (Author: pzw2018):
Thank [~julianhyde] for you review. Firstly,I have handled all forms of
case-when expression.I handle all the Then-Branches and then I handle the else
branch as the code shown below:
{code:java}
+884 if (childNode instanceof SqlCase) {
+885 SqlCase sqlCase = (SqlCase) childNode;
+886 SqlNodeList thenOperands = sqlCase.getThenOperands();
+887 for (int i = 0; i < thenOperands.size(); i++) { //Firstly, handle
all then-branches
+888 SqlNode newThenOperand = reg(scope,
+889 SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO,
thenOperands.get(i)));
newThenOperand = pushDownNotForIn(scope, newThenOperand);
thenOperands.set(i, newThenOperand);
}
SqlNode elseNode = sqlCase.getElseOperand();
if (elseNode != null) { //Secondly,handle else-branch
elseNode = reg(scope,
SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO, elseNode));
elseNode = pushDownNotForIn(scope, elseNode);
sqlCase.setOperand(3, elseNode);
}
return sqlCase;
{code}
I agree with you that create a new SqlCase and refactoring the code using
switch.I will do the work later.
> ClassCastException in SqlToRelConverter#pushDownNotForIn
> --------------------------------------------------------
>
> Key: CALCITE-2551
> URL: https://issues.apache.org/jira/browse/CALCITE-2551
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.17.0
> Reporter: pengzhiwei
> Assignee: Julian Hyde
> Priority: Critical
> Attachments: 屏幕快照 2018-09-12 上午11.12.11.png
>
>
> In the sql as follow:
> {code:java}
> select empno from emp
> where not case when true then deptno in (10,20) else true end
> {code}
> A ClassCastException was thrown out as follow:
> {code:java}
> java.lang.ClassCastException: org.apache.calcite.sql.fun.SqlCase cannot be
> cast to org.apache.calcite.sql.SqlBasicCall
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.pushDownNotForIn(SqlToRelConverter.java:987)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertWhere(SqlToRelConverter.java:1070)
> at
> {code}
> The reason for this issue is that the SqlToRelConverter#pushDownNotForIn
> method missing consideration
> for SqlCase as the code shown below:
> !屏幕快照 2018-09-12 上午11.12.11.png!
> I have made a PR for this issue which push not down through SqlCase.Anybody
> can have a check for me? Thanks!
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)