You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2014/03/25 02:36:28 UTC

[13/13] git commit: TAJO-353: Add Database support to Tajo. (hyunsik)

TAJO-353: Add Database support to Tajo. (hyunsik)


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

Branch: refs/heads/master
Commit: 3ba262412cfef82943de7f2c831916b340c01925
Parents: 7283c58
Author: Hyunsik Choi <hy...@apache.org>
Authored: Thu Mar 20 21:18:18 2014 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Thu Mar 20 21:20:38 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |    2 +
 .../tajo/algebra/ColumnReferenceExpr.java       |    5 +-
 .../org/apache/tajo/algebra/CreateDatabase.java |   65 +
 .../org/apache/tajo/algebra/CreateTable.java    |   19 +-
 .../org/apache/tajo/algebra/DropDatabase.java   |   52 +
 .../java/org/apache/tajo/algebra/DropTable.java |   14 +-
 .../java/org/apache/tajo/algebra/OpType.java    |    2 +
 .../tajo/catalog/AbstractCatalogClient.java     |  278 +++-
 .../org/apache/tajo/catalog/CatalogService.java |  100 +-
 .../src/main/proto/CatalogProtocol.proto        |   39 +-
 .../apache/tajo/catalog/CatalogConstants.java   |    7 +-
 .../org/apache/tajo/catalog/CatalogUtil.java    |   94 +-
 .../org/apache/tajo/catalog/DDLBuilder.java     |   23 +-
 .../org/apache/tajo/catalog/FunctionDesc.java   |    2 +-
 .../java/org/apache/tajo/catalog/IndexDesc.java |   57 +-
 .../java/org/apache/tajo/catalog/TableDesc.java |   45 +-
 .../AlreadyExistsDatabaseException.java         |   30 +
 .../exception/AlreadyExistsIndexException.java  |   24 +-
 .../exception/AlreadyExistsTableException.java  |    6 +-
 .../AlreadyExistsTablespaceException.java       |   30 +
 .../exception/InvalidTableException.java        |   36 -
 .../exception/NoPartitionedTableException.java  |   28 +
 .../exception/NoSuchDatabaseException.java      |   30 +
 .../exception/NoSuchFunctionException.java      |    4 +-
 .../catalog/exception/NoSuchIndexException.java |   25 +-
 .../catalog/exception/NoSuchTableException.java |    4 +
 .../exception/NoSuchTablespaceException.java    |   29 +
 .../tajo/catalog/partition/PartitionDesc.java   |   46 +-
 .../catalog/partition/PartitionMethodDesc.java  |   53 +-
 .../src/main/proto/CatalogProtos.proto          |   79 +-
 .../apache/tajo/catalog/TestCatalogUtil.java    |    3 +-
 .../org/apache/tajo/catalog/TestIndexDesc.java  |   21 +-
 .../org/apache/tajo/catalog/TestTableDesc.java  |    4 +-
 .../tajo/catalog/store/HCatalogStore.java       |  264 ++--
 .../catalog/store/HCatalogStoreClientPool.java  |    3 +-
 .../apache/tajo/catalog/store/HCatalogUtil.java |   46 +-
 .../tajo/catalog/store/TestHCatalogStore.java   |  119 +-
 .../org/apache/tajo/catalog/CatalogServer.java  |  448 ++++--
 .../tajo/catalog/store/AbstractDBStore.java     | 1390 +++++++++++-------
 .../apache/tajo/catalog/store/CatalogStore.java |   64 +-
 .../apache/tajo/catalog/store/DerbyStore.java   |  318 ++--
 .../org/apache/tajo/catalog/store/MemStore.java |  290 ++--
 .../apache/tajo/catalog/store/MySQLStore.java   |  151 +-
 .../src/main/resources/schemas/common/meta.sql  |    1 +
 .../main/resources/schemas/derby/columns.sql    |    8 +
 .../main/resources/schemas/derby/databases.sql  |    6 +
 .../resources/schemas/derby/databases_idx.sql   |    1 +
 .../main/resources/schemas/derby/indexes.sql    |   12 +
 .../schemas/derby/partition_methods.sql         |    6 +
 .../main/resources/schemas/derby/partitions.sql |   10 +
 .../src/main/resources/schemas/derby/stats.sql  |    6 +
 .../schemas/derby/table_properties.sql          |    6 +
 .../src/main/resources/schemas/derby/tables.sql |   10 +
 .../resources/schemas/derby/tablespaces.sql     |    7 +
 .../main/resources/schemas/mysql/columns.sql    |    9 +
 .../main/resources/schemas/mysql/databases.sql  |    7 +
 .../main/resources/schemas/mysql/indexes.sql    |   16 +
 .../schemas/mysql/partition_methods.sql         |    7 +
 .../main/resources/schemas/mysql/partitions.sql |   12 +
 .../src/main/resources/schemas/mysql/stats.sql  |    6 +
 .../schemas/mysql/table_properties.sql          |    7 +
 .../src/main/resources/schemas/mysql/tables.sql |   11 +
 .../resources/schemas/mysql/tablespaces.sql     |    7 +
 .../org/apache/tajo/catalog/TestCatalog.java    |  388 +++--
 .../tajo/catalog/TestCatalogConstants.java      |   46 -
 .../org/apache/tajo/catalog/TestDBStore.java    |  403 -----
 .../apache/tajo/cli/ConnectDatabaseCommand.java |   65 +
 .../org/apache/tajo/cli/CopyrightCommand.java   |   14 +-
 .../apache/tajo/cli/DescFunctionCommand.java    |   24 +-
 .../org/apache/tajo/cli/DescTableCommand.java   |   16 +-
 .../java/org/apache/tajo/cli/ExitCommand.java   |   10 +-
 .../java/org/apache/tajo/cli/HelpCommand.java   |   44 +-
 .../tajo/cli/InvalidClientSessionException.java |   27 +
 .../tajo/cli/InvalidStatementException.java     |   25 +
 .../apache/tajo/cli/ListDatabaseCommand.java    |   48 +
 .../java/org/apache/tajo/cli/ParsedResult.java  |   47 +
 .../java/org/apache/tajo/cli/SetCommand.java    |   61 +
 .../java/org/apache/tajo/cli/SimpleParser.java  |  262 ++++
 .../main/java/org/apache/tajo/cli/TajoCli.java  |  324 ++--
 .../org/apache/tajo/cli/TajoFileHistory.java    |   39 +
 .../org/apache/tajo/cli/TajoShellCommand.java   |   28 +-
 .../java/org/apache/tajo/cli/UnsetCommand.java  |   52 +
 .../org/apache/tajo/cli/VersionCommand.java     |    9 +-
 .../java/org/apache/tajo/client/TajoClient.java |  309 +++-
 .../java/org/apache/tajo/client/TajoDump.java   |   95 +-
 .../org/apache/tajo/jdbc/TajoResultSetBase.java |    4 +
 .../apache/tajo/jdbc/TajoResultSetMetaData.java |   10 +-
 tajo-client/src/main/proto/ClientProtos.proto   |   44 +-
 .../main/proto/TajoMasterClientProtocol.proto   |   49 +-
 .../java/org/apache/tajo/TajoConstants.java     |    5 +
 .../java/org/apache/tajo/conf/TajoConf.java     |    5 +
 .../org/apache/tajo/util/CommonTestingUtil.java |    3 +-
 .../java/org/apache/tajo/util/FileUtil.java     |   22 +-
 .../main/java/org/apache/tajo/util/Pair.java    |   37 +
 .../java/org/apache/tajo/util/ProtoBufUtil.java |   26 -
 .../java/org/apache/tajo/util/ProtoUtil.java    |   42 +
 .../java/org/apache/tajo/util/StringUtils.java  |    8 +
 .../main/java/org/apache/tajo/util/TUtil.java   |   12 +
 .../src/main/proto/PrimitiveProtos.proto        |    4 +
 tajo-common/src/main/proto/TajoIdProtos.proto   |    2 +-
 tajo-core/tajo-core-backend/pom.xml             |  210 ++-
 .../org/apache/tajo/engine/parser/SQLLexer.g4   |    2 +
 .../org/apache/tajo/engine/parser/SQLParser.g4  |   28 +-
 .../tajo/engine/parser/HiveQLAnalyzer.java      |    4 +-
 .../apache/tajo/engine/parser/SQLAnalyzer.java  |   14 +-
 .../tajo/engine/planner/AlgebraVisitor.java     |    2 +
 .../tajo/engine/planner/BaseAlgebraVisitor.java |   16 +
 .../engine/planner/BasicLogicalPlanVisitor.java |   17 +
 .../planner/ExplainLogicalPlanVisitor.java      |   14 +-
 .../tajo/engine/planner/ExprNormalizer.java     |    3 +-
 .../apache/tajo/engine/planner/LogicalPlan.java |   34 +-
 .../engine/planner/LogicalPlanPreprocessor.java |   53 +-
 .../engine/planner/LogicalPlanVerifier.java     |   96 +-
 .../tajo/engine/planner/LogicalPlanVisitor.java |    6 +
 .../tajo/engine/planner/LogicalPlanner.java     |   65 +-
 .../apache/tajo/engine/planner/PlannerUtil.java |   12 +-
 .../engine/planner/PreLogicalPlanVerifier.java  |  129 +-
 .../tajo/engine/planner/VerificationState.java  |    5 +
 .../engine/planner/global/GlobalPlanner.java    |    5 +-
 .../planner/logical/CreateDatabaseNode.java     |   85 ++
 .../engine/planner/logical/CreateTableNode.java |   37 +-
 .../planner/logical/DropDatabaseNode.java       |   85 ++
 .../engine/planner/logical/DropTableNode.java   |   25 +-
 .../tajo/engine/planner/logical/NodeType.java   |    3 +
 .../tajo/engine/planner/logical/ScanNode.java   |   21 +-
 .../apache/tajo/engine/query/QueryContext.java  |    1 -
 .../org/apache/tajo/engine/utils/ProtoUtil.java |   29 -
 .../org/apache/tajo/master/GlobalEngine.java    |  198 ++-
 .../java/org/apache/tajo/master/TajoMaster.java |   43 +-
 .../tajo/master/TajoMasterClientService.java    |  709 ++++++---
 .../tajo/master/YarnTaskRunnerLauncherImpl.java |    2 +-
 .../tajo/master/event/QueryStartEvent.java      |   18 +-
 .../master/metrics/CatalogMetricsGaugeSet.java  |    4 +-
 .../apache/tajo/master/querymaster/Query.java   |   38 +-
 .../master/querymaster/QueryInProgress.java     |    6 +
 .../master/querymaster/QueryJobManager.java     |    6 +-
 .../tajo/master/querymaster/QueryMaster.java    |    2 +-
 .../querymaster/QueryMasterManagerService.java  |    2 +
 .../master/querymaster/QueryMasterTask.java     |   16 +-
 .../tajo/master/rm/TajoResourceTracker.java     |    4 +-
 .../master/session/InvalidSessionException.java |   25 +
 .../session/NoSuchSessionVariableException.java |   25 +
 .../org/apache/tajo/master/session/Session.java |  124 ++
 .../tajo/master/session/SessionConstants.java   |   23 +
 .../tajo/master/session/SessionEvent.java       |   34 +
 .../tajo/master/session/SessionEventType.java   |   24 +
 .../session/SessionLivelinessMonitor.java       |   53 +
 .../tajo/master/session/SessionManager.java     |  139 ++
 .../src/main/proto/TajoWorkerProtocol.proto     |   15 +-
 .../resources/webapps/admin/catalogview.jsp     |   16 +-
 .../apache/tajo/LocalTajoTestingUtility.java    |   22 +-
 .../java/org/apache/tajo/QueryTestCaseBase.java |  160 +-
 .../org/apache/tajo/TajoTestingCluster.java     |   62 +-
 .../org/apache/tajo/benchmark/TestTPCH.java     |    6 +
 .../org/apache/tajo/cli/TestSimpleParser.java   |  164 +++
 .../org/apache/tajo/client/TestDDLBuilder.java  |   43 +-
 .../org/apache/tajo/client/TestTajoClient.java  |  141 +-
 .../apache/tajo/engine/eval/ExprTestBase.java   |   44 +-
 .../tajo/engine/eval/TestEvalTreeUtil.java      |   60 +-
 .../engine/function/TestBuiltinFunctions.java   |    6 +
 .../engine/planner/TestLogicalOptimizer.java    |   42 +-
 .../tajo/engine/planner/TestLogicalPlan.java    |    9 +-
 .../tajo/engine/planner/TestLogicalPlanner.java |  151 +-
 .../tajo/engine/planner/TestPlannerUtil.java    |   46 +-
 .../planner/physical/TestBNLJoinExec.java       |   25 +-
 .../planner/physical/TestBSTIndexExec.java      |   16 +-
 .../planner/physical/TestExternalSortExec.java  |   12 +-
 .../physical/TestFullOuterHashJoinExec.java     |   50 +-
 .../physical/TestFullOuterMergeJoinExec.java    |   83 +-
 .../planner/physical/TestHashAntiJoinExec.java  |   22 +-
 .../planner/physical/TestHashJoinExec.java      |   36 +-
 .../planner/physical/TestHashSemiJoinExec.java  |   22 +-
 .../physical/TestLeftOuterHashJoinExec.java     |   57 +-
 .../physical/TestLeftOuterNLJoinExec.java       |   57 +-
 .../planner/physical/TestMergeJoinExec.java     |   18 +-
 .../engine/planner/physical/TestNLJoinExec.java |   26 +-
 .../planner/physical/TestPhysicalPlanner.java   |  115 +-
 .../physical/TestProgressExternalSortExec.java  |   15 +-
 .../physical/TestRightOuterHashJoinExec.java    |   44 +-
 .../physical/TestRightOuterMergeJoinExec.java   |   78 +-
 .../engine/planner/physical/TestSortExec.java   |   11 +-
 .../apache/tajo/engine/query/TestCTASQuery.java |   28 +-
 .../tajo/engine/query/TestCaseByCases.java      |    6 +
 .../tajo/engine/query/TestCreateDatabase.java   |   72 +
 .../tajo/engine/query/TestCreateTable.java      |  313 ++--
 .../tajo/engine/query/TestGroupByQuery.java     |    6 +
 .../tajo/engine/query/TestInsertQuery.java      |   71 +-
 .../query/TestJoinOnPartitionedTables.java      |    6 +
 .../apache/tajo/engine/query/TestJoinQuery.java |   22 +-
 .../apache/tajo/engine/query/TestNetTypes.java  |   63 +-
 .../tajo/engine/query/TestSelectQuery.java      |   14 +-
 .../apache/tajo/engine/query/TestSortQuery.java |   23 +-
 .../tajo/engine/query/TestTablePartitions.java  |   68 +-
 .../tajo/engine/query/TestTableSubQuery.java    |    5 +
 .../tajo/engine/query/TestUnionQuery.java       |    5 +
 .../org/apache/tajo/jdbc/TestResultSet.java     |    4 +-
 .../java/org/apache/tajo/jdbc/TestTajoJdbc.java |  182 ++-
 .../tajo/master/TestExecutionBlockCursor.java   |   16 +-
 .../apache/tajo/master/TestGlobalPlanner.java   |   13 +-
 .../querymaster/TestQueryUnitStatusUpdate.java  |   18 +-
 .../tajo/worker/TestRangeRetrieverHandler.java  |   25 +-
 .../dataset/TestCreateTable/table1.tbl          |    3 -
 .../dataset/TestCreateTable/table1/table1.tbl   |    3 +
 .../resources/dataset/TestJoinQuery/table1.tbl  |    5 -
 .../dataset/TestJoinQuery/table1/table1.tbl     |    5 +
 .../resources/dataset/TestJoinQuery/table2.tbl  |    4 -
 .../dataset/TestJoinQuery/table2/table2.tbl     |    4 +
 .../resources/dataset/TestNetTypes/table1.tbl   |    5 -
 .../dataset/TestNetTypes/table1/table1.tbl      |    5 +
 .../resources/dataset/TestNetTypes/table2.tbl   |    4 -
 .../dataset/TestNetTypes/table2/table2.tbl      |    4 +
 .../resources/dataset/TestSortQuery/table1.tbl  |    5 -
 .../dataset/TestSortQuery/table1/table1.tbl     |    5 +
 .../resources/dataset/TestSortQuery/table2.tbl  |   24 -
 .../dataset/TestSortQuery/table2/table2.tbl     |   24 +
 .../create_table_various_types.sql              |    2 +
 .../create_table_various_types_for_hcatalog.sql |   50 +
 .../testCrossJoinWithAsterisk1.sql              |    2 +-
 .../testCrossJoinWithAsterisk2.sql              |    2 +-
 .../testCrossJoinWithAsterisk3.sql              |    2 +-
 .../testCrossJoinWithAsterisk4.sql              |    2 +-
 .../testJoinOnMultipleDatabases.sql             |   25 +
 .../queries/TestNetTypes/table1_ddl.sql         |    2 +-
 .../queries/TestNetTypes/table2_ddl.sql         |    2 +-
 .../testCrossJoinWithAsterisk3.result           |   52 +-
 .../testCrossJoinWithAsterisk4.result           |   52 +-
 .../testJoinOnMultipleDatabases.result          |    5 +
 .../results/TestTajoJdbc/getTables1.result      |    4 +
 .../results/TestTajoJdbc/getTables2.result      |    4 +
 .../test/resources/results/testBuildDDL.result  |    5 -
 .../results/testBuildDDLForBaseTable.result     |    5 +
 .../results/testBuildDDLForExternalTable.result |    5 +
 tajo-docs/src/main/sphinx/cli.rst               |   96 +-
 .../configuration/catalog_configuration.rst     |   16 +-
 .../main/sphinx/configuration/cluster_setup.rst |    2 +-
 tajo-docs/src/main/sphinx/sql_language/ddl.rst  |   37 +-
 .../org/apache/tajo/jdbc/TajoConnection.java    |  137 +-
 .../apache/tajo/jdbc/TajoDatabaseMetaData.java  |   90 +-
 tajo-project/pom.xml                            |    2 +-
 239 files changed, 9000 insertions(+), 3944 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0304190..7b379b3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-353: Add Database support to Tajo. (hyunsik)
