diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java index 7af68de..4c69534 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java @@ -190,7 +190,7 @@ private void reparseAndSuperAnalyze(ASTNode tree) throws SemanticException { addSetRCols((ASTNode) assignment.getChildren().get(1), setRCols); - String columnName = colName.getText(); + String columnName = normalizeColName(colName.getText()); // Make sure this isn't one of the partitioning columns, that's not supported. if (partCols != null) { @@ -397,11 +397,20 @@ private void addSetRCols(ASTNode node, Set setRCols) { ASTNode colName = (ASTNode)node.getChildren().get(0); assert colName.getToken().getType() == HiveParser.Identifier : "Expected column name"; - setRCols.add(colName.getText()); + setRCols.add(normalizeColName(colName.getText())); } else if (node.getChildren() != null) { for (Node n : node.getChildren()) { addSetRCols((ASTNode)n, setRCols); } } } + + /** + * Column names are stored in metastore in lower case, regardless of the CREATE TABLE statement. + * Unfortunately there is no single place that normalizes the input query. + * @param colName not null + */ + private static String normalizeColName(String colName) { + return colName.toLowerCase(); + } } diff --git ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java index 06d2ca2..0427495 100644 --- ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java +++ ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java @@ -108,6 +108,19 @@ public void testNonAcidInsert() throws Exception { List rs1 = runStatementOnDriver("select a,b from " + Table.NONACIDORCTBL); } @Test + public void testUpdateMixedCase() throws Exception { + int[][] tableData = {{1,2},{3,3},{5,3}}; + runStatementOnDriver("insert into " + Table.ACIDTBL + "(a,b) " + makeValuesClause(tableData)); + runStatementOnDriver("update " + Table.ACIDTBL + " set B = 7 where A=1"); + List rs = runStatementOnDriver("select a,b from " + Table.ACIDTBL + " order by a,b"); + int[][] updatedData = {{1,7},{3,3},{5,3}}; + Assert.assertEquals("Update failed", stringifyValues(updatedData), rs); + runStatementOnDriver("update " + Table.ACIDTBL + " set B = B + 1 where A=1"); + List rs2 = runStatementOnDriver("select a,b from " + Table.ACIDTBL + " order by a,b"); + int[][] updatedData2 = {{1,8},{3,3},{5,3}}; + Assert.assertEquals("Update failed", stringifyValues(updatedData2), rs2); + } + @Test public void testDeleteIn() throws Exception { int[][] tableData = {{1,2},{3,2},{5,2},{1,3},{3,3},{5,3}}; runStatementOnDriver("insert into " + Table.ACIDTBL + "(a,b) " + makeValuesClause(tableData));