You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by su...@apache.org on 2015/06/22 04:40:36 UTC

hive git commit: HIVE-11042 - Need fix Utilities.replaceTaskId method (Yongzhi Chen, reviewed by Chao Sun)

Repository: hive
Updated Branches:
  refs/heads/master 9134347b1 -> 142426394


HIVE-11042 - Need fix Utilities.replaceTaskId method (Yongzhi Chen, reviewed by Chao Sun)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/14242639
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/14242639
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/14242639

Branch: refs/heads/master
Commit: 142426394cfdc8a1fea51f7642c63f43f36b0333
Parents: 9134347
Author: Chao Sun <su...@apache.org>
Authored: Sun Jun 21 19:40:16 2015 -0700
Committer: Chao Sun <su...@apache.org>
Committed: Sun Jun 21 19:40:16 2015 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hive/ql/exec/Utilities.java   | 22 ++++++++++++++++++--
 .../hadoop/hive/ql/exec/TestUtilities.java      | 11 ++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/14242639/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
index 024e05c..14aaceb 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
@@ -1777,8 +1777,26 @@ public final class Utilities {
     return (ret);
   }
 
-  private static String replaceTaskId(String taskId, int bucketNum) {
-    return replaceTaskId(taskId, String.valueOf(bucketNum));
+  /**
+   * Replace taskId with input bucketNum. For example, if taskId is 000000 and bucketNum is 1,
+   * return should be 000001; if taskId is (ds%3D1)000000 and bucketNum is 1, return should be
+   * (ds%3D1)000001. This method is different from the replaceTaskId(String, String) method.
+   * In this method, the pattern is in taskId.
+   * @param taskId
+   * @param bucketNum
+   * @return
+   */
+  public static String replaceTaskId(String taskId, int bucketNum) {
+    String bucketNumStr = String.valueOf(bucketNum);
+    Matcher m = PREFIXED_TASK_ID_REGEX.matcher(taskId);
+    if (!m.matches()) {
+        LOG.warn("Unable to determine bucket number from task id: " + taskId + ". Using " +
+            "task ID as bucket number.");
+        return adjustBucketNumLen(bucketNumStr, taskId);
+    } else {
+      String adjustedBucketNum = adjustBucketNumLen(bucketNumStr, m.group(2));
+      return (m.group(1) == null ? "" : m.group(1)) + adjustedBucketNum;
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hive/blob/14242639/ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java
index 69f8889..ccc21e9 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java
@@ -140,4 +140,15 @@ public class TestUtilities extends TestCase {
       FileUtils.deleteQuietly(f);
     }
   }
+
+  public void testReplaceTaskId() {
+    String taskID = "000000";
+    int bucketNum = 1;
+    String newTaskID = Utilities.replaceTaskId(taskID, bucketNum);
+    Assert.assertEquals("000001", newTaskID);
+    taskID = "(ds%3D1)000001";
+    newTaskID = Utilities.replaceTaskId(taskID, 5);
+    Assert.assertEquals("(ds%3D1)000005", newTaskID);
+  }
+
 }