hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hashut...@apache.org
Subject svn commit: r1364038 - in /hive/trunk/common/src: java/org/apache/hadoop/hive/conf/HiveConf.java test/org/apache/hadoop/hive/conf/TestHiveConf.java
Date Sat, 21 Jul 2012 04:14:07 GMT
Author: hashutosh
Date: Sat Jul 21 04:14:06 2012
New Revision: 1364038

URL: http://svn.apache.org/viewvc?rev=1364038&view=rev
Log:
HIVE-3221 : HiveConf.getPositionFromInternalName does not support more than sinle digit column
numbers (Sushanth Sowmyan via Ashutosh Chauhan)

Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
    hive/trunk/common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1364038&r1=1364037&r2=1364038&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Sat Jul 21 04:14:06
2012
@@ -28,6 +28,8 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.security.auth.login.LoginException;
 
@@ -1040,11 +1042,13 @@ public class HiveConf extends Configurat
   }
 
   public static int getPositionFromInternalName(String internalName) {
-    char pos = internalName.charAt(internalName.length()-1);
-    if (Character.isDigit(pos)) {
-      return Character.digit(pos, 10);
-    } else{
+    Pattern internalPattern = Pattern.compile("_col([0-9]+)");
+    Matcher m = internalPattern.matcher(internalName);
+    if (!m.matches()){
       return -1;
+    } else {
+      return Integer.parseInt(m.group(1));
     }
+
   }
 }

Modified: hive/trunk/common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java?rev=1364038&r1=1364037&r2=1364038&view=diff
==============================================================================
--- hive/trunk/common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java (original)
+++ hive/trunk/common/src/test/org/apache/hadoop/hive/conf/TestHiveConf.java Sat Jul 21 04:14:06
2012
@@ -76,4 +76,10 @@ public class TestHiveConf extends TestCa
     // Test HiveConf property variable substitution in hive-site.xml
     checkHiveConf("test.var.hiveconf.property", ConfVars.DEFAULTPARTITIONNAME.defaultVal);
   }
+
+  public void testColumnNameMapping() throws Exception {
+    for (int i = 0 ; i < 20 ; i++ ){
+      assertTrue(i == HiveConf.getPositionFromInternalName(HiveConf.getColumnInternalName(i)));
+    }
+  }
 }



Mime
View raw message