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

jeagles pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/tez.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new 6f519eb  TEZ-4133. key class implements writableComparable and 
configurable use default configuration (wang qiang via jeagles)
6f519eb is described below

commit 6f519eba1c358e025b1e19224887d60b3abe3988
Author: Jonathan Eagles <[email protected]>
AuthorDate: Tue Jul 21 15:45:22 2020 +0000

    TEZ-4133. key class implements writableComparable and configurable use 
default configuration (wang qiang via jeagles)
    
    Signed-off-by: Jonathan Eagles <[email protected]>
    (cherry picked from commit 2d7c60849adf3ed62f36f00e161c5d55962206f5)
---
 .../tez/runtime/library/common/ConfigUtils.java    |  4 +-
 .../runtime/library/common/TestConfigUtils.java    | 85 ++++++++++++++++++++++
 2 files changed, 87 insertions(+), 2 deletions(-)

diff --git 
a/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/ConfigUtils.java
 
b/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/ConfigUtils.java
index 24ad0ad..76d3dff 100644
--- 
a/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/ConfigUtils.java
+++ 
b/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/ConfigUtils.java
@@ -122,7 +122,7 @@ public class ConfigUtils {
     if (theClass != null)
       return ReflectionUtils.newInstance(theClass, conf);
     return 
WritableComparator.get(getIntermediateOutputKeyClass(conf).asSubclass(
-        WritableComparable.class));
+        WritableComparable.class), conf);
   }
 
   public static <K> RawComparator<K> 
getIntermediateInputKeyComparator(Configuration conf) {
@@ -132,7 +132,7 @@ public class ConfigUtils {
     if (theClass != null)
       return ReflectionUtils.newInstance(theClass, conf);
     return 
WritableComparator.get(getIntermediateInputKeyClass(conf).asSubclass(
-        WritableComparable.class));
+        WritableComparable.class), conf);
   }
 
   
diff --git 
a/tez-runtime-library/src/test/java/org/apache/tez/runtime/library/common/TestConfigUtils.java
 
b/tez-runtime-library/src/test/java/org/apache/tez/runtime/library/common/TestConfigUtils.java
new file mode 100644
index 0000000..24f76cc
--- /dev/null
+++ 
b/tez-runtime-library/src/test/java/org/apache/tez/runtime/library/common/TestConfigUtils.java
@@ -0,0 +1,85 @@
+/**
+ * Licensed 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.tez.runtime.library.common;
+
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.WritableComparable;
+import org.apache.hadoop.io.WritableComparator;
+import org.apache.tez.runtime.library.api.TezRuntimeConfiguration;
+import org.junit.Test;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+
+import static org.junit.Assert.assertEquals;
+
+
+public class TestConfigUtils {
+
+  private static class CustomKey implements WritableComparable<CustomKey>, 
Configurable {
+
+    private Configuration conf;
+
+    @Override
+    public int compareTo(CustomKey o) {
+      return 0;
+    }
+
+    @Override
+    public void write(DataOutput out) {
+
+    }
+
+    @Override
+    public void readFields(DataInput in) {
+
+    }
+
+    @Override
+    public void setConf(Configuration conf) {
+      this.conf = conf;
+    }
+
+    @Override
+    public Configuration getConf() {
+      return conf;
+    }
+  }
+
+  @Test
+  public void getIntermediateOutputKeyComparator() {
+    Configuration conf = new Configuration();
+    String testKey = "test_flag_name";
+    String testValue = "tez";
+    conf.set(testKey, testValue);
+    conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_KEY_CLASS, 
CustomKey.class.getName());
+    WritableComparator rawComparator = (WritableComparator) 
ConfigUtils.getIntermediateOutputKeyComparator(conf);
+    CustomKey customKey = (CustomKey) rawComparator.newKey();
+    assertEquals(testValue, customKey.getConf().get(testKey));
+  }
+
+  @Test
+  public void getIntermediateInputKeyComparator() {
+    Configuration conf = new Configuration();
+    String testKey = "test_flag_name";
+    String testValue = "tez";
+    conf.set(testKey, testValue);
+    conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_KEY_CLASS, 
CustomKey.class.getName());
+    WritableComparator rawComparator = (WritableComparator) 
ConfigUtils.getIntermediateInputKeyComparator(conf);
+    CustomKey customKey = (CustomKey) rawComparator.newKey();
+    assertEquals(testValue, customKey.getConf().get(testKey));
+  }
+}
\ No newline at end of file

Reply via email to