mihaibudiu commented on code in PR #4360:
URL: https://github.com/apache/calcite/pull/4360#discussion_r2073984864
##########
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:
if this function is specific to BigQuery, the function name should reflect
that.
I would not abbreviate BQ in the JavaDoc, why force people to try to guess
what it is when you can just write it down?
##########
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:
is this correct?
is trim(s, "\n") the same as trimming all whitespaces?
##########
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:
missing parens in comment
--
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]