beyond1920 commented on code in PR #9030:
URL: https://github.com/apache/hudi/pull/9030#discussion_r1239722712


##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/cluster/ITTestFlinkConsistentHashingClustering.java:
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.hudi.sink.cluster;
+
+import org.apache.hudi.avro.model.HoodieClusteringPlan;
+import org.apache.hudi.client.HoodieFlinkWriteClient;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.model.WriteOperationType;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.util.ClusteringUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.config.HoodieClusteringConfig;
+import org.apache.hudi.config.HoodieIndexConfig;
+import org.apache.hudi.configuration.FlinkOptions;
+import org.apache.hudi.index.HoodieIndex;
+import org.apache.hudi.sink.clustering.FlinkClusteringConfig;
+import org.apache.hudi.table.HoodieFlinkTable;
+import 
org.apache.hudi.client.clustering.plan.strategy.FlinkConsistentBucketClusteringPlanStrategy;
+import org.apache.hudi.util.CompactionUtil;
+import org.apache.hudi.util.FlinkWriteClients;
+import org.apache.hudi.util.StreamerUtil;
+import org.apache.hudi.utils.TestConfigurations;
+import org.apache.hudi.utils.TestData;
+import org.apache.hudi.utils.TestSQL;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.config.ExecutionConfigOptions;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public class ITTestFlinkConsistentHashingClustering {
+
+  private static final Map<String, String> EXPECTED_AFTER_INITIAL_INSERT = new 
HashMap<>();
+  private static final Map<String, String> EXPECTED_AFTER_UPSERT = new 
HashMap<>();
+
+  static {
+    EXPECTED_AFTER_INITIAL_INSERT.put("", "id1,,id1,Danny,23,1000,, 
id2,,id2,Stephen,33,2000,, "
+        + "id3,,id3,Julian,53,3000,, id4,,id4,Fabian,31,4000,, 
id5,,id5,Sophia,18,5000,, "
+        + "id6,,id6,Emma,20,6000,, id7,,id7,Bob,44,7000,, 
id8,,id8,Han,56,8000,, ]");
+    EXPECTED_AFTER_UPSERT.put("", "[id1,,id1,Danny,24,1000,, 
id2,,id2,Stephen,34,2000,, id3,,id3,Julian,54,3000,, "
+        + "id4,,id4,Fabian,32,4000,, id5,,id5,Sophia,18,5000,, 
id6,,id6,Emma,20,6000,, "
+        + "id7,,id7,Bob,44,7000,, id8,,id8,Han,56,8000,, 
id9,,id9,Jane,19,6000,, "
+        + "id10,,id10,Ella,38,7000,, id11,,id11,Phoebe,52,8000,,]");
+  }
+
+  @TempDir
+  File tempFile;
+
+  @Test
+  public void testScheduleSplitPlan() throws Exception {
+    TableEnvironment tableEnv = setupTableEnv();
+    prepareData(tableEnv);
+
+    Configuration conf = getDefaultConfiguration();
+    conf.setString(HoodieIndexConfig.BUCKET_INDEX_MIN_NUM_BUCKETS.key(), "4");
+    conf.setString(HoodieIndexConfig.BUCKET_INDEX_MAX_NUM_BUCKETS.key(), "8");
+    // Manually set the split threshold to trigger split in the clustering
+    conf.set(FlinkOptions.WRITE_PARQUET_MAX_FILE_SIZE, 1);
+    conf.setString(HoodieIndexConfig.BUCKET_SPLIT_THRESHOLD.key(), 
String.valueOf(1 / 1024.0 / 1024.0));
+    HoodieFlinkWriteClient writeClient = 
FlinkWriteClients.createWriteClient(conf);
+    Option<String> clusteringInstantOption = 
writeClient.scheduleClustering(Option.empty());
+    Assertions.assertTrue(clusteringInstantOption.isPresent());
+
+    // Validate clustering plan
+    HoodieClusteringPlan clusteringPlan = getLatestClusteringPlan(writeClient);
+    Assertions.assertEquals(4, clusteringPlan.getInputGroups().size());
+    Assertions.assertEquals(1, 
clusteringPlan.getInputGroups().get(0).getSlices().size());
+    Assertions.assertEquals(1, 
clusteringPlan.getInputGroups().get(1).getSlices().size());
+    Assertions.assertEquals(1, 
clusteringPlan.getInputGroups().get(2).getSlices().size());
+    Assertions.assertEquals(1, 
clusteringPlan.getInputGroups().get(3).getSlices().size());
+  }
+
+  @Test
+  public void testScheduleMergePlan() throws Exception {
+    TableEnvironment tableEnv = setupTableEnv();
+    prepareData(tableEnv);
+
+    Configuration conf = getDefaultConfiguration();
+    HoodieFlinkWriteClient writeClient = 
FlinkWriteClients.createWriteClient(conf);
+    Option<String> clusteringInstantOption = 
writeClient.scheduleClustering(Option.empty());
+    Assertions.assertFalse(clusteringInstantOption.isPresent());
+  }
+
+  @Test
+  public void testScheduleSortPlan() throws Exception {
+    TableEnvironment tableEnv = setupTableEnv();
+    prepareData(tableEnv);
+
+    Configuration conf = getDefaultConfiguration();
+    conf.setBoolean(FlinkOptions.BUCKET_CLUSTERING_SORT_ENABLED, true);
+    HoodieFlinkWriteClient writeClient = 
FlinkWriteClients.createWriteClient(conf);

Review Comment:
   No.
   If the index is a consistent bucket index, the value of 
`hoodie.clustering.plan.strategy.class` must be 
`org.apache.hudi.client.clustering.plan.strategy.FlinkConsistentBucketClusteringPlanStrategy`.
 `hoodie.bucket.clustering.merge.enabled` must be set to `false`.
   If the index is a consistent bucket index, these two configuration values 
will be automatically set by the engine. The engine will also check the 
parameter values before submitting the job to ensure they meet the expected 
criteria and prevent user errors.
   The only advanced configure that users might need to consider is 
`hoodie.bucket.clustering.sort.enabled`, which controls whether to generate 
regular clustering plans for buckets that are not involved in merge or split 
within the consistent hashing bucket index clustering plan. The default value 
is `false` to avoid unnecessary clustering services. If users need to, they can 
enable this configure.
   There are some cases in `ITTestFlinkConsistentHashingClustering`, you could 
find the use don't need manual config options.



-- 
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-unsubscr...@hudi.apache.org

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

Reply via email to