danny0405 commented on a change in pull request #1437: [CALCITE-3318]
Preserving CAST of STRING operands in comparison operator
URL: https://github.com/apache/calcite/pull/1437#discussion_r335374694
##########
File path:
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
##########
@@ -305,21 +305,19 @@ private static RexNode stripCastFromString(RexNode node)
{
final RexNode o1 = call.operands.get(1);
if (o0.getKind() == SqlKind.CAST
&& o1.getKind() != SqlKind.CAST) {
- final RexNode o0b = ((RexCall) o0).getOperands().get(0);
- switch (o0b.getType().getSqlTypeName()) {
- case CHAR:
- case VARCHAR:
- return call.clone(call.getType(), ImmutableList.of(o0b, o1));
+ if (dialect.castRequiredForStringOperand((RexCall) o0)) {
+ return node;
}
+ final RexNode o0b = ((RexCall) o0).getOperands().get(0);
+ return call.clone(call.getType(), ImmutableList.of(o0b, o1));
}
if (o1.getKind() == SqlKind.CAST
&& o0.getKind() != SqlKind.CAST) {
- final RexNode o1b = ((RexCall) o1).getOperands().get(0);
- switch (o1b.getType().getSqlTypeName()) {
- case CHAR:
- case VARCHAR:
- return call.clone(call.getType(), ImmutableList.of(o0, o1b));
+ if (dialect.castRequiredForStringOperand((RexCall) o1)) {
+ return node;
}
+ final RexNode o1b = ((RexCall) o1).getOperands().get(0);
+ return call.clone(call.getType(), ImmutableList.of(o0, o1b));
Review comment:
The name `castRequiredForStringOperand` is confusing because in your patch
it only works for `EQUALS` and `IS_NOT_DISTINCT_FROM`, can we rename it to
`supportsImplicitTypeCoercion` ? Which i think can be reused by many sql
contexts that can have implicit type coercion.
----------------------------------------------------------------
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