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


##########
core/src/main/java/org/apache/calcite/util/RelToSqlConverterUtil.java:
##########
@@ -68,6 +68,43 @@ public static void unparseHiveTrim(
     }
   }
 
+  /**
+   * For usage of TRIM, LTRIM and RTRIM in BQ see
+   * <a 
href="https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#trim";>
+   * BQ Trim Function</a>,
+   * <a 
href="https://prestodb.io/docs/current/functions/string.html#trim-string-varchar";>
+   * Presto Trim Function</a>.
+   */
+  public static void unparseTrim(SqlWriter writer, SqlCall call, int leftPrec,

Review Comment:
   Yes,make sense, this method not only used for BigQuery,can be used by any 
need convert trim(both from) to trim/ltrim/rtrim functions, so method name may 
not need to be changed, I had updated the bbreviate BQ in JavaDoc.Thanks for 
suggestion @mihaibudiu 



##########
core/src/main/java/org/apache/calcite/util/RelToSqlConverterUtil.java:
##########
@@ -68,6 +68,43 @@ public static void unparseHiveTrim(
     }
   }
 
+  /**
+   * For usage of TRIM, LTRIM and RTRIM in BQ see
+   * <a 
href="https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#trim";>
+   * BQ Trim Function</a>,
+   * <a 
href="https://prestodb.io/docs/current/functions/string.html#trim-string-varchar";>
+   * Presto Trim Function</a>.
+   */
+  public static void unparseTrim(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'

Review Comment:
   Done.



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