You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2022/05/24 05:39:06 UTC

[GitHub] [calcite] wojustme commented on a diff in pull request #2812: [CALCITE-5163] MysqlSqlDialect support to unparse LISTAGG aggregate function

wojustme commented on code in PR #2812:
URL: https://github.com/apache/calcite/pull/2812#discussion_r880076497


##########
core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java:
##########
@@ -223,11 +229,56 @@ public MysqlSqlDialect(Context context) {
       unparseFloor(writer, call);
       break;
 
+    case WITHIN_GROUP:
+      final List<SqlNode> operands = call.getOperandList();
+      if (operands.size() <= 0 || operands.get(0).getKind() != SqlKind.LISTAGG) {
+        super.unparseCall(writer, call, leftPrec, rightPrec);
+        return;
+      }
+      unparseListAggCall(writer, (SqlCall) operands.get(0),
+          operands.size() == 2 ? operands.get(1) : null, leftPrec, rightPrec);
+      break;
+
+    case LISTAGG:
+      unparseListAggCall(writer, call, null, leftPrec, rightPrec);
+      break;
+
     default:
       super.unparseCall(writer, call, leftPrec, rightPrec);
     }
   }
 
+  /**
+   * Unparses LISTAGG for MySQL. This call is translated to GROUP_CONCAT.
+   *
+   * @param writer Writer
+   * @param listAggCall Call of LISTAGG
+   * @param orderItemNode Elems of WITHIN_GROUP, NULL means none elem in the WITHIN_GROUP
+   * @param leftPrec Origin leftPrec
+   * @param rightPrec Origin rightPrec
+   */
+  private void unparseListAggCall(SqlWriter writer, SqlCall listAggCall,
+      @Nullable SqlNode orderItemNode, int leftPrec, int rightPrec) {
+    // LISTAGG(DISTINCT c1, ',') WITHIN GROUP (ORDER BY c2, c3)
+    // GROUP_CONCAT(DISTINCT c1 ORDER BY c2, c3 DESC SEPARATOR ',')
+    final List<SqlNode> listAggCallOperands = listAggCall.getOperandList();

Review Comment:
   OK.



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org