DonnyZone commented on a change in pull request #1724: [CALCITE-3675] SQL to
Rel conversion is broken for coalesce on nullable field
URL: https://github.com/apache/calcite/pull/1724#discussion_r363583754
##########
File path: core/src/main/java/org/apache/calcite/sql/fun/SqlCaseOperator.java
##########
@@ -293,16 +294,26 @@ private RelDataType inferTypeFromValidator(
return ret;
}
- private RelDataType inferTypeFromOperands(
- RelDataTypeFactory typeFactory,
- List<RelDataType> argTypes) {
+ private RelDataType inferTypeFromOperands(SqlOperatorBinding opBinding) {
+ final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+ final List<RelDataType> argTypes = opBinding.collectOperandTypes();
assert (argTypes.size() % 2) == 1 : "odd number of arguments expected: "
+ argTypes.size();
assert argTypes.size() > 1 : "CASE must have more than 1 argument. Given "
+ argTypes.size() + ", " + argTypes;
List<RelDataType> thenTypes = new ArrayList<>();
for (int j = 1; j < (argTypes.size() - 1); j += 2) {
- thenTypes.add(argTypes.get(j));
+ RelDataType argType = argTypes.get(j);
+ if (opBinding instanceof RexCallBinding) {
+ RexNode whenNode = ((RexCallBinding) opBinding).getOperands().get(j -
1);
+ RexNode thenNode = ((RexCallBinding) opBinding).getOperands().get(j);
+ if (whenNode.getKind() == SqlKind.IS_NOT_NULL && argType.isNullable())
{
+ if (((RexCall) whenNode).getOperands().get(0).equals(thenNode)) {
Review comment:
Thanks for review!
> It might be better if we put the if condition out of the loop.
It's might be difficult. Only when SqlKind is `IS_NOT_NULL`, we convert it
to `RexCall`. Or can we combine these two `if` conditions?
> Also extract ((RexCallBinding) opBinding) as a variable to avoid casting
twice.
Done.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services