FAQ
Repository: hive
Updated Branches:
   refs/heads/master bd90fc349 -> db46e6e8c


HIVE-11451: SemanticAnalyzer throws IndexOutOfBounds Exception (Aihua Xu, reviewed by Chao Sun)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/db46e6e8
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/db46e6e8
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/db46e6e8

Branch: refs/heads/master
Commit: db46e6e8ccc4ee86fbd074dbc3d2e4fa7d88ce25
Parents: bd90fc3
Author: Aihua Xu <aihuaxu@gmail.com>
Authored: Thu Aug 13 10:55:30 2015 -0700
Committer: Chao Sun <sunchao@apache.org>
Committed: Thu Aug 13 11:24:31 2015 -0700

----------------------------------------------------------------------
  .../hadoop/hive/ql/parse/SemanticAnalyzer.java | 15 +++++++++------
  .../clientnegative/mismatch_columns_insertion.q | 4 ++++
  .../clientnegative/mismatch_columns_insertion.q.out | 9 +++++++++
  3 files changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/db46e6e8/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
----------------------------------------------------------------------
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 5ea6f3f..b809a23 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
@@ -6724,6 +6724,14 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
        outColumnCnt += dpCtx.getNumDPCols();
      }

+ // The numbers of input columns and output columns should match for regular query
+ if (!updating() && !deleting() && inColumnCnt != outColumnCnt) {
+ String reason = "Table " + dest + " has " + outColumnCnt
+ + " columns, but query has " + inColumnCnt + " columns.";
+ throw new SemanticException(ErrorMsg.TARGET_TABLE_COLUMN_MISMATCH.getMsg(
+ qb.getParseInfo().getDestForClause(dest), reason));
+ }
+
      // Check column types
      boolean converted = false;
      int columnNumber = tableFields.size();
@@ -6830,12 +6838,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
          dpCtx.mapInputToDP(rowFields.subList(tableFields.size() + 1, rowFields.size()));
        }
      } else {
- if (inColumnCnt != outColumnCnt) {
- String reason = "Table " + dest + " has " + outColumnCnt
- + " columns, but query has " + inColumnCnt + " columns.";
- throw new SemanticException(ErrorMsg.TARGET_TABLE_COLUMN_MISMATCH.getMsg(
- qb.getParseInfo().getDestForClause(dest), reason));
- } else if (dynPart && dpCtx != null) {
+ if (dynPart && dpCtx != null) {
          // create the mapping from input ExprNode to dest table DP column
          dpCtx.mapInputToDP(rowFields.subList(tableFields.size(), rowFields.size()));
        }

http://git-wip-us.apache.org/repos/asf/hive/blob/db46e6e8/ql/src/test/queries/clientnegative/mismatch_columns_insertion.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientnegative/mismatch_columns_insertion.q b/ql/src/test/queries/clientnegative/mismatch_columns_insertion.q
new file mode 100644
index 0000000..dad1ec1
--- /dev/null
+++ b/ql/src/test/queries/clientnegative/mismatch_columns_insertion.q
@@ -0,0 +1,4 @@
+
+create table mismatch_columns(key string, value string);
+
+insert overwrite table mismatch_columns select key from srcpart where ds is not null;

http://git-wip-us.apache.org/repos/asf/hive/blob/db46e6e8/ql/src/test/results/clientnegative/mismatch_columns_insertion.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/mismatch_columns_insertion.q.out b/ql/src/test/results/clientnegative/mismatch_columns_insertion.q.out
new file mode 100644
index 0000000..831af12
--- /dev/null
+++ b/ql/src/test/results/clientnegative/mismatch_columns_insertion.q.out
@@ -0,0 +1,9 @@
+PREHOOK: query: create table mismatch_columns(key string, value string)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@mismatch_columns
+POSTHOOK: query: create table mismatch_columns(key string, value string)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@mismatch_columns
+FAILED: SemanticException [Error 10044]: Line 3:23 Cannot insert into target table because column number/types are different 'mismatch_columns': Table insclause-0 has 2 columns, but query has 1 columns.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categorieshive, hadoop
postedAug 13, '15 at 6:25p
activeAug 13, '15 at 6:25p
posts1
users1
websitehive.apache.org

1 user in discussion

Sunchao: 1 post

People

Translate

site design / logo © 2021 Grokbase