Repository: tajo
Updated Branches:
  refs/heads/master 1872df943 -> 4f3a46c36


TAJO-1623: INSERT INTO with wrong target columns causes NPE.

Closes #587


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

Branch: refs/heads/master
Commit: 4f3a46c3646ca7a551916c57c980b2862a9dbb4e
Parents: 1872df9
Author: Hyunsik Choi <[email protected]>
Authored: Tue May 26 21:54:07 2015 -0700
Committer: Hyunsik Choi <[email protected]>
Committed: Tue May 26 21:54:07 2015 -0700

----------------------------------------------------------------------
 CHANGES                                            |  2 ++
 .../java/org/apache/tajo/QueryTestCaseBase.java    | 16 ++++++++++++----
 .../tajo/engine/planner/TestQueryValidation.java   | 17 ++++++++++++-----
 .../java/org/apache/tajo/plan/LogicalPlanner.java  |  6 ++++++
 4 files changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/4f3a46c3/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 58944a5..aeda418 100644
--- a/CHANGES
+++ b/CHANGES
@@ -136,6 +136,8 @@ Release 0.11.0 - unreleased
 
   BUG FIXES
 
+    TAJO-1623: INSERT INTO with wrong target columns causes NPE. (hyunsik)
+
     TAJO-1621: Compilation error with hadoop 2.7.0. (jinho)
 
     TAJO-1619: JDBC program is stuck after closing. (jihoon)

http://git-wip-us.apache.org/repos/asf/tajo/blob/4f3a46c3/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java 
b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
index 8d0ff12..9a92e90 100644
--- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
@@ -306,24 +306,32 @@ public class QueryTestCaseBase {
     return state;
   }
 
-  public void assertValidSQL(String fileName) throws PlanningException, 
IOException {
-    Path queryFilePath = getQueryFilePath(fileName);
-    String query = FileUtil.readTextFile(new File(queryFilePath.toUri()));
+  public void assertValidSQL(String query) throws PlanningException, 
IOException {
     VerificationState state = verify(query);
     if (state.getErrorMessages().size() > 0) {
       fail(state.getErrorMessages().get(0));
     }
   }
 
-  public void assertInvalidSQL(String fileName) throws PlanningException, 
IOException {
+  public void assertValidSQLFromFile(String fileName) throws 
PlanningException, IOException {
     Path queryFilePath = getQueryFilePath(fileName);
     String query = FileUtil.readTextFile(new File(queryFilePath.toUri()));
+    assertValidSQL(query);
+  }
+
+  public void assertInvalidSQL(String query) throws PlanningException, 
IOException {
     VerificationState state = verify(query);
     if (state.getErrorMessages().size() == 0) {
       fail(PreLogicalPlanVerifier.class.getSimpleName() + " cannot catch any 
verification error: " + query);
     }
   }
 
+  public void assertInvalidSQLFromFile(String fileName) throws 
PlanningException, IOException {
+    Path queryFilePath = getQueryFilePath(fileName);
+    String query = FileUtil.readTextFile(new File(queryFilePath.toUri()));
+    assertInvalidSQL(query);
+  }
+
   public void assertPlanError(String fileName) throws PlanningException, 
IOException {
     Path queryFilePath = getQueryFilePath(fileName);
     String query = FileUtil.readTextFile(new File(queryFilePath.toUri()));

http://git-wip-us.apache.org/repos/asf/tajo/blob/4f3a46c3/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestQueryValidation.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestQueryValidation.java
 
b/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestQueryValidation.java
index b6827a2..fd60a5e 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestQueryValidation.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestQueryValidation.java
@@ -25,19 +25,26 @@ import org.junit.Test;
 import java.io.IOException;
 
 public class TestQueryValidation extends QueryTestCaseBase {
+
+  @Test
+  public void testInsertWithWrongTargetColumn() throws Exception {
+    executeString("CREATE TABLE T1 (col1 int, col2 int)").close();
+    assertInvalidSQL("INSERT INTO T1 (col1, col3) select l_orderkey, l_partkey 
from default.lineitem");
+  }
+
   @Test
   public void testLimitClauses() throws PlanningException, IOException {
     // select * from lineitem limit 3;
-    assertValidSQL("valid_limit_1.sql");
+    assertValidSQLFromFile("valid_limit_1.sql");
 
     // select * from lineitem limit l_orderkey;
-    assertInvalidSQL("invalid_limit_1.sql");
+    assertInvalidSQLFromFile("invalid_limit_1.sql");
   }
 
   @Test
   public void testGroupByClauses() throws PlanningException, IOException {
     // select l_orderkey from lineitem group by l_orderkey;
-    assertValidSQL("valid_groupby_1.sql");
+    assertValidSQLFromFile("valid_groupby_1.sql");
 
     // select * from lineitem group by l_orderkey;
     assertPlanError("error_groupby_1.sql");
@@ -48,12 +55,12 @@ public class TestQueryValidation extends QueryTestCaseBase {
   @Test
   public void testCaseWhenExprs() throws PlanningException, IOException {
     // See TAJO-1098
-    assertInvalidSQL("invalid_casewhen_1.sql");
+    assertInvalidSQLFromFile("invalid_casewhen_1.sql");
   }
 
   @Test
   public void testUnsupportedStoreType() throws PlanningException, IOException 
{
     // See TAJO-1249
-    assertInvalidSQL("invalid_store_format.sql");
+    assertInvalidSQLFromFile("invalid_store_format.sql");
   }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4f3a46c3/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java 
b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
index cec0760..5571cdf 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
@@ -1564,6 +1564,12 @@ public class LogicalPlanner extends 
BaseAlgebraVisitor<LogicalPlanner.PlanContex
       Schema targetColumns = new Schema();
       for (int i = 0; i < targets.length; i++) {
         Column targetColumn = desc.getLogicalSchema().getColumn(targets[i]);
+
+        if (targetColumn == null) {
+          throw new PlanningException("column \"" + targets[i] + "\" of 
relation \"" +
+              desc.getName() + "\" does not exist");
+        }
+
         targetColumns.addColumn(targetColumn);
       }
       insertNode.setTargetSchema(targetColumns);

Reply via email to