tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [22/50] [abbrv] git commit: TAJO-848: PreLogicalPlanVerifier::visitInsert need to find smaller expressions than target columns for a partitioned table. (jaehwa)
Date Wed, 09 Jul 2014 04:10:39 GMT
TAJO-848: PreLogicalPlanVerifier::visitInsert need to find smaller expressions than target
columns for a partitioned table. (jaehwa)


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

Branch: refs/heads/window_function
Commit: 1613cd2c7917ffa8ecc8aee24729bd670f3b0ac8
Parents: 4ec8f0d
Author: blrunner <jhjung@gruter.com>
Authored: Mon Jun 23 11:41:59 2014 +0900
Committer: blrunner <jhjung@gruter.com>
Committed: Mon Jun 23 11:41:59 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 +
 .../engine/planner/PreLogicalPlanVerifier.java  | 27 ++++++-
 .../tajo/engine/query/TestTablePartitions.java  | 83 +++++++++++++++++++-
 .../queries/TestTablePartitions/case14.sql      |  3 +
 .../queries/TestTablePartitions/case15.sql      |  3 +
 .../results/TestTablePartitions/case14.result   |  3 +
 .../results/TestTablePartitions/case15.result   |  3 +
 7 files changed, 121 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/1613cd2c/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 636808d..74f016b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -71,6 +71,9 @@ Release 0.9.0 - unreleased
 
   BUG FIXES
 
+    TAJO-848: PreLogicalPlanVerifier::visitInsert need to find smaller expressions than target
+    columns for a partitioned table. (jaehwa)
+
     TAJO-880: NULL in CASE clause occurs Exception. (Hyoungjun Kim via hyunsik)
 
     TAJO-862: Restore failure of dumped relations. (jihoon)

http://git-wip-us.apache.org/repos/asf/tajo/blob/1613cd2c/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
b/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
index 5eca5fd..f744cf6 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
@@ -18,9 +18,11 @@
 
 package org.apache.tajo.engine.planner;
 
+import org.apache.tajo.TajoConstants;
 import org.apache.tajo.algebra.*;
 import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.master.session.Session;
 import org.apache.tajo.util.TUtil;
@@ -223,7 +225,6 @@ public class PreLogicalPlanVerifier extends BaseAlgebraVisitor <PreLogicalPlanVe
 
   public Expr visitInsert(Context context, Stack<Expr> stack, Insert expr) throws PlanningException
{
     Expr child = super.visitInsert(context, stack, expr);
-
     if (!expr.isOverwrite()) {
       context.state.addVerification("INSERT INTO statement is not supported yet.");
     }
@@ -233,9 +234,10 @@ public class PreLogicalPlanVerifier extends BaseAlgebraVisitor <PreLogicalPlanVe
     }
 
     if (child != null && child.getType() == OpType.Projection) {
+      Projection projection = (Projection) child;
+      int projectColumnNum = projection.getNamedExprs().length;
+
       if (expr.hasTargetColumns()) {
-        Projection projection = (Projection) child;
-        int projectColumnNum = projection.getNamedExprs().length;
         int targetColumnNum = expr.getTargetColumns().length;
 
         if (targetColumnNum > projectColumnNum)  {
@@ -243,6 +245,25 @@ public class PreLogicalPlanVerifier extends BaseAlgebraVisitor <PreLogicalPlanVe
         } else if (targetColumnNum < projectColumnNum) {
           context.state.addVerification("INSERT has more expressions than target columns");
         }
+      } else {
+        if (expr.hasTableName()) {
+          String qualifiedName = expr.getTableName();
+          if (TajoConstants.EMPTY_STRING.equals(CatalogUtil.extractQualifier(expr.getTableName())))
{
+            qualifiedName = CatalogUtil.buildFQName(context.session.getCurrentDatabase(),
+                expr.getTableName());
+          }
+
+          TableDesc table = catalog.getTableDesc(qualifiedName);
+          if (table.hasPartition()) {
+            int columnSize = table.getSchema().getColumns().size();
+            columnSize += table.getPartitionMethod().getExpressionSchema().getColumns().size();
+            if (projectColumnNum < columnSize) {
+              context.state.addVerification("INSERT has smaller expressions than target columns");
+            } else if (projectColumnNum > columnSize) {
+              context.state.addVerification("INSERT has more expressions than target columns");
+            }
+          }
+        }
       }
     }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/1613cd2c/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
index 0ec7de0..8c989b5 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
@@ -31,6 +31,7 @@ import org.apache.tajo.TajoTestingCluster;
 import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.ipc.ClientProtos;
 import org.junit.Test;
 
 import java.io.IOException;
@@ -59,7 +60,8 @@ public class TestTablePartitions extends QueryTestCaseBase {
     assertEquals(3, catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName).getLogicalSchema().size());
 
     res = testBase.execute(
-        "insert overwrite into " + tableName + " select l_orderkey, l_partkey, l_quantity
from lineitem");
+        "insert overwrite into " + tableName + " select l_orderkey, l_partkey, " +
+            "l_quantity from lineitem");
     res.close();
   }
 
@@ -486,4 +488,83 @@ public class TestTablePartitions extends QueryTestCaseBase {
     assertFalse(res.next());
     res.close();
   }
