diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java index f2560e2e4793cca11950519708b1a666eb700e50..23a1b9757854c73a87e50edaeda330d5f7ef32e9 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -628,6 +628,12 @@ public final void testSelectAll() throws Exception { } @Test + public final void testSelectAllFromView() throws Exception { + doTestSelectAll(viewName, -1, -1); // tests not setting maxRows (return all) + doTestSelectAll(viewName, 0, -1); // tests setting maxRows to 0 (return all) + } + + @Test public final void testSelectAllPartioned() throws Exception { doTestSelectAll(partitionedTableName, -1, -1); // tests not setting maxRows // (return all) @@ -922,17 +928,20 @@ private void doTestSelectAll(String tableName, int maxRows, int fetchSize) throw assertEquals( "Unexpected column count", expectedColCount, meta.getColumnCount()); - String colQualifier = ((tableName != null) && !tableName.isEmpty()) ? tableName.toLowerCase() + "." : ""; boolean moreRow = res.next(); while (moreRow) { try { i++; - assertEquals(res.getInt(1), res.getInt(colQualifier + "under_col")); - assertEquals(res.getString(1), res.getString(colQualifier + "under_col")); - assertEquals(res.getString(2), res.getString(colQualifier + "value")); + assertEquals(res.getInt(1), res.getInt(tableName + ".under_col")); + assertEquals(res.getInt(1), res.getInt("under_col")); + assertEquals(res.getString(1), res.getString(tableName + ".under_col")); + assertEquals(res.getString(1), res.getString("under_col")); + assertEquals(res.getString(2), res.getString(tableName + ".value")); + assertEquals(res.getString(2), res.getString("value")); if (isPartitionTable) { assertEquals(res.getString(3), partitionedColumnValue); - assertEquals(res.getString(3), res.getString(colQualifier + partitionedColumnName)); + assertEquals(res.getString(3), res.getString(partitionedColumnName)); + assertEquals(res.getString(3), res.getString(tableName + "."+ partitionedColumnName)); } assertFalse("Last result value was not null", res.wasNull()); assertNull("No warnings should be found on ResultSet", res diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java b/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java index 8cbf9e7092489a2adb0bc2ba6b5ee38e41c041f8..cd1916fe7e8dd39dfd4927b7e56bd10bcfd30404 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java @@ -85,11 +85,21 @@ public void deleteRow() throws SQLException { } public int findColumn(String columnName) throws SQLException { - int columnIndex = normalizedColumnNames.indexOf(columnName.toLowerCase()); - if (columnIndex==-1) { - throw new SQLException(); + int columnIndex = 0; + boolean findColumn = false; + for (String normalizedColumnName : normalizedColumnNames) { + ++columnIndex; + String[] names = normalizedColumnName.split("\\."); + String name = names[names.length -1]; + if (name.equalsIgnoreCase(columnName) || normalizedColumnName.equalsIgnoreCase(columnName)) { + findColumn = true; + break; + } + } + if (!findColumn) { + throw new SQLException("Could not find " + columnName + " in " + normalizedColumnNames); } else { - return ++columnIndex; + return columnIndex; } }