diff --git a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index fafd78e63e9b41c9fdb0e017b567dc719d151784..5ab67223f6b4d1be216a4abc5dd6e5411ed67466 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -320,11 +320,6 @@ HIVE_FILE_MAX_FOOTER("hive.file.max.footer", 100, "maximum number of lines for footer user can define for a table file"), - HIVE_RESULTSET_USE_UNIQUE_COLUMN_NAMES("hive.resultset.use.unique.column.names", true, - "Make column names unique in the result set by qualifying column names with table alias if needed.\n" + - "Table alias will be added to column names for queries of type \"select *\" or \n" + - "if query explicitly uses table alias \"select r1.x..\"."), - // Hadoop Configuration Properties // Properties with null values are ignored and exist only for the purpose of giving us // a symbolic name to reference in the Hive source code. Properties with non-null @@ -2592,7 +2587,6 @@ private static String getSQLStdAuthDefaultWhiteListPattern() { ConfVars.HIVE_LOCALIZE_RESOURCE_NUM_WAIT_ATTEMPTS.varname, ConfVars.HIVE_MULTI_INSERT_MOVE_TASKS_SHARE_DEPENDENCIES.varname, ConfVars.HIVE_QUOTEDID_SUPPORT.varname, - ConfVars.HIVE_RESULTSET_USE_UNIQUE_COLUMN_NAMES.varname, ConfVars.HIVE_STATS_COLLECT_PART_LEVEL_STATS.varname, ConfVars.JOB_DEBUG_CAPTURE_STACKTRACES.varname, ConfVars.JOB_DEBUG_TIMEOUT.varname, 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; } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 1953e81e52bd7ada7b7ec750205a8e33edfcd9ae..9ce6e2bc03b35385cb38c7bcff10ed4eed80fa80 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -10121,11 +10121,7 @@ public void analyzeInternal(ASTNode ast) throws SemanticException { sinkOp = genPlan(qb); } - if (createVwDesc != null) - resultSchema = convertRowSchemaToViewSchema(opParseCtx.get(sinkOp).getRowResolver()); - else - resultSchema = convertRowSchemaToResultSetSchema(opParseCtx.get(sinkOp).getRowResolver(), - HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_RESULTSET_USE_UNIQUE_COLUMN_NAMES)); + resultSchema = convertRowSchemaToResultSetSchema(opParseCtx.get(sinkOp).getRowResolver()); ParseContext pCtx = new ParseContext(conf, qb, child, opToPartPruner, opToPartList, topOps, topSelOps, opParseCtx, joinContext, smbMapJoinContext, @@ -10503,14 +10499,8 @@ private void saveViewDefinition() throws SemanticException { createVwDesc.setViewExpandedText(expandedText); } - private List convertRowSchemaToViewSchema(RowResolver rr) throws SemanticException { - List fieldSchema = convertRowSchemaToResultSetSchema(rr, false); - ParseUtils.validateColumnNameUniqueness(fieldSchema); - return fieldSchema; - } - - private List convertRowSchemaToResultSetSchema(RowResolver rr, - boolean useTabAliasIfAvailable) { + private List convertRowSchemaToResultSetSchema(RowResolver rr) + throws SemanticException { List fieldSchemas = new ArrayList(); String[] qualifiedColName; String colName; @@ -10521,7 +10511,7 @@ private void saveViewDefinition() throws SemanticException { } qualifiedColName = rr.reverseLookup(colInfo.getInternalName()); - if (useTabAliasIfAvailable && qualifiedColName[0] != null && !qualifiedColName[0].isEmpty()) { + if (qualifiedColName[0] != null && !qualifiedColName[0].isEmpty()) { colName = qualifiedColName[0] + "." + qualifiedColName[1]; } else { colName = qualifiedColName[1]; @@ -12612,8 +12602,7 @@ public RelNode apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlu try { optiqGenPlan = genLogicalPlan(qb, true); - topLevelFieldSchema = convertRowSchemaToResultSetSchema(relToHiveRR.get(optiqGenPlan), - HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_RESULTSET_USE_UNIQUE_COLUMN_NAMES)); + topLevelFieldSchema = convertRowSchemaToResultSetSchema(relToHiveRR.get(optiqGenPlan)); } catch (SemanticException e) { semanticException = e; throw new RuntimeException(e);