juntaozhang commented on code in PR #4353:
URL: https://github.com/apache/calcite/pull/4353#discussion_r2070971386
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlCoalesceFunction.java:
##########
@@ -80,4 +93,40 @@ public SqlCoalesceFunction() {
assert call.getFunctionQuantifier() == null;
return SqlCase.createSwitched(pos, null, whenList, thenList, elseExpr);
}
+
+ @Override @NonNull public RelDataType inferReturnType(
+ SqlOperatorBinding opBinding) {
+ RelDataType returnType =
getReturnTypeInference().inferReturnType(opBinding);
+ if (returnType == null
+ && opBinding instanceof SqlCallBinding
+ && ((SqlCallBinding) opBinding).isTypeCoercionEnabled()) {
+ SqlCallBinding callBinding = (SqlCallBinding) opBinding;
+ List<RelDataType> argTypes = new ArrayList<>();
+ for (SqlNode operand : callBinding.operands()) {
+ RelDataType type = SqlTypeUtil.deriveType(callBinding, operand);
+ argTypes.add(type);
+ }
+ TypeCoercion typeCoercion = callBinding.getValidator().getTypeCoercion();
+ RelDataType commonType = typeCoercion.getWiderTypeFor(argTypes, true);
+ if (null != commonType) {
+ boolean coerced = typeCoercion.caseWhenCoercion(callBinding);
Review Comment:
I totally agree, and in ansi doc, `COALESCE` and `NULLIF` is a define in
`case abbreviation`[SQL 2023 standard, 6.12\<case
expression\>](https://www.iso.org/standard/76584.html).
How about add new API name it by `caseExpressionCoercion `?
```
<case expression> ::= <case abbreviation> | <case specification>
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]