tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject git commit: TAJO-792: Insert table error with database name. (Hyoungjun Kim via hyunsik)
Date Wed, 30 Apr 2014 11:21:35 GMT
Repository: tajo
Updated Branches:
  refs/heads/master bd032094c -> 08bcc2d82


TAJO-792: Insert table error with database name. (Hyoungjun Kim via hyunsik)


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

Branch: refs/heads/master
Commit: 08bcc2d8282fd3b066ed37eafc2c2b142227015d
Parents: bd03209
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Wed Apr 30 20:20:32 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Wed Apr 30 20:20:32 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 +++
 .../tajo/engine/planner/LogicalPlanner.java     | 17 ++++++++++++----
 .../org/apache/tajo/master/GlobalEngine.java    |  2 +-
 .../tajo/engine/query/TestInsertQuery.java      | 21 ++++++++++++++++++--
 .../testInsertOverwriteWithDatabase.sql         |  1 +
 5 files changed, 37 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/08bcc2d8/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 7ac546e..f1bacf4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,9 @@ Release 0.9.0 - unreleased
 
   BUG FIXES
 
+    TAJO-792: Insert table error with database name. 
+    (Hyoungjun Kim via hyunsik)
+
     TAJO-806: CreateTableNode in CTAS uses a wrong schema as output schema and 
     table schema. (hyunsik)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/08bcc2d8/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
index 1c63354..63ac515 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
@@ -1153,15 +1153,24 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
    *
    * We use the following terms, such target table, target column
    * <pre>
-   * INSERT INTO    TB_NAME        (col1, col2)          SELECT    c1,   c2        FROM ...
-   *                ^^^^^^^        ^^^^^^^^^^^^                  ^^^^^^^^^^^^
-   *             target table   target columns (or schema)     projected columns (or schema)
+   * INSERT INTO    [DATABASE_NAME.]TB_NAME        (col1, col2)          SELECT    c1,  
c2        FROM ...
+   *                 ^^^^^^^^^^^^^^ ^^^^^^^        ^^^^^^^^^^^^                  ^^^^^^^^^^^^
+   *               target database target table  target columns (or schema)     projected
columns (or schema)
    * </pre>
    */
   private InsertNode buildInsertIntoTablePlan(PlanContext context, InsertNode insertNode,
Insert expr)
       throws PlanningException {
     // Get and set a target table
-    TableDesc desc = catalog.getTableDesc(context.session.getCurrentDatabase(), expr.getTableName());
+    String databaseName;
+    String tableName;
+    if (CatalogUtil.isFQTableName(expr.getTableName())) {
+      databaseName = CatalogUtil.extractQualifier(expr.getTableName());
+      tableName = CatalogUtil.extractSimpleName(expr.getTableName());
+    } else {
+      databaseName = context.session.getCurrentDatabase();
+      tableName = expr.getTableName();
+    }
+    TableDesc desc = catalog.getTableDesc(databaseName, tableName);
     insertNode.setTargetTable(desc);
 
     //

http://git-wip-us.apache.org/repos/asf/tajo/blob/08bcc2d8/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java b/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
index 35b8ab8..c87ad84 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
@@ -289,7 +289,7 @@ public class GlobalEngine extends AbstractService {
         return QueryIdFactory.NULL_QUERY_ID;
       }
     } catch (Exception e) {
-      e.printStackTrace();
+      LOG.error(e.getMessage(), e);
       throw new IOException(e.getMessage(), e);
     }
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/08bcc2d8/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java
index c7df75c..06ce973 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java
@@ -34,7 +34,6 @@ import org.junit.experimental.categories.Category;
 
 import java.sql.ResultSet;
 
-import static org.apache.tajo.TajoConstants.DEFAULT_DATABASE_NAME;
 import static org.junit.Assert.*;
 
 @Category(IntegrationTest.class)
@@ -256,7 +255,8 @@ public class TestInsertQuery extends QueryTestCaseBase {
       CatalogService catalog = testingCluster.getMaster().getCatalog();
       assertTrue(catalog.existsTable(getCurrentDatabase(), "full_table_parquet"));
 
-      res = executeString("insert overwrite into full_table_parquet select * from default.lineitem
where l_orderkey = 3");
+      res = executeString(
+          "insert overwrite into full_table_parquet select * from default.lineitem where
l_orderkey = 3");
       res.close();
       TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), "full_table_parquet");
       if (!testingCluster.isHCatalogStoreRunning()) {
@@ -272,4 +272,21 @@ public class TestInsertQuery extends QueryTestCaseBase {
       executeString("DROP TABLE full_table_parquet_ddl PURGE");
     }
   }
+
+  @Test
+  public final void testInsertOverwriteWithDatabase() throws Exception {
+    ResultSet res = executeFile("table1_ddl.sql");
+    res.close();
+
+    CatalogService catalog = testingCluster.getMaster().getCatalog();
+    assertTrue(catalog.existsTable(getCurrentDatabase(), "table1"));
+
+    res = executeQuery();
+    res.close();
+
+    TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), "table1");
+    if (!testingCluster.isHCatalogStoreRunning()) {
+      assertEquals(5, desc.getStats().getNumRows().intValue());
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/08bcc2d8/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithDatabase.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithDatabase.sql
b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithDatabase.sql
new file mode 100644
index 0000000..db18c0e
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithDatabase.sql
@@ -0,0 +1 @@
+insert overwrite into table1 select l_orderkey, l_partkey, l_quantity from default.lineitem;
\ No newline at end of file


Mime
View raw message