mihaibudiu commented on code in PR #4439:
URL: https://github.com/apache/calcite/pull/4439#discussion_r2166997571
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/AbstractTypeCoercion.java:
##########
@@ -213,7 +214,11 @@ protected boolean coerceColumnType(
}
RelDataType targetType3 = syncAttributes(validator.deriveType(scope,
node), targetType);
SqlNode node3 = castTo(node, targetType3);
- if (node.getKind() == SqlKind.IDENTIFIER) {
+ // Although this function is called coerceColumnType, it is not always
invoked on a "column".
Review Comment:
The original change would rewrite an expression like CAST(S.A as T) to
CAST(S.A as T) AS A, preserving the original column name. This should be only
done if this CAST is a (toplevel) item in a SELECT, and this is what the fix
does.
This will work for any SELECT, nested or unnested.
Notice that this shows up in the SqlNode query rewritten by the validator.
The bug was hard to reproduce because SqlToRelConverter was happy to take
the malformed Sql and it would generate correct code out of it.
--
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]