tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject tajo git commit: TAJO-1684: CREATE EXTERNAL TABLE should allows just a path.
Date Mon, 20 Jul 2015 11:48:23 GMT
Repository: tajo
Updated Branches:
  refs/heads/master 5d62c409a -> bdd102c8f


TAJO-1684: CREATE EXTERNAL TABLE should allows just a path.

Closes #629


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

Branch: refs/heads/master
Commit: bdd102c8f7446c43404ec9bd81d576e3be9dc90c
Parents: 5d62c40
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Mon Jul 20 20:46:18 2015 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Mon Jul 20 20:46:18 2015 +0900

----------------------------------------------------------------------
 CHANGES                                             |  2 ++
 .../org/apache/tajo/storage/StorageService.java     |  1 +
 .../org/apache/tajo/master/exec/DDLExecutor.java    | 15 +++++++++++++--
 .../tajo/engine/planner/TestLogicalPlanner.java     |  2 +-
 .../apache/tajo/engine/query/TestCreateTable.java   | 16 ++++++++++++++++
 .../java/org/apache/tajo/plan/LogicalPlanner.java   |  7 ++++++-
 6 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/bdd102c8/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index f90ade9..6804e73 100644
--- a/CHANGES
+++ b/CHANGES
@@ -381,6 +381,8 @@ Release 0.11.0 - unreleased
 
   SUB TASKS
 
+    TAJO-1684: CREATE EXTERNAL TABLE should allows just a path. (hyunsik)
+
     TAJO-1670: Refactor client errors and exceptions. (hyunsik)
 
     TAJO-1514: Distinguish UNION and UNION ALL. (contributed by Keuntae Park,

http://git-wip-us.apache.org/repos/asf/tajo/blob/bdd102c8/tajo-common/src/main/java/org/apache/tajo/storage/StorageService.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/storage/StorageService.java b/tajo-common/src/main/java/org/apache/tajo/storage/StorageService.java
index 1057097..4e5741b 100644
--- a/tajo-common/src/main/java/org/apache/tajo/storage/StorageService.java
+++ b/tajo-common/src/main/java/org/apache/tajo/storage/StorageService.java
@@ -25,6 +25,7 @@ import java.net.URI;
  * TablespaceManager interface for loosely coupled usages
  */
 public interface StorageService {
+
   /**
    * Get Table URI
    *

http://git-wip-us.apache.org/repos/asf/tajo/blob/bdd102c8/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
index b0024dc..f6bb4f7 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
@@ -18,6 +18,7 @@
 
 package org.apache.tajo.master.exec;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -257,9 +258,19 @@ public class DDLExecutor {
 
     Tablespace tableSpace;
     if (tableSpaceName != null) {
-      tableSpace = TablespaceManager.getByName(tableSpaceName).get();
+      Optional<Tablespace> ts = (Optional<Tablespace>) TablespaceManager.getByName(tableSpaceName);
+      if (ts.isPresent()) {
+        tableSpace = ts.get();
+      } else {
+        throw new IOException("Tablespace '" + tableSpaceName + "' does not exist");
+      }
     } else if (uri != null) {
-      tableSpace = TablespaceManager.get(uri).get();
+      Optional<Tablespace> ts = TablespaceManager.get(uri);
+      if (ts.isPresent()) {
+        tableSpace = ts.get();
+      } else {
+        throw new IOException("Unknown tablespace URI: " + uri);
+      }
     } else {
       tableSpace = TablespaceManager.getDefault();
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/bdd102c8/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
b/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
index fb0579c..d1b0c37 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java
@@ -991,7 +991,7 @@ public class TestLogicalPlanner {
     assertEquals("score", def.getColumn(3).getSimpleName());
     assertEquals(Type.FLOAT4, def.getColumn(3).getDataType().getType());
     assertTrue("CSV".equalsIgnoreCase(createTable.getStorageType()));
-    assertEquals("/tmp/data", createTable.getUri().toString());
+    assertEquals("file://tmp/data", createTable.getUri().toString());
     assertTrue(createTable.hasOptions());
     assertEquals("|", createTable.getOptions().get("csv.delimiter"));
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/bdd102c8/tajo-core/src/test/java/org/apache/tajo/engine/query/TestCreateTable.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestCreateTable.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestCreateTable.java
index b19a488..dfdf09a 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestCreateTable.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestCreateTable.java
@@ -441,6 +441,22 @@ public class TestCreateTable extends QueryTestCaseBase {
   }
 
   @Test
+  public final void testCreateExternalTable1FromOnlyPath() throws Exception {
+    // This test verifies CREATE EXTERNAL TABLE from just a path instead of a full qualified
URI.
+    ResultSet res = null;
+    try {
+      res = executeString(
+          "INSERT INTO LOCATION '/testCreateExternalTable1FromOnlyPath' SELECT * FROM default.lineitem");
+      res = executeString(
+          "CREATE EXTERNAL TABLE table1 (col1 INTEGER) USING CSV LOCATION '/testCreateExternalTable1FromOnlyPath';");
+    } catch (Throwable t) {
+      if (res != null) {
+        res.close();
+      }
+    }
+  }
+
+  @Test
   public final void testCreateTableLike1() throws Exception {
     // //HiveCatalogStore does not support varchar type in hive-0.12.0
     if (testingCluster.isHiveCatalogStoreRunning()) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/bdd102c8/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 a67fdd4..ef8663d 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
@@ -1956,7 +1956,12 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
   private URI getCreatedTableURI(PlanContext context, CreateTable createTable) {
 
     if (createTable.hasLocation()) {
-      return URI.create(createTable.getLocation());
+      URI tableUri = URI.create(createTable.getLocation());
+      if (tableUri.getScheme() == null) { // if a given table URI is a just path, the default
tablespace will be added.
+        tableUri = URI.create(context.queryContext.get(QueryVars.DEFAULT_SPACE_ROOT_URI)
+ createTable.getLocation());
+      }
+      return tableUri;
+
     } else {
 
       String tableName = createTable.getTableName();


Mime
View raw message