Davis-Zhang-Onehouse commented on code in PR #13489:
URL: https://github.com/apache/hudi/pull/13489#discussion_r2220023810


##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/data/TestHoodieJavaPairRDDDynamicRepartition.java:
##########
@@ -0,0 +1,435 @@
+/*
+ * 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.data;
+
+import org.apache.hudi.client.common.HoodieSparkEngineContext;
+import org.apache.hudi.common.data.HoodiePairData;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.metadata.HoodieBackedTestDelayedTableMetadata;
+
+import org.apache.spark.api.java.JavaPairRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import scala.Tuple2;
+import scala.Tuple3;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestHoodieJavaPairRDDDynamicRepartition {

Review Comment:
   make total sense, let's decide if it worth the maintainability against the 
value they deliver:
   
   the test covers a very special aspects of RDD operation - data partitioning 
behavior
   - We start with some rdd partition distribution
   - We end up with a different rdd distribution, data per partition/ across 
partition has special properties as declared by the java doc of 
org.apache.hudi.common.engine.HoodieEngineContext#mapGroupsByKey.
   
   
   why special RDD generator: needed to ensure we have rdd partitioned evenly 
and each partition the key is mixed.
   Later we validate keys in partitions are uniform
   
   why collect rdd into a nested map: we need to validate data properties 
across partitions and within partitions. It is easy to validate if we have it 
dumped to a hashmap. In other test, they rarely care info tagged with partition 
info.
   
   it allows us to do very straight forward validations like showing whoever 
reading the code what's the rdd content is per partition
   ```
       // With under sampling, num of split points = num of data points we 
sampled.
       Map<Integer, Map<Integer, List<String>>> expectedPartitionContents = 
Collections.unmodifiableMap(
           new HashMap<Integer, Map<Integer, List<String>>>() {
             {
               put(0, Collections.singletonMap(1, Arrays.asList("1", "10", 
"11", "12", "13", "14", "15", "16", "2", "3", "4")));
               put(1, Collections.singletonMap(1, Arrays.asList("5", "6", "7", 
"8", "9")));
               put(2, Collections.singletonMap(2, Arrays.asList("1", "10", 
"11", "12", "13", "14", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9")));
               put(3, Collections.emptyMap()); // Under-sampling leads to 
unnessarily allocating partitions to keys that do not have many entries.
               put(4, Collections.singletonMap(3, Arrays.asList("1", "10", "2", 
"3", "4", "5")));
               put(5, Collections.singletonMap(3, Arrays.asList("6", "7", "8", 
"9")));
             }
           }
       );
   ```
   it allows us to do randomized testing and show that the invariant that the 
API delivers hold consistently in testLargeScaleRandomized
   
   why special logging - 
https://github.com/apache/hudi/pull/13489#discussion_r2220001207
   
   if any argument is proven to be invalid, the corresponding code can be 
removed.



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