Repository: tajo Updated Branches: refs/heads/branch-0.10.2 18d84dde1 -> 90e74e99e
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/90e74e99 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/90e74e99 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/90e74e99 Branch: refs/heads/branch-0.10.2 Commit: 90e74e99e5db3e40186da5440b1e138ba0fcc25a Parents: 18d84dd Author: Hyunsik Choi <[email protected]> Authored: Tue May 26 21:54:07 2015 -0700 Committer: Hyunsik Choi <[email protected]> Committed: Tue May 26 21:56:59 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/90e74e99/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index bbc9448..2d0cfee 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,8 @@ Release 0.10.1 - Released 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/90e74e99/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 ddfa7a6..92d1bcd 100644 --- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java +++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java @@ -276,24 +276,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/90e74e99/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/90e74e99/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 27cd3b0..435b3e3 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 @@ -1534,6 +1534,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);
