xuzifu666 commented on code in PR #4360:
URL: https://github.com/apache/calcite/pull/4360#discussion_r2076565601


##########
core/src/main/java/org/apache/calcite/util/RelToSqlConverterUtil.java:
##########
@@ -68,6 +70,44 @@ public static void unparseHiveTrim(
     }
   }
 
+  /**
+   * For usage of TRIM(LEADING 'A' FROM 'ABCA') convert to TRIM, LTRIM and 
RTRIM,
+   * can refer to BigQuery and Presto documents:
+   * <a 
href="https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#trim";>
+   * BigQuery Trim Function</a>,
+   * <a 
href="https://prestodb.io/docs/current/functions/string.html#trim-string-varchar";>
+   * Presto Trim Function</a>.
+   */
+  public static void unparseTrimLR(SqlWriter writer, SqlCall call, int 
leftPrec,
+      int rightPrec) {
+    final String operatorName;
+    SqlLiteral trimFlag = call.operand(0);
+    SqlLiteral valueToTrim = call.operand(1);
+    switch (trimFlag.getValueAs(SqlTrimFunction.Flag.class)) {
+    case LEADING:
+      operatorName = "LTRIM";
+      break;
+    case TRAILING:
+      operatorName = "RTRIM";
+      break;
+    default:
+      operatorName = call.getOperator().getName();
+      break;
+    }
+    final SqlWriter.Frame trimFrame = writer.startFunCall(operatorName);
+    call.operand(2).unparse(writer, leftPrec, rightPrec);
+
+    // If the trimmed character is a non-space character, add it to the target 
SQL.
+    // eg: TRIM(BOTH 'A' from 'ABCD')
+    // Output Query: TRIM('ABC', 'A')
+    String value = requireNonNull(valueToTrim.toValue(), 
"valueToTrim.toValue()");
+    if (!StringUtils.isWhitespace(value)) {

Review Comment:
   Make sense, I agree with it and had changed it, thanks @mihaibudiu 



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