You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by br...@apache.org on 2014/10/04 18:50:00 UTC

svn commit: r1629416 - in /hive/trunk: itests/hive-unit/src/test/java/org/apache/hive/jdbc/ jdbc/src/java/org/apache/hive/jdbc/

Author: brock
Date: Sat Oct  4 16:50:00 2014
New Revision: 1629416

URL: http://svn.apache.org/r1629416
Log:
HIVE-8330 - HiveResultSet.findColumn() parameters are case sensitive (Sergio Pena via Brock)

Modified:
    hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveMetaDataResultSet.java
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java

Modified: hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
URL: http://svn.apache.org/viewvc/hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java?rev=1629416&r1=1629415&r2=1629416&view=diff
==============================================================================
--- hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java (original)
+++ hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java Sat Oct  4 16:50:00 2014
@@ -1318,6 +1318,42 @@ public class TestJdbcDriver2 {
   }
 
   @Test
+  public void testResultSetColumnNameCaseInsensitive() throws SQLException {
+    Statement stmt = con.createStatement();
+    ResultSet res;
+
+    res = stmt.executeQuery("select c1 from " + dataTypeTableName + " limit 1");
+    try {
+      int count = 0;
+      while (res.next()) {
+        res.findColumn("c1");
+        res.findColumn("C1");
+        count++;
+      }
+      assertEquals(count, 1);
+    } catch (Exception e) {
+      String msg = "Unexpected exception: " + e;
+      LOG.info(msg, e);
+      fail(msg);
+    }
+
+    res = stmt.executeQuery("select c1 C1 from " + dataTypeTableName + " limit 1");
+    try {
+      int count = 0;
+      while (res.next()) {
+        res.findColumn("c1");
+        res.findColumn("C1");
+        count++;
+      }
+      assertEquals(count, 1);
+    } catch (Exception e) {
+      String msg = "Unexpected exception: " + e;
+      LOG.info(msg, e);
+      fail(msg);
+    }
+  }
+
+  @Test
   public void testResultSetMetaData() throws SQLException {
     Statement stmt = con.createStatement();
 

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=1629416&r1=1629415&r2=1629416&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 Sat Oct  4 16:50:00 2014
@@ -58,6 +58,7 @@ public abstract class HiveBaseResultSet 
   protected boolean wasNull = false;
   protected Object[] row;
   protected List<String> columnNames;
+  protected List<String> normalizedColumnNames;
   protected List<String> columnTypes;
   protected List<JdbcColumnAttributes> columnAttributes;
 
@@ -84,7 +85,7 @@ public abstract class HiveBaseResultSet 
   }
 
   public int findColumn(String columnName) throws SQLException {
-    int columnIndex = columnNames.indexOf(columnName);
+    int columnIndex = normalizedColumnNames.indexOf(columnName.toLowerCase());
     if (columnIndex==-1) {
       throw new SQLException();
     } else {

Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveMetaDataResultSet.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveMetaDataResultSet.java?rev=1629416&r1=1629415&r2=1629416&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveMetaDataResultSet.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveMetaDataResultSet.java Sat Oct  4 16:50:00 2014
@@ -36,8 +36,13 @@ public abstract class HiveMetaDataResult
     }
     if (columnNames!=null) {
       this.columnNames = new ArrayList<String>(columnNames);
+      this.normalizedColumnNames = new ArrayList<String>();
+      for (String colName : columnNames) {
+        this.normalizedColumnNames.add(colName.toLowerCase());
+      }
     } else {
       this.columnNames =  new ArrayList<String>();
+      this.normalizedColumnNames = new ArrayList<String>();
     }
     if (columnTypes!=null) {
       this.columnTypes = new ArrayList<String>(columnTypes);

Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java?rev=1629416&r1=1629415&r2=1629416&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java Sat Oct  4 16:50:00 2014
@@ -191,6 +191,7 @@ public class HiveQueryResultSet extends 
     this.fetchSize = builder.fetchSize;
     this.transportLock = builder.transportLock;
     columnNames = new ArrayList<String>();
+    normalizedColumnNames = new ArrayList<String>();
     columnTypes = new ArrayList<String>();
     columnAttributes = new ArrayList<JdbcColumnAttributes>();
     if (builder.retrieveSchema) {
@@ -279,6 +280,7 @@ public class HiveQueryResultSet extends 
         }
         String columnName = columns.get(pos).getColumnName();
         columnNames.add(columnName);
+        normalizedColumnNames.add(columnName.toLowerCase());
         TPrimitiveTypeEntry primitiveTypeEntry =
             columns.get(pos).getTypeDesc().getTypes().get(0).getPrimitiveEntry();
         String columnTypeName = TYPE_NAMES.get(primitiveTypeEntry.getType());
@@ -303,6 +305,10 @@ public class HiveQueryResultSet extends 
     columnNames.addAll(colNames);
     columnTypes.addAll(colTypes);
     columnAttributes.addAll(colAttributes);
+
+    for (String colName : colNames) {
+      normalizedColumnNames.add(colName.toLowerCase());
+    }
   }
 
   @Override