+
+  @Test
+  public final void testColumnPartitionedTableWithSmallerExpressions1() throws Exception
{
+    String tableName = CatalogUtil.normalizeIdentifier("testColumnPartitionedTableWithSmallerExpressions1");
+    ResultSet res = executeString(
+        "create table " + tableName + " (col1 int4, col2 int4, null_col int4) partition by
column(key float8) ");
+    res.close();
+
+    assertTrue(catalog.existsTable(DEFAULT_DATABASE_NAME, tableName));
+
+    ClientProtos.SubmitQueryResponse response = client.executeQuery("insert overwrite into
" + tableName
+        + " select l_orderkey, l_partkey from lineitem");
+
+    assertTrue(response.hasErrorMessage());
+    assertEquals(response.getErrorMessage(), "INSERT has smaller expressions than target
columns\n");
+
+    res = executeFile("case14.sql");
+    assertResultSet(res, "case14.result");
+    res.close();
+  }
+
+  @Test
+  public final void testColumnPartitionedTableWithSmallerExpressions2() throws Exception
{
+    String tableName = CatalogUtil.normalizeIdentifier("testColumnPartitionedTableWithSmallerExpressions2");
+    ResultSet res = executeString(
+        "create table " + tableName + " (col1 int4, col2 int4, null_col int4) partition by
column(key float8) ");
+    res.close();
+
+    assertTrue(catalog.existsTable(DEFAULT_DATABASE_NAME, tableName));
+
+    ClientProtos.SubmitQueryResponse response = client.executeQuery("insert overwrite into
" + tableName
+        + " select l_returnflag , l_orderkey, l_partkey from lineitem");
+
+    assertTrue(response.hasErrorMessage());
+    assertEquals(response.getErrorMessage(), "INSERT has smaller expressions than target
columns\n");
+
+    res = executeFile("case15.sql");
+    assertResultSet(res, "case15.result");
+    res.close();
+  }
+
+
+  @Test
+  public final void testColumnPartitionedTableWithSmallerExpressions3() throws Exception
{
+    ResultSet res = executeString("create database testinsertquery1;");
+    res.close();
+    res = executeString("create database testinsertquery2;");
+    res.close();
+
+    res = executeString("create table testinsertquery1.table1 " +
+        "(col1 int4, col2 int4, col3 float8)");
+    res.close();
+
+    res = executeString("create table testinsertquery2.table1 " +
+        "(col1 int4, col2 int4, col3 float8)");
+    res.close();
+
+    CatalogService catalog = testingCluster.getMaster().getCatalog();
+    assertTrue(catalog.existsTable("testinsertquery1", "table1"));
+    assertTrue(catalog.existsTable("testinsertquery2", "table1"));
+
+    res = executeString("insert overwrite into testinsertquery1.table1 " +
+        "select l_orderkey, l_partkey, l_quantity from default.lineitem;");
+    res.close();
+
+    TableDesc desc = catalog.getTableDesc("testinsertquery1", "table1");
+    if (!testingCluster.isHCatalogStoreRunning()) {
+      assertEquals(5, desc.getStats().getNumRows().intValue());
+    }
+
+    res = executeString("insert overwrite into testinsertquery2.table1 " +
+        "select col1, col2, col3 from testinsertquery1.table1;");
+    res.close();
+
+    desc = catalog.getTableDesc("testinsertquery2", "table1");
+    if (!testingCluster.isHCatalogStoreRunning()) {
+      assertEquals(5, desc.getStats().getNumRows().intValue());
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/1613cd2c/tajo-core/src/test/resources/queries/TestTablePartitions/case14.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestTablePartitions/case14.sql b/tajo-core/src/test/resources/queries/TestTablePartitions/case14.sql
new file mode 100644
index 0000000..ac1ad20
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestTablePartitions/case14.sql
@@ -0,0 +1,3 @@
+select count(*) as cnt
+  from
+    testColumnPartitionedTableWithSmallerExpressions1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/1613cd2c/tajo-core/src/test/resources/queries/TestTablePartitions/case15.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestTablePartitions/case15.sql b/tajo-core/src/test/resources/queries/TestTablePartitions/case15.sql
new file mode 100644
index 0000000..03cf55b
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestTablePartitions/case15.sql
@@ -0,0 +1,3 @@
+select count(*) as cnt
+  from
+    testColumnPartitionedTableWithSmallerExpressions2
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/1613cd2c/tajo-core/src/test/resources/results/TestTablePartitions/case14.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTablePartitions/case14.result b/tajo-core/src/test/resources/results/TestTablePartitions/case14.result
new file mode 100644
index 0000000..785d264
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTablePartitions/case14.result
@@ -0,0 +1,3 @@
+cnt
+-------------------------------
+0
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/1613cd2c/tajo-core/src/test/resources/results/TestTablePartitions/case15.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTablePartitions/case15.result b/tajo-core/src/test/resources/results/TestTablePartitions/case15.result
new file mode 100644
index 0000000..785d264
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTablePartitions/case15.result
@@ -0,0 +1,3 @@
+cnt
+-------------------------------
+0
\ No newline at end of file


Mime
View raw message