swuferhong commented on code in PR #1452:
URL: https://github.com/apache/fluss/pull/1452#discussion_r2670534062


##########
fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/procedure/ListRebalanceProcessProcedure.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fluss.flink.procedure;
+
+import org.apache.fluss.client.admin.Admin;
+import org.apache.fluss.cluster.rebalance.RebalanceProgress;
+import org.apache.fluss.cluster.rebalance.RebalanceResultForBucket;
+import org.apache.fluss.cluster.rebalance.RebalanceStatus;
+import org.apache.fluss.metadata.TableBucket;
+
+import org.apache.flink.table.annotation.ArgumentHint;
+import org.apache.flink.table.annotation.DataTypeHint;
+import org.apache.flink.table.annotation.ProcedureHint;
+import org.apache.flink.table.procedure.ProcedureContext;
+
+import javax.annotation.Nullable;
+
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Procedure to list rebalance progress.
+ *
+ * <p>This procedure allows querying rebalance progress. See {@link
+ * Admin#listRebalanceProgress(String)} for more details.
+ *
+ * <p>Usage examples:
+ *
+ * <pre>
+ * -- List the rebalance progress without rebalance id
+ * CALL sys.list_rebalance_process();
+ *
+ * -- List the rebalance progress with rebalance id
+ * CALL sys.list_rebalance_process('xxx_xxx_xxx');
+ * </pre>
+ */
+public class ListRebalanceProcessProcedure extends ProcedureBase {
+
+    @ProcedureHint(
+            argument = {
+                @ArgumentHint(
+                        name = "rebalanceId",
+                        type = @DataTypeHint("STRING"),
+                        isOptional = true)
+            })
+    public String[] call(ProcedureContext context, @Nullable String 
rebalanceId) throws Exception {
+        RebalanceProgress progress = 
admin.listRebalanceProgress(rebalanceId).get();
+        return progressToString(progress);
+    }
+
+    private static String[] progressToString(RebalanceProgress progress) {
+        RebalanceStatus status = progress.status();
+        double rebalanceProgress = progress.progress();
+        Map<TableBucket, RebalanceResultForBucket> bucketMap = 
progress.progressForBucketMap();
+
+        List<String> result = new ArrayList<>();
+        if (progress.rebalanceId() != null) {
+            result.add("Rebalance id: " + progress.rebalanceId());
+        }
+        result.add("Reblance total status: " + status);
+        result.add("Rebalance progress: " + 
formatAsPercentage(rebalanceProgress));
+        result.add("Rebalance detail progress for bucket:");
+        for (RebalanceResultForBucket resultForBucket : bucketMap.values()) {

Review Comment:
   I will add one todo first. it will be support soon.



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