ILuffZhe commented on code in PR #4462:
URL: https://github.com/apache/calcite/pull/4462#discussion_r2194740220
##########
core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java:
##########
@@ -1952,10 +1960,32 @@ private static class TrimConvertlet implements
SqlRexConvertlet {
@Override public RexNode convertCall(SqlRexContext cx, SqlCall call) {
final RexBuilder rexBuilder = cx.getRexBuilder();
+ final SqlParserPos pos = call.getParserPosition();
+ final RelDataTypeFactory typeFactory =
+ cx.getValidator().getTypeFactory();
final RexNode operand =
cx.convertExpression(call.getOperandList().get(0));
- return rexBuilder.makeCall(call.getParserPosition(),
SqlStdOperatorTable.TRIM,
- rexBuilder.makeFlag(flag), rexBuilder.makeLiteral(" "), operand);
+ RexNode rawCall =
+ rexBuilder.makeCall(pos, SqlStdOperatorTable.TRIM,
rexBuilder.makeFlag(flag),
+ rexBuilder.makeLiteral(" "), operand);
+ SqlConformance conformance = cx.getValidator().config().conformance();
+ if (conformance.emptyStringIsNull()) {
+ // Translate
+ // LTRIM/RTRIM(operand0[,operand1,...])
+ //
+ // to the following if we want Oracle semantics
Review Comment:
> Here, we convert LTRIM(A) to the following expression: CASE WHEN LTRIM(A)
= '' THEN NULL ELSE LTRIM(A) END. LTRIM(A) is calculated multiple times. If
LTRIM(A) is a non-deterministic function, it may lead to an uncontrolled final
result.
Nondeterministic is not allowed during runtime, I've added some tests and
throw exception when it occurs.
--
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]