Repository: hive Updated Branches: refs/heads/master cd027b7c5 -> 57fcbce52
HIVE-10481 - ACID table update finishes but values not really updated if column names are not all lower case Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/57fcbce5 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/57fcbce5 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/57fcbce5 Branch: refs/heads/master Commit: 57fcbce5251c04818dd0975f921c2648f289c8f8 Parents: cd027b7 Author: Eugene Koifman <ekoif...@hortonworks.com> Authored: Tue Apr 28 16:07:44 2015 -0700 Committer: Eugene Koifman <ekoif...@hortonworks.com> Committed: Tue Apr 28 16:07:44 2015 -0700 ---------------------------------------------------------------------- .../hive/ql/parse/UpdateDeleteSemanticAnalyzer.java | 13 +++++++++++-- .../org/apache/hadoop/hive/ql/TestTxnCommands2.java | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/57fcbce5/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java index 7af68de..4c69534 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java @@ -190,7 +190,7 @@ public class UpdateDeleteSemanticAnalyzer extends SemanticAnalyzer { 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 @@ public class UpdateDeleteSemanticAnalyzer extends SemanticAnalyzer { 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(); + } } http://git-wip-us.apache.org/repos/asf/hive/blob/57fcbce5/ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java ---------------------------------------------------------------------- diff --git a/ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java b/ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java index 06d2ca2..ac5ae2a 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java @@ -58,6 +58,7 @@ public class TestTxnCommands2 { @Before public void setUp() throws Exception { + tearDown(); hiveConf = new HiveConf(this.getClass()); hiveConf.set(HiveConf.ConfVars.PREEXECHOOKS.varname, ""); hiveConf.set(HiveConf.ConfVars.POSTEXECHOOKS.varname, ""); @@ -108,6 +109,19 @@ public class TestTxnCommands2 { List<String> 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<String> 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<String> 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));