DonnyZone commented on a change in pull request #1714: [Calcite 3663] Support 
for TRIM function in BigQuery dialect
URL: https://github.com/apache/calcite/pull/1714#discussion_r362699302
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/sql/dialect/BigQuerySqlDialect.java
 ##########
 @@ -192,6 +197,37 @@ public BigQuerySqlDialect(SqlDialect.Context context) {
     }
   }
 
+  /**
+   * 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>.
+   */
+  private void unparseTrim(SqlWriter writer, SqlCall call, int leftPrec,
+      int rightPrec) {
+    assert call.operand(0) instanceof SqlLiteral : call.operand(0);
+    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 (!valueToTrim.toValue().matches("\\s+")) {
 
 Review comment:
   This `if `logic is different with that of `HiveSqlDialect`. Could you add 
doc for it?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to