This is an automated email from the ASF dual-hosted git repository.

zuston pushed a commit to branch branch-0.7
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git


The following commit(s) were added to refs/heads/branch-0.7 by this push:
     new a6e6e462 [#665] feat(client): keep consistent with vanilla spark when 
key or value is null (#666)
a6e6e462 is described below

commit a6e6e4621997347b1355c65e8b1cc88826cf28ce
Author: Junfan Zhang <[email protected]>
AuthorDate: Mon Feb 27 17:17:56 2023 +0800

    [#665] feat(client): keep consistent with vanilla spark when key or value 
is null (#666)
    
    ### What changes were proposed in this pull request?
    
    keep consistent with vanilla spark when key or value is null
    
    ### Why are the changes needed?
    
    Fix: #665
    
    The PR of https://github.com/apache/incubator-uniffle/pull/296 has fixed 
the bug of NPE of value. But in some cases of production, the key also could be 
null. So this corner case also should keep consistent with vanilla spark.
    
    And to prevent this logic from reverting, the corresponding tests have been 
attached.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    1. Unit tests
---
 .../spark/shuffle/writer/WriteBufferManager.java   |  6 ++-
 .../apache/uniffle/test/NullOfKeyOrValueTest.java  | 58 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/writer/WriteBufferManager.java
 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/writer/WriteBufferManager.java
index 7b10fb83..9f33be38 100644
--- 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/writer/WriteBufferManager.java
+++ 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/writer/WriteBufferManager.java
@@ -116,7 +116,11 @@ public class WriteBufferManager extends MemoryConsumer {
   public List<ShuffleBlockInfo> addRecord(int partitionId, Object key, Object 
value) {
     final long start = System.currentTimeMillis();
     arrayOutputStream.reset();
-    serializeStream.writeKey(key, ClassTag$.MODULE$.apply(key.getClass()));
+    if (key != null) {
+      serializeStream.writeKey(key, ClassTag$.MODULE$.apply(key.getClass()));
+    } else {
+      serializeStream.writeKey(null, ManifestFactory$.MODULE$.Null());
+    }
     if (value != null) {
       serializeStream.writeValue(value, 
ClassTag$.MODULE$.apply(value.getClass()));
     } else {
diff --git 
a/integration-test/spark-common/src/test/java/org/apache/uniffle/test/NullOfKeyOrValueTest.java
 
b/integration-test/spark-common/src/test/java/org/apache/uniffle/test/NullOfKeyOrValueTest.java
new file mode 100644
index 00000000..ba8917ef
--- /dev/null
+++ 
b/integration-test/spark-common/src/test/java/org/apache/uniffle/test/NullOfKeyOrValueTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.uniffle.test;
+
+import java.util.Map;
+
+import com.google.common.collect.Lists;
+import org.apache.spark.api.java.JavaPairRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.Test;
+import scala.Tuple2;
+
+/**
+ * This class is to test whether the RSS keep consistent with the vanilla 
spark shuffle when
+ * the key or value is null.
+ */
+public class NullOfKeyOrValueTest extends SimpleTestBase {
+
+  @Test
+  public void nullOfKeyOrValueTest() throws Exception {
+    run();
+  }
+
+  @Override
+  public Map runTest(SparkSession spark, String fileName) throws Exception {
+    // take a rest to make sure shuffle server is registered
+    Thread.sleep(4000);
+    JavaSparkContext jsc = new JavaSparkContext(spark.sparkContext());
+    JavaPairRDD<String, Integer> javaPairRDD = jsc.parallelizePairs(
+        Lists.newArrayList(
+            new Tuple2<>("cat1", null),
+            new Tuple2<>("dog", 22),
+            new Tuple2<>("cat", 33),
+            new Tuple2<>("pig", 44),
+            new Tuple2<>(null, 55),
+            new Tuple2<>("cat", 66)
+        ),
+        2
+    );
+    return javaPairRDD.collectAsMap();
+  }
+}

Reply via email to