platinumhamburg commented on code in PR #1452: URL: https://github.com/apache/fluss/pull/1452#discussion_r2663436176
########## fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/procedure/ListRebalanceProcessProcedure.java: ########## @@ -0,0 +1,78 @@ +/* + * 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.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 process. */ +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); Review Comment: It is recommended to use RowType as the return type to make the return value more readable and user-friendly. ########## fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/procedure/RebalanceProcedure.java: ########## @@ -0,0 +1,83 @@ +/* + * 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.RebalancePlan; +import org.apache.fluss.cluster.rebalance.GoalType; +import org.apache.fluss.cluster.rebalance.RebalancePlanForBucket; + +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.util.ArrayList; +import java.util.List; + +/** Procedure to rebalance. */ +public class RebalanceProcedure extends ProcedureBase { + + /** + * As flink call don't support input a nested type like 'ARRAY'. So priorityGoals is defined as + * a String type, and different goals are split by ';'. + */ + @ProcedureHint( + argument = { + @ArgumentHint(name = "priorityGoals", type = @DataTypeHint("STRING")), + @ArgumentHint(name = "dryRun", type = @DataTypeHint("BOOLEAN"), isOptional = true) + }) + public String[] call(ProcedureContext context, String priorityGoals, @Nullable Boolean dryRun) + throws Exception { + List<GoalType> goalTypes = validateAndGetPriorityGoals(priorityGoals); + RebalancePlan rebalancePlan = admin.rebalance(goalTypes, dryRun != null && dryRun).get(); + return planToString(rebalancePlan); + } + + private static String[] planToString(RebalancePlan plan) { Review Comment: Ditto, It is recommended to use RowType as the return type to make the return value more readable and user-friendly. -- 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]
