xuzifu666 commented on code in PR #4360:
URL: https://github.com/apache/calcite/pull/4360#discussion_r2074497816
##########
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'
+ // Output Query: TRIM('ABC', 'A')
+ String value = requireNonNull(valueToTrim.toValue(),
"valueToTrim.toValue()");
+ if (!value.matches("\\s+")) {
Review Comment:
Yes,you are right,maybe we can use StringUtils.isWhitespace(value) to
instead of it? which can only match write spaces. @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]