+
     TAJO-574: Add a sort-based physical executor for column partition store.
     (hyunsik)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
index 97a6a3a..e1369df 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
@@ -55,12 +55,9 @@ public class ColumnReferenceExpr extends Expr {
   public void setName(String qualifiedName) {
     String [] parts = qualifiedName.toLowerCase().split("\\.");
 
-    if (parts.length == 3) {
+    if (parts.length > 1) {
       qualifier = qualifiedName.substring(0, qualifiedName.lastIndexOf("."));
       name = qualifiedName.substring(qualifiedName.lastIndexOf(".") + 1, qualifiedName.length());
-    } else if (parts.length == 2) {
-      qualifier = parts[0];
-      name = parts[1];
     } else {
       name = parts[0];
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateDatabase.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateDatabase.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateDatabase.java
new file mode 100644
index 0000000..a4ebc84
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateDatabase.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.algebra;
+
+import com.google.common.base.Objects;
+import org.apache.tajo.util.TUtil;
+
+public class CreateDatabase extends Expr {
+  private String databaseName;
+  private String tablespaceName;
+  private boolean ifNotExists;
+
+  public CreateDatabase(final String databaseName, final String tablespaceName, final boolean ifNotExists) {
+    super(OpType.CreateDatabase);
+    this.databaseName = databaseName;
+    this.tablespaceName = tablespaceName;
+    this.ifNotExists = ifNotExists;
+  }
+
+  public String getDatabaseName() {
+    return this.databaseName;
+  }
+
+  public boolean hasTablespaceName() {
+    return tablespaceName != null;
+  }
+
+  public String getTablespaceName() {
+    return tablespaceName;
+  }
+
+  public boolean isIfNotExists() {
+    return ifNotExists;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hashCode(databaseName, tablespaceName, ifNotExists);
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    CreateDatabase another = (CreateDatabase) expr;
+    return databaseName.equals(another.databaseName) &&
+        TUtil.checkEquals(tablespaceName, another.tablespaceName) &&
+        ifNotExists == another.ifNotExists;
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java
index 7ad802c..42dcc68 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java
@@ -33,14 +33,16 @@ public class CreateTable extends Expr {
   private Expr subquery;
   private Map<String, String> params;
   private PartitionMethodDescExpr partition;
+  private boolean ifNotExists;
 
-  public CreateTable(final String tableName) {
+  public CreateTable(final String tableName, boolean ifNotExists) {
     super(OpType.CreateTable);
     this.tableName = tableName;
+    this.ifNotExists = ifNotExists;
   }
 
-  public CreateTable(final String tableName, final Expr subQuery) {
-    this(tableName);
+  public CreateTable(final String tableName, final Expr subQuery, boolean ifNotExists) {
+    this(tableName, ifNotExists);
     this.subquery = subQuery;
   }
 
@@ -128,11 +130,15 @@ public class CreateTable extends Expr {
     return subquery;
   }
 
+  public boolean isIfNotExists() {
+    return ifNotExists;
+  }
+
   @Override
   public int hashCode() {
     return Objects.hashCode(
         external, tableName, Objects.hashCode(tableElements),
-        storageType, subquery, location, params, partition);
+        storageType, subquery, location, params, partition, ifNotExists);
   }
 
   @Override
@@ -145,7 +151,8 @@ public class CreateTable extends Expr {
         TUtil.checkEquals(location, another.location) &&
         TUtil.checkEquals(subquery, another.subquery) &&
         TUtil.checkEquals(params, another.params) &&
-        TUtil.checkEquals(partition, another.partition);
+        TUtil.checkEquals(partition, another.partition) &&
+        ifNotExists == another.ifNotExists;
   }
 
   public static class ColumnDefinition extends DataTypeExpr {
@@ -444,7 +451,7 @@ public class CreateTable extends Expr {
 
     public boolean equals(Object obj) {
       if (obj instanceof PartitionSpecifier ) {
-        return name == ((PartitionSpecifier)obj).name;
+        return name.equals(((PartitionSpecifier)obj).name);
       } else {
         return false;
       }

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropDatabase.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropDatabase.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropDatabase.java
new file mode 100644
index 0000000..88e799c
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropDatabase.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.algebra;
+
+import com.google.common.base.Objects;
+import com.google.gson.annotations.Expose;
+
+public class DropDatabase extends Expr {
+  @Expose private String databaseName;
+  @Expose private boolean ifExists;
+
+  public DropDatabase(final String databaseName, final boolean ifExists) {
+    super(OpType.DropDatabase);
+    this.databaseName = databaseName;
+    this.ifExists = ifExists;
+  }
+
+  public String getDatabaseName() {
+    return this.databaseName;
+  }
+
+  public boolean isIfExists() {
+    return ifExists;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hashCode(databaseName, ifExists);
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    DropDatabase another = (DropDatabase) expr;
+    return databaseName.equals(another.databaseName) && ifExists == another.ifExists;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java
index 83e1707..cb0bbf4 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java
@@ -22,11 +22,13 @@ import com.google.common.base.Objects;
 
 public class DropTable extends Expr {
   private final String tableName;
+  private final boolean ifExists;
   private final boolean purge;
 
-  public DropTable(String tableName, boolean purge) {
+  public DropTable(String tableName, boolean ifExists, boolean purge) {
     super(OpType.DropTable);
     this.tableName = tableName;
+    this.ifExists = ifExists;
     this.purge = purge;
   }
 
@@ -34,20 +36,26 @@ public class DropTable extends Expr {
     return this.tableName;
   }
 
+  public boolean isIfExists() {
+    return ifExists;
+  }
+
   public boolean isPurge() {
     return purge;
   }
 
   @Override
   public int hashCode() {
-    return Objects.hashCode(tableName, purge);
+    return Objects.hashCode(tableName, ifExists, purge);
   }
 
   @Override
   boolean equalsTo(Expr expr) {
     if (expr instanceof DropTable) {
       DropTable another = (DropTable) expr;
-      return tableName.equals(another.tableName) && purge == another.purge;
+      return tableName.equals(another.tableName) &&
+          ifExists == another.ifExists &&
+          purge == another.purge;
     }
     return false;
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
index 7122af8..c4a007a 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
@@ -42,6 +42,8 @@ public enum OpType {
   ScalarSubQuery(ScalarSubQuery.class),
 
   // Data definition language
+  CreateDatabase(CreateDatabase.class),
+  DropDatabase(DropDatabase.class),
   CreateTable(CreateTable.class),
   DropTable(DropTable.class),
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
index 1932db5..6ee788c 100644
--- a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
+++ b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
@@ -21,6 +21,7 @@ package org.apache.tajo.catalog;
 import com.google.protobuf.ServiceException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.catalog.CatalogProtocol.CatalogProtocolService;
 import org.apache.tajo.catalog.exception.NoSuchFunctionException;
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
@@ -30,8 +31,9 @@ import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.rpc.NettyClientBase;
 import org.apache.tajo.rpc.RpcConnectionPool;
 import org.apache.tajo.rpc.ServerCallable;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
 import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.NullProto;
-import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringProto;
+import org.apache.tajo.util.ProtoUtil;
 
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
@@ -57,12 +59,148 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final TableDesc getTableDesc(final String name) {
+  public final Boolean createTablespace(final String tablespaceName, final String tablespaceUri) {
+    try {
+      return new ServerCallable<Boolean>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Boolean call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+
+          CreateTablespaceRequest.Builder builder = CreateTablespaceRequest.newBuilder();
+          builder.setTablespaceName(tablespaceName);
+          builder.setTablespaceUri(tablespaceUri);
+          return stub.createTablespace(null, builder.build()).getValue();
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return Boolean.FALSE;
+    }
+  }
+
+  @Override
+  public final Boolean dropTablespace(final String tablespaceName) {
+    try {
+      return new ServerCallable<Boolean>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Boolean call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          return stub.dropTablespace(null, ProtoUtil.convertString(tablespaceName)).getValue();
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return Boolean.FALSE;
+    }
+  }
+
+  @Override
+  public final Boolean existTablespace(final String tablespaceName) {
+    try {
+      return new ServerCallable<Boolean>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Boolean call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          return stub.existTablespace(null, ProtoUtil.convertString(tablespaceName)).getValue();
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return Boolean.FALSE;
+    }
+  }
+
+  @Override
+  public final Collection<String> getAllTablespaceNames() {
+    try {
+      return new ServerCallable<Collection<String>>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Collection<String> call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          PrimitiveProtos.StringListProto response = stub.getAllTablespaceNames(null, ProtoUtil.NULL_PROTO);
+          return ProtoUtil.convertStrings(response);
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return null;
+    }
+  }
+
+  @Override
+  public final Boolean createDatabase(final String databaseName, @Nullable final String tablespaceName) {
+    try {
+      return new ServerCallable<Boolean>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Boolean call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+
+          CreateDatabaseRequest.Builder builder = CreateDatabaseRequest.newBuilder();
+          builder.setDatabaseName(databaseName);
+          if (tablespaceName != null) {
+            builder.setTablespaceName(tablespaceName);
+          }
+          return stub.createDatabase(null, builder.build()).getValue();
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return Boolean.FALSE;
+    }
+  }
+
+  @Override
+  public final Boolean dropDatabase(final String databaseName) {
+    try {
+      return new ServerCallable<Boolean>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Boolean call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          return stub.dropDatabase(null, ProtoUtil.convertString(databaseName)).getValue();
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return Boolean.FALSE;
+    }
+  }
+
+  @Override
+  public final Boolean existDatabase(final String databaseName) {
+    try {
+      return new ServerCallable<Boolean>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Boolean call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          return stub.existDatabase(null, ProtoUtil.convertString(databaseName)).getValue();
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return Boolean.FALSE;
+    }
+  }
+
+  @Override
+  public final Collection<String> getAllDatabaseNames() {
+    try {
+      return new ServerCallable<Collection<String>>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Collection<String> call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          PrimitiveProtos.StringListProto response = stub.getAllDatabaseNames(null, ProtoUtil.NULL_PROTO);
+          return ProtoUtil.convertStrings(response);
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return null;
+    }
+  }
+
+  @Override
+  public final TableDesc getTableDesc(final String databaseName, final String tableName) {
     try {
       return new ServerCallable<TableDesc>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public TableDesc call(NettyClientBase client) throws ServiceException {
+          TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder();
+          builder.setDatabaseName(databaseName);
+          builder.setTableName(tableName);
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return CatalogUtil.newTableDesc(stub.getTableDesc(null, StringProto.newBuilder().setValue(name).build()));
+          return CatalogUtil.newTableDesc(stub.getTableDesc(null, builder.build()));
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -72,13 +210,23 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final PartitionMethodDesc getPartitionMethod(final String tableName) {
+  public TableDesc getTableDesc(String qualifiedName) {
+    String [] splitted = CatalogUtil.splitFQTableName(qualifiedName);
+    return getTableDesc(splitted[0], splitted[1]);
+  }
+
+  @Override
+  public final PartitionMethodDesc getPartitionMethod(final String databaseName, final String tableName) {
     try {
       return new ServerCallable<PartitionMethodDesc>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public PartitionMethodDesc call(NettyClientBase client) throws ServiceException {
+
+          TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder();
+          builder.setDatabaseName(databaseName);
+          builder.setTableName(tableName);
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return CatalogUtil.newPartitionMethodDesc(stub.getPartitionMethodByTableName(null,
-              StringProto.newBuilder().setValue(tableName).build()));
+          return CatalogUtil.newPartitionMethodDesc(stub.getPartitionMethodByTableName(null,  builder.build()));
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -88,13 +236,17 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final boolean existPartitionMethod(final String tableId) {
+  public final boolean existPartitionMethod(final String databaseName, final String tableName) {
     try {
       return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Boolean call(NettyClientBase client) throws ServiceException {
+
+          TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder();
+          builder.setDatabaseName(databaseName);
+          builder.setTableName(tableName);
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return stub.existPartitionMethod(null, StringProto.newBuilder().
-              setValue(tableId).build()).getValue();
+          return stub.existPartitionMethod(null, builder.build()).getValue();
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -104,19 +256,13 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final Collection<String> getAllTableNames() {
+  public final Collection<String> getAllTableNames(final String databaseName) {
     try {
       return new ServerCallable<Collection<String>>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Collection<String> call(NettyClientBase client) throws ServiceException {
-          List<String> protos = new ArrayList<String>();
-          GetAllTableNamesResponse response;
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          response = stub.getAllTableNames(null, NullProto.newBuilder().build());
-          int size = response.getTableNameCount();
-          for (int i = 0; i < size; i++) {
-            protos.add(response.getTableName(i));
-          }
-          return protos;
+          PrimitiveProtos.StringListProto response = stub.getAllTableNames(null, ProtoUtil.convertString(databaseName));
+          return ProtoUtil.convertStrings(response);
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -153,12 +299,12 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final boolean addTable(final TableDesc desc) {
+  public final boolean createTable(final TableDesc desc) {
     try {
       return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Boolean call(NettyClientBase client) throws ServiceException {
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return stub.addTable(null, desc.getProto()).getValue();
+          return stub.createTable(null, desc.getProto()).getValue();
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -168,13 +314,21 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final boolean deleteTable(final String name) {
+  public boolean dropTable(String tableName) {
+    String [] splitted = CatalogUtil.splitFQTableName(tableName);
+    final String databaseName = splitted[0];
+    final String simpleName = splitted[1];
+
     try {
       return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Boolean call(NettyClientBase client) throws ServiceException {
+
+          TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder();
+          builder.setDatabaseName(databaseName);
+          builder.setTableName(simpleName);
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return stub.deleteTable(null,
-              StringProto.newBuilder().setValue(name).build()).getValue();
+          return stub.dropTable(null, builder.build()).getValue();
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -184,14 +338,21 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final boolean existsTable(final String tableId) {
+  public final boolean existsTable(final String databaseName, final String tableName) {
+    if (CatalogUtil.isFQTableName(tableName)) {
+      throw new IllegalArgumentException(
+          "tableName cannot be composed of multiple parts, but it is \"" + tableName + "\"");
+    }
     try {
       return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Boolean call(NettyClientBase client) throws ServiceException {
+
+          TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder();
+          builder.setDatabaseName(databaseName);
+          builder.setTableName(tableName);
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return stub
-              .existsTable(null, StringProto.newBuilder().setValue(tableId).build())
-              .getValue();
+          return stub.existsTable(null, builder.build()).getValue();
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -200,13 +361,18 @@ public abstract class AbstractCatalogClient implements CatalogService {
     }
   }
 
+  public final boolean existsTable(final String tableName) {
+    String [] splitted = CatalogUtil.splitFQTableName(tableName);
+    return existsTable(splitted[0], splitted[1]);
+  }
+
   @Override
-  public final boolean addIndex(final IndexDesc index) {
+  public final boolean createIndex(final IndexDesc index) {
     try {
       return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Boolean call(NettyClientBase client) throws ServiceException {
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return stub.addIndex(null, index.getProto()).getValue();
+          return stub.createIndex(null, index.getProto()).getValue();
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -216,13 +382,16 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final boolean existIndex(final String indexName) {
+  public final boolean existIndexByName(final String databaseName, final String indexName) {
     try {
       return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Boolean call(NettyClientBase client) throws ServiceException {
+          IndexNameProto.Builder builder = IndexNameProto.newBuilder();
+          builder.setDatabaseName(databaseName);
+          builder.setIndexName(indexName);
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return stub.existIndexByName(null, StringProto.newBuilder().
-              setValue(indexName).build()).getValue();
+          return stub.existIndexByName(null, builder.build()).getValue();
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -232,15 +401,17 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public boolean existIndex(final String tableName, final String columnName) {
+  public boolean existIndexByColumn(final String databaseName, final String tableName, final String columnName) {
     try {
       return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Boolean call(NettyClientBase client) throws ServiceException {
-          GetIndexRequest.Builder builder = GetIndexRequest.newBuilder();
-          builder.setTableName(tableName);
-          builder.setColumnName(columnName);
+
+          GetIndexByColumnRequest.Builder builder = GetIndexByColumnRequest.newBuilder();
+          builder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName));
+          builder.setColumnName(CatalogUtil.normalizeIdentifier(columnName));
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return stub.existIndex(null, builder.build()).getValue();
+          return stub.existIndexByColumn(null, builder.build()).getValue();
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -250,14 +421,17 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final IndexDesc getIndex(final String indexName) {
+  public final IndexDesc getIndexByName(final String databaseName, final String indexName) {
     try {
       return new ServerCallable<IndexDesc>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public IndexDesc call(NettyClientBase client) throws ServiceException {
+
+          IndexNameProto.Builder builder = IndexNameProto.newBuilder();
+          builder.setDatabaseName(databaseName);
+          builder.setIndexName(indexName);
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return new IndexDesc(
-              stub.getIndexByName(null,
-                  StringProto.newBuilder().setValue(indexName).build()));
+          return new IndexDesc(stub.getIndexByName(null, builder.build()));
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -267,16 +441,19 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public final IndexDesc getIndex(final String tableName, final String columnName) {
+  public final IndexDesc getIndexByColumn(final String databaseName,
+                                          final String tableName,
+                                          final String columnName) {
     try {
       return new ServerCallable<IndexDesc>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public IndexDesc call(NettyClientBase client) throws ServiceException {
-          GetIndexRequest.Builder builder = GetIndexRequest.newBuilder();
-          builder.setTableName(tableName);
+
+          GetIndexByColumnRequest.Builder builder = GetIndexByColumnRequest.newBuilder();
+          builder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName));
           builder.setColumnName(columnName);
 
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return new IndexDesc(stub.getIndex(null, builder.build()));
+          return new IndexDesc(stub.getIndexByColumn(null, builder.build()));
         }
       }.withRetries();
     } catch (ServiceException e) {
@@ -286,13 +463,18 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
-  public boolean deleteIndex(final String indexName) {
+  public boolean dropIndex(final String databaseName,
+                           final String indexName) {
     try {
       return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
         public Boolean call(NettyClientBase client) throws ServiceException {
+
+          IndexNameProto.Builder builder = IndexNameProto.newBuilder();
+          builder.setDatabaseName(databaseName);
+          builder.setIndexName(indexName);
+
           CatalogProtocolService.BlockingInterface stub = getStub(client);
-          return stub.delIndex(null,
-              StringProto.newBuilder().setValue(indexName).build()).getValue();
+          return stub.dropIndex(null, builder.build()).getValue();
         }
       }.withRetries();
     } catch (ServiceException e) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java
index 494ac0b..d69ed7e 100644
--- a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java
+++ b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java
@@ -28,25 +28,85 @@ import static org.apache.tajo.catalog.proto.CatalogProtos.FunctionType;
 public interface CatalogService {
 
   /**
+   *
+   * @param tableSpaceName Tablespace name to be created
+   * @return True if tablespace is created successfully. Otherwise, it will return FALSE.
+   */
+  Boolean createTablespace(String tableSpaceName, String uri);
+
+  /**
+   *
+   * @param tableSpaceName Tablespace name to be created
+   * @return True if tablespace is created successfully. Otherwise, it will return FALSE.
+   */
+  Boolean existTablespace(String tableSpaceName);
+
+  /**
+   *
+   * @param tableSpaceName Tablespace name to be created
+   * @return True if tablespace is created successfully. Otherwise, it will return FALSE.
+   */
+  Boolean dropTablespace(String tableSpaceName);
+
+  /**
+   *
+   * @return All tablespace names
+   */
+  Collection<String> getAllTablespaceNames();
+
+  /**
+   *
+   * @param databaseName Database name to be created
+   * @return True if database is created successfully. Otherwise, it will return FALSE.
+   */
+  Boolean createDatabase(String databaseName, String tablespaceName);
+
+  /**
+   *
+   * @param databaseName Database name to be dropped
+   * @return True if database is dropped sucessfully. Otherwise, it will return FALSE.
+   */
+  Boolean dropDatabase(String databaseName);
+
+  /**
+   *
+   * @param databaseName Database name to be checked
+   * @return True if database exists. Otherwise, it will return FALSE.
+   */
+  Boolean existDatabase(String databaseName);
+
+  /**
+   *
+   * @return All database names
+   */
+  Collection<String> getAllDatabaseNames();
+
+  /**
+   * Get a table description by name
+   * @param tableName table name
+   * @return a table description
+   * @see TableDesc
+   * @throws Throwable
+   */
+  TableDesc getTableDesc(String databaseName, String tableName);
+
+  /**
    * Get a table description by name
-   * @param name table name
    * @return a table description
    * @see TableDesc
    * @throws Throwable
    */
-  TableDesc getTableDesc(String name);
+  TableDesc getTableDesc(String qualifiedName);
 
   /**
    *
-   * @return
-   * @throws org.apache.tajo.catalog.exception.CatalogException
+   * @return All table names which belong to a given database.
    */
-  Collection<String> getAllTableNames();
+  Collection<String> getAllTableNames(String databaseName);
 
   /**
    *
-   * @return
-   * @throws org.apache.tajo.catalog.exception.CatalogException
+   * @return All FunctionDescs
    */
   Collection<FunctionDesc> getFunctions();
 
@@ -55,34 +115,36 @@ public interface CatalogService {
    * @see TableDesc
    * @throws Throwable
    */
-  boolean addTable(TableDesc desc);
+  boolean createTable(TableDesc desc);
 
 
   /**
    * Drop a table by name
    *
-   * @param name table name
+   * @param tableName table name
    * @throws Throwable
    */
-  boolean deleteTable(String name);
+  boolean dropTable(String tableName);
+
+  boolean existsTable(String databaseName, String tableName);
 
-  boolean existsTable(String tableId);
+  boolean existsTable(String tableName);
 
-  PartitionMethodDesc getPartitionMethod(String tableId);
+  PartitionMethodDesc getPartitionMethod(String databaseName, String tableName);
 
-  boolean existPartitionMethod(String tableId);
+  boolean existPartitionMethod(String databaseName, String tableName);
 
-  boolean addIndex(IndexDesc index);
+  boolean createIndex(IndexDesc index);
 
-  boolean existIndex(String indexName);
+  boolean existIndexByName(String databaseName, String indexName);
 
-  boolean existIndex(String tableName, String columnName);
+  boolean existIndexByColumn(String databaseName, String tableName, String columnName);
 
-  IndexDesc getIndex(String indexName);
+  IndexDesc getIndexByName(String databaseName, String indexName);
 
-  IndexDesc getIndex(String tableName, String columnName);
+  IndexDesc getIndexByColumn(String databaseName, String tableName, String columnName);
 
-  boolean deleteIndex(String indexName);
+  boolean dropIndex(String databaseName, String indexName);
 
   boolean createFunction(FunctionDesc funcDesc);
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto b/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto
index 6a96b4e..06b69c1 100644
--- a/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto
+++ b/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto
@@ -25,15 +25,26 @@ import "CatalogProtos.proto";
 import "PrimitiveProtos.proto";
 
 service CatalogProtocolService {
-  rpc getTableDesc(StringProto) returns (TableDescProto);
-  rpc getAllTableNames(NullProto) returns (GetAllTableNamesResponse);
-  rpc addTable(TableDescProto) returns (BoolProto);
-  rpc deleteTable(StringProto) returns (BoolProto);
-  rpc existsTable(StringProto) returns (BoolProto);
 
-  rpc getPartitionMethodByTableName(StringProto) returns (PartitionMethodProto);
-  rpc existPartitionMethod(StringProto) returns (BoolProto);
-  rpc delPartitionMethod(StringProto) returns (BoolProto);
+  rpc createTablespace(CreateTablespaceRequest) returns (BoolProto);
+  rpc dropTablespace(StringProto) returns (BoolProto);
+  rpc existTablespace(StringProto) returns (BoolProto);
+  rpc getAllTablespaceNames(NullProto) returns (StringListProto);
+
+  rpc createDatabase(CreateDatabaseRequest) returns (BoolProto);
+  rpc dropDatabase(StringProto) returns (BoolProto);
+  rpc existDatabase(StringProto) returns (BoolProto);
+  rpc getAllDatabaseNames(NullProto) returns (StringListProto);
+
+  rpc createTable(TableDescProto) returns (BoolProto);
+  rpc dropTable(TableIdentifierProto) returns (BoolProto);
+  rpc existsTable(TableIdentifierProto) returns (BoolProto);
+  rpc getTableDesc(TableIdentifierProto) returns (TableDescProto);
+  rpc getAllTableNames(StringProto) returns (StringListProto);
+
+  rpc getPartitionMethodByTableName(TableIdentifierProto) returns (PartitionMethodProto);
+  rpc existPartitionMethod(TableIdentifierProto) returns (BoolProto);
+  rpc dropPartitionMethod(TableIdentifierProto) returns (BoolProto);
 
   rpc addPartitions(PartitionsProto) returns (BoolProto);
   rpc addPartition(PartitionDescProto) returns (BoolProto);
@@ -41,12 +52,12 @@ service CatalogProtocolService {
   rpc getPartitionsByTableName(StringProto) returns (PartitionsProto);
   rpc delAllPartitions(StringProto) returns (PartitionsProto);
 
-  rpc addIndex(IndexDescProto) returns (BoolProto);
-  rpc existIndexByName(StringProto) returns (BoolProto);
-  rpc existIndex(GetIndexRequest) returns (BoolProto);
-  rpc getIndexByName(StringProto) returns (IndexDescProto);
-  rpc getIndex(GetIndexRequest) returns (IndexDescProto);
-  rpc delIndex(StringProto) returns (BoolProto);
+  rpc createIndex(IndexDescProto) returns (BoolProto);
+  rpc dropIndex(IndexNameProto) returns (BoolProto);
+  rpc existIndexByName(IndexNameProto) returns (BoolProto);
+  rpc existIndexByColumn(GetIndexByColumnRequest) returns (BoolProto);
+  rpc getIndexByName(IndexNameProto) returns (IndexDescProto);
+  rpc getIndexByColumn(GetIndexByColumnRequest) returns (IndexDescProto);
 
   rpc createFunction(FunctionDescProto) returns (BoolProto);
   rpc dropFunction(UnregisterFunctionRequest) returns (BoolProto);

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogConstants.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogConstants.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogConstants.java
index fa23da1..c7116f6 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogConstants.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogConstants.java
@@ -30,6 +30,8 @@ public class CatalogConstants {
   public static final String DEPRECATED_CATALOG_URI="tajo.catalog.jdbc.uri";
 
   public static final String TB_META = "META";
+  public static final String TB_SPACES = "TABLESPACES";
+  public static final String TB_DATABASES = "DATABASES_";
   public static final String TB_TABLES = "TABLES";
   public static final String TB_COLUMNS = "COLUMNS";
   public static final String TB_OPTIONS = "OPTIONS";
@@ -38,7 +40,10 @@ public class CatalogConstants {
   public static final String TB_PARTITION_METHODS = "PARTITION_METHODS";
   public static final String TB_PARTTIONS = "PARTITIONS";
 
-  public static final String C_TABLE_ID = "TABLE_ID";
+  public static final String COL_TABLESPACE_PK = "SPACE_ID";
+  public static final String COL_DATABASES_PK = "DB_ID";
+  public static final String COL_TABLES_PK = "TID";
+  public static final String COL_TABLES_NAME = "TABLE_NAME";
 
   // table options
   public static final String COMPRESSION_CODEC = "compression.codec";

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
index 2a6727e..05a18bd 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
@@ -50,6 +50,52 @@ public class CatalogUtil {
     return identifier.toLowerCase();
   }
 
+  public static boolean isFQColumnName(String tableName) {
+    return tableName.split(IDENTIFIER_DELIMITER_REGEXP).length == 3;
+  }
+
+  public static boolean isFQTableName(String tableName) {
+    int lastDelimiterIdx = tableName.lastIndexOf(IDENTIFIER_DELIMITER);
+    return lastDelimiterIdx > -1;
+  }
+
+  public static String [] splitFQTableName(String qualifiedName) {
+    String [] splitted = CatalogUtil.splitTableName(CatalogUtil.normalizeIdentifier(qualifiedName));
+    if (splitted.length == 1) {
+      throw new IllegalArgumentException("createTable() requires a qualified table name, but it is \""
+          + qualifiedName + "\".");
+    }
+    return splitted;
+  }
+
+  public static String [] splitTableName(String tableName) {
+    int lastDelimiterIdx = tableName.lastIndexOf(IDENTIFIER_DELIMITER);
+    if (lastDelimiterIdx > -1) {
+      return new String [] {
+          tableName.substring(0, lastDelimiterIdx),
+          tableName.substring(lastDelimiterIdx + 1, tableName.length())
+      };
+    } else {
+      return new String [] {tableName};
+    }
+  }
+
+  public static String buildFQName(String... identifiers) {
+    boolean first = true;
+    StringBuilder sb = new StringBuilder();
+    for(String id : identifiers) {
+      if (first) {
+        first = false;
+      } else {
+        sb.append(IDENTIFIER_DELIMITER);
+      }
+
+      sb.append(id);
+    }
+
+    return sb.toString();
+  }
+
   /**
    * Extract a qualification name from an identifier.
    *
@@ -87,11 +133,18 @@ public class CatalogUtil {
     }
   }
 
-  public static String getCanonicalName(String signature, Collection<DataType> paramTypes) {
+  public static String getCanonicalTableName(String databaseName, String tableName) {
+    StringBuilder sb = new StringBuilder(databaseName);
+    sb.append(IDENTIFIER_DELIMITER);
+    sb.append(tableName);
+    return sb.toString();
+  }
+
+  public static String getCanonicalSignature(String functionName, Collection<DataType> paramTypes) {
     DataType [] types = paramTypes.toArray(new DataType[paramTypes.size()]);
-    return getCanonicalName(signature, types);
+    return getCanonicalSignature(functionName, types);
   }
-  public static String getCanonicalName(String signature, DataType...paramTypes) {
+  public static String getCanonicalSignature(String signature, DataType... paramTypes) {
     StringBuilder sb = new StringBuilder(signature);
     sb.append("(");
     int i = 0;
@@ -144,10 +197,6 @@ public class CatalogUtil {
     return new PartitionMethodDesc(proto);
   }
 
-  public static TableDesc newTableDesc(String tableName, Schema schema, StoreType type, Options options, Path path) {
-    return new TableDesc(tableName, schema, type, options, path);
-  }
-
   /**
   * This method transforms the unqualified names of a given schema into
   * the qualified names.
@@ -206,6 +255,13 @@ public class CatalogUtil {
     return sb.toString();
   }
 
+  public static CatalogProtos.TableIdentifierProto buildTableIdentifier(String databaseName, String tableName) {
+    CatalogProtos.TableIdentifierProto.Builder builder = CatalogProtos.TableIdentifierProto.newBuilder();
+    builder.setDatabaseName(databaseName);
+    builder.setTableName(tableName);
+    return builder.build();
+  }
+
   public static void closeQuietly(Connection conn) {
     try {
       if (conn != null)
@@ -230,31 +286,11 @@ public class CatalogUtil {
     }
   }
 
-  public static void closeQuietly(Connection conn, Statement stmt)  {
-    try {
-      closeQuietly(stmt);
-    } finally {
-      closeQuietly(conn);
-    }
-  }
-
-  public static void closeQuietly(Connection conn, ResultSet res) {
-    try {
-      closeQuietly(res);
-    } finally {
-      closeQuietly(conn);
-    }
-  }
-
-  public static void closeQuietly(Connection conn, Statement stmt, ResultSet res) {
+  public static void closeQuietly(Statement stmt, ResultSet res) {
     try {
       closeQuietly(res);
     } finally {
-      try {
-        closeQuietly(stmt);
-      } finally {
-        closeQuietly(conn);
-      }
+      closeQuietly(stmt);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/DDLBuilder.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/DDLBuilder.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/DDLBuilder.java
index 1e51cc2..fd2fe8f 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/DDLBuilder.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/DDLBuilder.java
@@ -25,7 +25,7 @@ import java.util.Map;
 
 public class DDLBuilder {
 
-  public static String buildDDL(TableDesc desc) {
+  public static String buildDDLForExternalTable(TableDesc desc) {
     StringBuilder sb = new StringBuilder();
 
     sb.append("--\n")
@@ -48,6 +48,27 @@ public class DDLBuilder {
     return sb.toString();
   }
 
+  public static String buildDDLForBaseTable(TableDesc desc) {
+    StringBuilder sb = new StringBuilder();
+
+    sb.append("--\n")
+        .append("-- Name: ").append(desc.getName()).append("; Type: TABLE;")
+        .append(" Storage: ").append(desc.getMeta().getStoreType().name());
+    sb.append("\n-- Path: ").append(desc.getPath());
+    sb.append("\n--\n");
+    sb.append("CREATE TABLE ").append(desc.getName());
+    buildSchema(sb, desc.getSchema());
+    buildUsingClause(sb, desc.getMeta());
+    buildWithClause(sb, desc.getMeta());
+
+    if (desc.hasPartition()) {
+      buildPartitionClause(sb, desc);
+    }
+
+    sb.append(";");
+    return sb.toString();
+  }
+
   private static void buildSchema(StringBuilder sb, Schema schema) {
     boolean first = true;
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java
index 0ef8497..d6d9290 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/FunctionDesc.java
@@ -204,7 +204,7 @@ public class FunctionDesc implements ProtoObject<FunctionDescProto>, Cloneable,
   }
 
   public String getHelpSignature() {
-    return returnType.getType() + " " + CatalogUtil.getCanonicalName(signature, getParamTypes());
+    return returnType.getType() + " " + CatalogUtil.getCanonicalSignature(signature, getParamTypes());
   }
 
   public static String dataTypesToStr(List<DataType> parameterTypesList) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/IndexDesc.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/IndexDesc.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/IndexDesc.java
index 6199259..ef65b36 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/IndexDesc.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/IndexDesc.java
@@ -21,6 +21,7 @@ package org.apache.tajo.catalog;
 import com.google.common.base.Objects;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto;
 import org.apache.tajo.catalog.proto.CatalogProtos.IndexMethod;
 import org.apache.tajo.common.ProtoObject;
@@ -28,11 +29,12 @@ import org.apache.tajo.common.ProtoObject;
 public class IndexDesc implements ProtoObject<IndexDescProto>, Cloneable {
   private IndexDescProto.Builder builder;
   
-  private String name; // required
-  private String tableId; // required
-  private Column column; // required
-  private IndexMethod indexMethod; // required
-  private boolean isUnique = false; // optional [default = false]
+  private String indexName;            // required
+  private String databaseName;         // required
+  private String tableName;            // required
+  private Column column;               // required
+  private IndexMethod indexMethod;     // required
+  private boolean isUnique = false;    // optional [default = false]
   private boolean isClustered = false; // optional [default = false]
   private boolean isAscending = false; // optional [default = false]
   
@@ -40,11 +42,12 @@ public class IndexDesc implements ProtoObject<IndexDescProto>, Cloneable {
     this.builder = IndexDescProto.newBuilder();
   }
   
-  public IndexDesc(String name, String tableId, Column column, IndexMethod type,
-      boolean isUnique, boolean isClustered, boolean isAscending) {
+  public IndexDesc(String idxName, String databaseName, String tableName, Column column,
+                   IndexMethod type,  boolean isUnique, boolean isClustered, boolean isAscending) {
     this();
-    this.name = name.toLowerCase();
-    this.tableId = tableId.toLowerCase();
+    this.indexName = idxName.toLowerCase();
+    this.databaseName = databaseName;
+    this.tableName = tableName.toLowerCase();
     this.column = column;
     this.indexMethod = type;
     this.isUnique = isUnique;
@@ -53,16 +56,19 @@ public class IndexDesc implements ProtoObject<IndexDescProto>, Cloneable {
   }
   
   public IndexDesc(IndexDescProto proto) {
-    this(proto.getName(), proto.getTableId(), new Column(proto.getColumn()),
+    this(proto.getIndexName(),
+        proto.getTableIdentifier().getDatabaseName(),
+        proto.getTableIdentifier().getTableName(),
+        new Column(proto.getColumn()),
         proto.getIndexMethod(), proto.getIsUnique(), proto.getIsClustered(), proto.getIsAscending());
   }
   
-  public String getName() {
-    return name;
+  public String getIndexName() {
+    return indexName;
   }
   
-  public String getTableId() {
-    return tableId;
+  public String getTableName() {
+    return tableName;
   }
   
   public Column getColumn() {
@@ -90,8 +96,17 @@ public class IndexDesc implements ProtoObject<IndexDescProto>, Cloneable {
     if (builder == null) {
       builder = IndexDescProto.newBuilder();
     }
-    builder.setName(this.name);
-    builder.setTableId(this.tableId);
+
+    CatalogProtos.TableIdentifierProto.Builder tableIdentifierBuilder = CatalogProtos.TableIdentifierProto.newBuilder();
+    if (databaseName != null) {
+      tableIdentifierBuilder.setDatabaseName(databaseName);
+    }
+    if (tableName != null) {
+      tableIdentifierBuilder.setTableName(tableName);
+    }
+
+    builder.setTableIdentifier(tableIdentifierBuilder.build());
+    builder.setIndexName(this.indexName);
     builder.setColumn(this.column.getProto());
     builder.setIndexMethod(indexMethod);
     builder.setIsUnique(this.isUnique);
@@ -104,8 +119,8 @@ public class IndexDesc implements ProtoObject<IndexDescProto>, Cloneable {
   public boolean equals(Object obj) {
     if (obj instanceof IndexDesc) {
       IndexDesc other = (IndexDesc) obj;
-      return getName().equals(other.getName())
-          && getTableId().equals(other.getTableId())
+      return getIndexName().equals(other.getIndexName())
+          && getTableName().equals(other.getTableName())
           && getColumn().equals(other.getColumn())
           && getIndexMethod().equals(other.getIndexMethod())
           && isUnique() == other.isUnique()
@@ -117,14 +132,14 @@ public class IndexDesc implements ProtoObject<IndexDescProto>, Cloneable {
   }
   
   public int hashCode() {
-    return Objects.hashCode(getName(), getTableId(), getColumn(), 
+    return Objects.hashCode(getIndexName(), getTableName(), getColumn(),
         getIndexMethod(), isUnique(), isClustered(), isAscending());
   }
 
   public Object clone() throws CloneNotSupportedException {
     IndexDesc desc = (IndexDesc) super.clone();
-    desc.name = name;
-    desc.tableId = tableId;
+    desc.indexName = indexName;
+    desc.tableName = tableName;
     desc.column = (Column) column.clone();
     desc.indexMethod = indexMethod;
     desc.isUnique = isUnique;

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
index 153d5f0..30102eb 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
@@ -38,25 +38,33 @@ public class TableDesc implements ProtoObject<TableDescProto>, GsonObject, Clone
   private final Log LOG = LogFactory.getLog(TableDesc.class);
 
   protected TableDescProto.Builder builder = null;
-  
 	@Expose protected String tableName;                        // required
   @Expose protected Schema schema;
   @Expose protected TableMeta meta;                          // required
-  @Expose protected Path uri;                                // required
+  /** uri is set if external flag is TRUE.*/
+  @Expose protected Path uri;                                // optional
   @Expose	protected TableStats stats;                        // optional
+  /** the description of table partition */
   @Expose protected PartitionMethodDesc partitionMethodDesc; // optional
+  /** True if it is an external table. False if it is a managed table. */
+  @Expose protected Boolean external;                        // optional
 
 	public TableDesc() {
 		builder = TableDescProto.newBuilder();
 	}
-	
-	public TableDesc(String tableName, Schema schema, TableMeta info, Path path) {
-		this();
-		// tajo deems all identifiers as lowcase characters
-	  this.tableName = tableName.toLowerCase();
+
+  public TableDesc(String tableName, Schema schema, TableMeta meta,
+                   Path path, boolean external) {
+    this();
+    this.tableName = tableName.toLowerCase();
     this.schema = schema;
-	  this.meta = info;
-	  this.uri = path;
+    this.meta = meta;
+    this.uri = path;
+    this.external = external;
+  }
+
+	public TableDesc(String tableName, Schema schema, TableMeta meta, Path path) {
+		this(CatalogUtil.normalizeIdentifier(tableName), schema, meta, path, true);
 	}
 	
 	public TableDesc(String tableName, Schema schema, StoreType type, Options options, Path path) {
@@ -64,7 +72,8 @@ public class TableDesc implements ProtoObject<TableDescProto>, GsonObject, Clone
 	}
 	
 	public TableDesc(TableDescProto proto) {
-	  this(proto.getId(), new Schema(proto.getSchema()), new TableMeta(proto.getMeta()), new Path(proto.getPath()));
+	  this(proto.getTableName(), new Schema(proto.getSchema()),
+        new TableMeta(proto.getMeta()), new Path(proto.getPath()), proto.getIsExternal());
     if(proto.hasStats()) {
       this.stats = new TableStats(proto.getStats());
     }
@@ -141,6 +150,14 @@ public class TableDesc implements ProtoObject<TableDescProto>, GsonObject, Clone
     this.partitionMethodDesc = partitionMethodDesc;
   }
 
+  public void setExternal(boolean external) {
+    this.external = external;
+  }
+
+  public boolean isExternal() {
+    return external;
+  }
+
   public int hashCode() {
     return Objects.hashCode(tableName, schema, meta, uri, stats, partitionMethodDesc);
   }
@@ -154,6 +171,7 @@ public class TableDesc implements ProtoObject<TableDescProto>, GsonObject, Clone
       eq = eq && meta.equals(other.meta);
       eq = eq && uri.equals(other.uri);
       eq = eq && TUtil.checkEquals(partitionMethodDesc, other.partitionMethodDesc);
+      eq = eq && TUtil.checkEquals(external, other.external);
       return eq && TUtil.checkEquals(stats, other.stats);
     }
     
@@ -169,6 +187,7 @@ public class TableDesc implements ProtoObject<TableDescProto>, GsonObject, Clone
     desc.uri = uri;
     desc.stats = stats != null ? (TableStats) stats.clone() : null;
     desc.partitionMethodDesc = partitionMethodDesc != null ? (PartitionMethodDesc) partitionMethodDesc.clone() : null;
+    desc.external = external != null ? external : null;
 	  return desc;
 	}
 
@@ -186,8 +205,9 @@ public class TableDesc implements ProtoObject<TableDescProto>, GsonObject, Clone
     if (builder == null) {
       builder = TableDescProto.newBuilder();
     }
+
     if (this.tableName != null) {
-      builder.setId(this.tableName);
+      builder.setTableName(this.tableName);
     }
     if (this.schema != null) {
       builder.setSchema(schema.getProto());
@@ -204,6 +224,9 @@ public class TableDesc implements ProtoObject<TableDescProto>, GsonObject, Clone
     if (this.partitionMethodDesc != null) {
       builder.setPartition(this.partitionMethodDesc.getProto());
     }
+    if (this.external != null) {
+      builder.setIsExternal(external);
+    }
 
     return builder.build();
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsDatabaseException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsDatabaseException.java
new file mode 100644
index 0000000..f811689
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsDatabaseException.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.catalog.exception;
+
+
+public class AlreadyExistsDatabaseException extends CatalogException {
+
+  public AlreadyExistsDatabaseException() {
+	}
+
+	public AlreadyExistsDatabaseException(String dbName) {
+		super(String.format("Already exists database \"%s\"", dbName));
+	}
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java
index a254514..22c8172 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java
@@ -18,6 +18,8 @@
 
 package org.apache.tajo.catalog.exception;
 
+import org.apache.tajo.annotation.Nullable;
+
 public class AlreadyExistsIndexException extends CatalogException {
   private static final long serialVersionUID = 3705839985189534673L;
 
@@ -27,25 +29,11 @@ public class AlreadyExistsIndexException extends CatalogException {
   public AlreadyExistsIndexException() {
   }
 
-  /**
-   * @param message
-   */
-  public AlreadyExistsIndexException(String message) {
-    super(message);
+  public AlreadyExistsIndexException(String databaseName, @Nullable String namespace, String indexName) {
+    super(String.format("index \" %s \" already exists in %s.%s", indexName, databaseName, namespace));
   }
 
-  /**
-   * @param cause
-   */
-  public AlreadyExistsIndexException(Throwable cause) {
-    super(cause);
-  }
-
-  /**
-   * @param message
-   * @param cause
-   */
-  public AlreadyExistsIndexException(String message, Throwable cause) {
-    super(message, cause);
+  public AlreadyExistsIndexException(String indexName) {
+    super("index \"" + indexName + "\" exists table");
   }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java
index a2e3a6a..ec4cf67 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java
@@ -25,7 +25,11 @@ public class AlreadyExistsTableException extends CatalogException {
 	public AlreadyExistsTableException() {		
 	}
 
+  public AlreadyExistsTableException(String databaseName, String relName) {
+    super(String.format("relation \" %s \" already exists in %s", relName, databaseName));
+  }
+
 	public AlreadyExistsTableException(String tableName) {
-		super("Already exists table: "+tableName);
+		super("relation \"" + tableName + "\" exists table");
 	}
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTablespaceException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTablespaceException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTablespaceException.java
new file mode 100644
index 0000000..49c5bf9
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTablespaceException.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.catalog.exception;
+
+
+public class AlreadyExistsTablespaceException extends CatalogException {
+
+  public AlreadyExistsTablespaceException() {
+	}
+
+	public AlreadyExistsTablespaceException(String dbName) {
+		super(String.format("Already exists tablespace \"%s\"", dbName));
+	}
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/InvalidTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/InvalidTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/InvalidTableException.java
deleted file mode 100644
index c19888f..0000000
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/InvalidTableException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tajo.catalog.exception;
-
-import org.apache.tajo.exception.InternalException;
-
-public class InvalidTableException extends InternalException {
-
-	private static final long serialVersionUID = -6326266814969872171L;
-
-	public InvalidTableException() {
-	}
-
-	/**
-	 * @param message
-	 */
-	public InvalidTableException(String message) {
-		super(message);
-	}
-}

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoPartitionedTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoPartitionedTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoPartitionedTableException.java
new file mode 100644
index 0000000..faa8bc4
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoPartitionedTableException.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.catalog.exception;
+
+public class NoPartitionedTableException extends Exception {
+
+  public NoPartitionedTableException() {}
+
+  public NoPartitionedTableException(String databaseName, String relName) {
+    super(String.format("ERROR: \"%s.%s\" is not a partitioned table", databaseName, relName));
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchDatabaseException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchDatabaseException.java
new file mode 100644
index 0000000..757cad5
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchDatabaseException.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.catalog.exception;
+
+
+public class NoSuchDatabaseException extends CatalogException {
+	private static final long serialVersionUID = 277182608283894937L;
+
+	public NoSuchDatabaseException() {}
+
+	public NoSuchDatabaseException(String databaseName) {
+		super("ERROR: database \"" + databaseName + "\" does not exist");
+	}
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/3ba26241/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchFunctionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchFunctionException.java
index 7765c31..78df08f 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchFunctionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/NoSuchFunctionException.java
@@ -27,10 +27,10 @@ public class NoSuchFunctionException extends RuntimeException {
 	private static final long serialVersionUID = 5062193018697228028L;
 
   public NoSuchFunctionException(String funcName, TajoDataTypes.DataType [] parameters) {
-    super("function " + CatalogUtil.getCanonicalName(funcName, parameters) + " does not exist");
+    super("function " + CatalogUtil.getCanonicalSignature(funcName, parameters) + " does not exist");
   }
 
 	public NoSuchFunctionException(String funcName, Collection<TajoDataTypes.DataType> parameters) {
-		super("function " + CatalogUtil.getCanonicalName(funcName, parameters) + " does not exist");
+		super("function " + CatalogUtil.getCanonicalSignature(funcName, parameters) + " does not exist");
 	}
 }