ILuffZhe commented on code in PR #4462:
URL: https://github.com/apache/calcite/pull/4462#discussion_r2194741064


##########
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
+        //   CASE
+        //     WHEN LTRIM/RTRIM(operand0[,operand1,...]) = ''
+        //     THEN NULL
+        //     ELSE LTRIM/RTRIM(operand0[,operand1,...])
+        //   END
+        return rexBuilder.makeCall(pos, SqlStdOperatorTable.CASE,
+            rexBuilder.makeCall(pos, SqlStdOperatorTable.EQUALS, rawCall,
+                rexBuilder.makeLiteral("")),
+                
rexBuilder.makeNullLiteral(typeFactory.createSqlType(SqlTypeName.NULL)),

Review Comment:
   Done, NULL type now is consistent with call's.



-- 
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]

Reply via email to