hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hashut...@apache.org
Subject svn commit: r1464037 - in /hive/trunk: data/files/ jdbc/src/java/org/apache/hive/jdbc/ jdbc/src/test/org/apache/hive/jdbc/ service/src/java/org/apache/hive/service/cli/operation/
Date Wed, 03 Apr 2013 14:22:29 GMT
Author: hashutosh
Date: Wed Apr  3 14:22:29 2013
New Revision: 1464037

URL: http://svn.apache.org/r1464037
Log:
HIVE-4269 : fix handling of binary type in hiveserver2, jdbc driver (Thejas Nair via Ashutosh
Chauhan)

Modified:
    hive/trunk/data/files/datatypes.txt
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveResultSetMetaData.java
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java
    hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
    hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java

Modified: hive/trunk/data/files/datatypes.txt
URL: http://svn.apache.org/viewvc/hive/trunk/data/files/datatypes.txt?rev=1464037&r1=1464036&r2=1464037&view=diff
==============================================================================
--- hive/trunk/data/files/datatypes.txt (original)
+++ hive/trunk/data/files/datatypes.txt Wed Apr  3 14:22:29 2013
@@ -1,3 +1,3 @@
-\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N
--1false-1.1\N\N\N-1-1-1.0-1\N\N\N\N
-1true1.11121x2ykva92.2111.01abcd1111213142212212x1abcd22012-04-22
09:00:00.123456789123456789.0123456
+\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N
+-1false-1.1\N\N\N-1-1-1.0-1\N\N\N\N\N
+1true1.11121x2ykva92.2111.01abcd1111213142212212x1abcd22012-04-22
09:00:00.123456789123456789.0123456YWJjZA==

Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java?rev=1464037&r1=1464036&r2=1464037&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java Wed Apr  3 14:22:29
2013
@@ -439,6 +439,15 @@ public abstract class HiveBaseResultSet 
     return null;
   }
 
+  private byte[] getBinaryValue(TStringValue tString) {
+    if (tString.isSetValue()) {
+      wasNull = false;
+      return tString.getValue().getBytes();
+    }
+    wasNull = true;
+    return null;
+  }
+
   private BigDecimal getBigDecimalValue(TStringValue tStringValue) {
     if (tStringValue.isSetValue()) {
       wasNull = false;
@@ -480,6 +489,8 @@ public abstract class HiveBaseResultSet 
       return getDoubleValue(tColumnValue.getDoubleVal());
     case STRING_TYPE:
       return getStringValue(tColumnValue.getStringVal());
+    case BINARY_TYPE:
+      return getBinaryValue(tColumnValue.getStringVal());
     case TIMESTAMP_TYPE:
       return getTimestampValue(tColumnValue.getStringVal());
     case DECIMAL_TYPE:
@@ -588,6 +599,9 @@ public abstract class HiveBaseResultSet 
     if (wasNull) {
       return null;
     }
+    if (value instanceof byte[]){
+      return new String((byte[])value);
+    }
     return value.toString();
   }
 

Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveResultSetMetaData.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveResultSetMetaData.java?rev=1464037&r1=1464036&r2=1464037&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveResultSetMetaData.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveResultSetMetaData.java Wed Apr  3 14:22:29
2013
@@ -114,6 +114,8 @@ public class HiveResultSetMetaData imple
       return serdeConstants.TIMESTAMP_TYPE_NAME;
     } else if ("decimal".equalsIgnoreCase(type)) {
       return serdeConstants.DECIMAL_TYPE_NAME;
+    } else if ("binary".equalsIgnoreCase(type)) {
+      return serdeConstants.BINARY_TYPE_NAME;
     } else if (type.startsWith("map<")) {
       return serdeConstants.STRING_TYPE_NAME;
     } else if (type.startsWith("array<")) {

Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java?rev=1464037&r1=1464036&r2=1464037&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java Wed Apr  3 14:22:29 2013
@@ -132,6 +132,8 @@ public class Utils {
       return Types.TIMESTAMP;
     } else if ("decimal".equalsIgnoreCase(type)) {
       return Types.DECIMAL;
+    } else if ("binary".equalsIgnoreCase(type)) {
+      return Types.BINARY;
     } else if (type.startsWith("map<")) {
       return Types.VARCHAR;
     } else if (type.startsWith("array<")) {

Modified: hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java?rev=1464037&r1=1464036&r2=1464037&view=diff
==============================================================================
--- hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java (original)
+++ hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java Wed Apr  3 14:22:29
2013
@@ -145,7 +145,8 @@ public class TestJdbcDriver2 extends Tes
         + " c15 struct<r:int,s:struct<a:int,b:string>>,"
         + " c16 array<struct<m:map<string,string>,n:int>>,"
         + " c17 timestamp, "
-        + " c18 decimal) comment'" + dataTypeTableComment
+        + " c18 decimal, "
+        + " c19 binary) comment'" + dataTypeTableComment
             +"' partitioned by (dt STRING)");
 
     stmt.execute("load data local inpath '"
@@ -408,6 +409,9 @@ public class TestJdbcDriver2 extends Tes
     assertEquals(null, res.getString(14));
     assertEquals(null, res.getString(15));
     assertEquals(null, res.getString(16));
+    assertEquals(null, res.getString(17));
+    assertEquals(null, res.getString(18));
+    assertEquals(null, res.getString(19));
 
     // row 2
     assertTrue(res.next());
@@ -430,6 +434,7 @@ public class TestJdbcDriver2 extends Tes
     assertEquals(null, res.getString(17));
     assertEquals(null, res.getTimestamp(17));
     assertEquals(null, res.getBigDecimal(18));
+    assertEquals(null, res.getString(19));
 
     // row 3
     assertTrue(res.next());
@@ -452,6 +457,7 @@ public class TestJdbcDriver2 extends Tes
     assertEquals("2012-04-22 09:00:00.123456789", res.getString(17));
     assertEquals("2012-04-22 09:00:00.123456789", res.getTimestamp(17).toString());
     assertEquals("123456789.0123456", res.getBigDecimal(18).toString());
+    assertEquals("abcd", res.getString(19));
 
     // test getBoolean rules on non-boolean columns
     assertEquals(true, res.getBoolean(1));

Modified: hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
URL: http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java?rev=1464037&r1=1464036&r2=1464037&view=diff
==============================================================================
--- hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java (original)
+++ hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java Wed
Apr  3 14:22:29 2013
@@ -198,10 +198,16 @@ public class SQLOperation extends Execut
   private static Object convertLazyToJava(Object o, ObjectInspector oi) {
     Object obj = ObjectInspectorUtils.copyToStandardObject(o, oi, ObjectInspectorCopyOption.JAVA);
 
+    if (obj == null) {
+      return obj;
+    }
+    if(oi.getTypeName().equals(serdeConstants.BINARY_TYPE_NAME)) {
+      return new String((byte[])obj);
+    }
     // for now, expose non-primitive as a string
     // TODO: expose non-primitive as a structured object while maintaining JDBC compliance
-    if (obj != null && oi.getCategory() != ObjectInspector.Category.PRIMITIVE) {
-      obj = obj.toString();
+    if (oi.getCategory() != ObjectInspector.Category.PRIMITIVE) {
+      return obj.toString();
     }
 
     return obj;



Mime
View raw message