tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [4/4] tajo git commit: TAJO-1699: Tajo Java Client version 2.
Date Tue, 04 Aug 2015 01:31:29 GMT
TAJO-1699: Tajo Java Client version 2.

Closes #662


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

Branch: refs/heads/master
Commit: 4253f1b60429adb9558f0b7b194754557eebcf15
Parents: d8ce562
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Tue Aug 4 10:29:21 2015 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Tue Aug 4 10:29:21 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |   2 +
 .../tajo/catalog/AbstractCatalogClient.java     |   4 +-
 .../org/apache/tajo/catalog/CatalogService.java |   5 +-
 .../java/org/apache/tajo/catalog/Schema.java    |   4 +-
 .../exception/AmbiguousFunctionException.java   |   6 +
 .../exception/AmbiguousTableException.java      |   9 +-
 .../catalog/exception/CatalogException.java     |   9 +-
 .../exception/DuplicateColumnException.java     |   5 +
 .../exception/DuplicateDatabaseException.java   |   6 +
 .../exception/DuplicateIndexException.java      |   5 +
 .../exception/DuplicatePartitionException.java  |   5 +
 .../exception/DuplicateTableException.java      |   5 +
 .../exception/UndefinedColumnException.java     |   5 +
 .../exception/UndefinedDatabaseException.java   |   5 +
 .../exception/UndefinedFunctionException.java   |   8 +-
 .../exception/UndefinedPartitionException.java  |   5 +
 .../exception/UndefinedTableException.java      |   5 +
 .../exception/UndefinedTablespaceException.java |   5 +
 .../org/apache/tajo/catalog/TestSchema.java     |   3 +-
 .../tajo/catalog/store/HiveCatalogUtil.java     |   2 +-
 .../org/apache/tajo/catalog/CatalogServer.java  |  62 +--
 .../InfoSchemaMetadataDictionary.java           |  12 +-
 .../tajo/catalog/store/AbstractDBStore.java     |  24 +-
 .../org/apache/tajo/catalog/store/MemStore.java |  24 +-
 .../catalog/store/XMLCatalogSchemaManager.java  |   8 +-
 .../org/apache/tajo/cli/tools/TajoAdmin.java    |   4 +-
 .../java/org/apache/tajo/cli/tsql/TajoCli.java  |   7 +-
 .../tsql/commands/ConnectDatabaseCommand.java   |   3 +-
 .../tajo/cli/tsql/commands/SetCommand.java      |   5 +-
 tajo-client/pom.xml                             |   4 +-
 .../apache/tajo/client/CatalogAdminClient.java  |  26 +-
 .../tajo/client/CatalogAdminClientImpl.java     |  91 ++--
 .../apache/tajo/client/ClientExceptionUtil.java | 106 ++++
 .../client/InvalidClientSessionException.java   |   9 +-
 .../org/apache/tajo/client/QueryClient.java     |  41 +-
 .../org/apache/tajo/client/QueryClientImpl.java |  83 ++--
 .../apache/tajo/client/SessionConnection.java   | 103 ++--
 .../org/apache/tajo/client/TajoClientImpl.java  |  46 +-
 .../org/apache/tajo/client/TajoClientUtil.java  |   2 +-
 .../apache/tajo/client/v2/ClientDelegate.java   |  41 ++
 .../tajo/client/v2/ClientDelegateFactory.java   |  42 ++
 .../org/apache/tajo/client/v2/ClientUtil.java   |  30 ++
 .../apache/tajo/client/v2/FutureListener.java   |  25 +
 .../tajo/client/v2/LegacyClientDelegate.java    | 485 +++++++++++++++++++
 .../org/apache/tajo/client/v2/QueryFuture.java  | 133 +++++
 .../org/apache/tajo/client/v2/QueryState.java   |  36 ++
 .../apache/tajo/client/v2/ServiceDiscovery.java |  28 ++
 .../org/apache/tajo/client/v2/TajoClient.java   | 154 ++++++
 .../v2/exception/ClientConnectionException.java |  28 ++
 .../ClientUnableToConnectException.java         |  28 ++
 .../org/apache/tajo/jdbc/FetchResultSet.java    |   2 +-
 .../exception/AmbiguousColumnException.java     |   9 +-
 .../apache/tajo/exception/ErrorMessages.java    |   6 +-
 .../NoSuchSessionVariableException.java         |  33 ++
 .../apache/tajo/exception/ReturnStateUtil.java  |   3 +-
 .../apache/tajo/exception/SQLExceptionUtil.java |  22 +-
 .../org/apache/tajo/exception/TajoError.java    |   7 +
 .../apache/tajo/exception/TajoException.java    |  11 +
 .../tajo/exception/TajoInternalError.java       |   6 +
 .../exception/UndefinedOperatorException.java   |   5 +
 .../tajo/exception/UnsupportedException.java    |   5 +
 tajo-core/pom.xml                               |   4 +-
 .../org/apache/tajo/benchmark/BenchmarkSet.java |   3 +-
 .../java/org/apache/tajo/benchmark/TPCH.java    |   5 +-
 .../engine/planner/global/GlobalPlanner.java    | 107 ++--
 .../java/org/apache/tajo/master/TajoMaster.java |   3 +-
 .../tajo/master/exec/CreateTableExecutor.java   |  15 +-
 .../apache/tajo/master/exec/DDLExecutor.java    |  36 +-
 .../apache/tajo/master/exec/QueryExecutor.java  |   3 +-
 .../tajo/session/InvalidSessionException.java   |   7 +-
 .../tajo/webapp/QueryExecutorServlet.java       |   2 +-
 .../apache/tajo/LocalTajoTestingUtility.java    |   6 +-
 .../java/org/apache/tajo/QueryTestCaseBase.java |  10 +-
 .../org/apache/tajo/client/TestTajoClient.java  |  62 +--
 .../tajo/client/TestTajoClientFailures.java     |  16 +-
 .../apache/tajo/client/v2/TestTajoClientV2.java | 236 +++++++++
 .../engine/codegen/TestEvalCodeGenerator.java   |  23 +-
 .../apache/tajo/engine/eval/ExprTestBase.java   |  31 +-
 .../tajo/engine/eval/TestIntervalType.java      |   5 +-
 .../apache/tajo/engine/eval/TestPredicates.java |  39 +-
 .../tajo/engine/eval/TestSQLDateTimeTypes.java  |  11 +-
 .../tajo/engine/eval/TestSQLExpression.java     |  32 +-
 .../function/TestConditionalExpressions.java    |  11 +-
 .../engine/function/TestDateTimeFunctions.java  |  21 +-
 .../tajo/engine/function/TestJsonFunctions.java |   5 +-
 .../tajo/engine/function/TestMathFunctions.java |  49 +-
 .../function/TestPatternMatchingPredicates.java |  15 +-
 .../engine/function/TestPythonFunctions.java    |   5 +-
 .../TestStringOperatorsAndFunctions.java        |  77 ++-
 .../apache/tajo/engine/query/TestIndexScan.java |   3 +-
 .../apache/tajo/engine/query/TestJoinQuery.java |   6 +-
 .../java/org/apache/tajo/jdbc/TestTajoJdbc.java |  90 ----
 .../testExecuteQueryAsync.result                |   7 +
 .../testExecuteQueryAsyncWithListener.result    |   2 +
 .../testExecuteQueryType1.result                |   7 +
 .../testExecuteQueryType2.result                |   4 +
 .../testExecuteQueryType3.result                |   4 +
 .../org/apache/tajo/jdbc/JdbcConnection.java    |  28 +-
 .../org/apache/tajo/jdbc/MetaDataTuple.java     |  17 +-
 .../org/apache/tajo/jdbc/TajoStatement.java     |  55 ---
 .../tajo/plan/expr/BasicEvalNodeVisitor.java    |   1 +
 .../tajo/plan/expr/SimpleEvalNodeVisitor.java   |   3 +-
 .../plan/function/stream/CSVLineSerializer.java |   1 -
 .../tajo/plan/nameresolver/NameResolver.java    |   6 +-
 .../plan/nameresolver/ResolverByLegacy.java     |   3 +-
 .../tajo/plan/nameresolver/ResolverByRels.java  |   4 +-
 .../nameresolver/ResolverByRelsAndSubExprs.java |   4 +-
 .../nameresolver/ResolverBySubExprsAndRels.java |   4 +-
 .../rewrite/rules/ProjectionPushDownRule.java   |  11 +-
 .../tajo/plan/serder/EvalNodeDeserializer.java  |   5 +-
 .../tajo/plan/verifier/VerificationState.java   |   6 +
 .../org/apache/tajo/storage/NullScanner.java    |   4 +-
 .../org/apache/tajo/storage/RowStoreUtil.java   |   2 +-
 .../org/apache/tajo/storage/Tablespace.java     |   3 +-
 .../apache/tajo/tuple/offheap/HeapTuple.java    |   2 -
 .../apache/tajo/tuple/offheap/UnSafeTuple.java  |   2 -
 116 files changed, 2276 insertions(+), 749 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 3deac6d..129c7de 100644
--- a/CHANGES
+++ b/CHANGES
@@ -33,6 +33,8 @@ Release 0.11.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-1699: Tajo Java Client version 2. (hyunsik)
+
     TAJO-1721: Separate routine for CREATE TABLE from DDLExecutor. (hyunsik)
 
     TAJO-1736: Remove unnecessary getMountPath(). 

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 52f4b8e..e239b78 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
@@ -723,13 +723,13 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable
 
   @Override
   public final FunctionDesc getFunction(final String signature, DataType... paramTypes)
-      throws UndefinedFunctionException {
+      throws AmbiguousFunctionException , UndefinedFunctionException {
     return getFunction(signature, null, paramTypes);
   }
 
   @Override
   public final FunctionDesc getFunction(final String signature, FunctionType funcType, DataType... paramTypes)
-      throws UndefinedFunctionException {
+      throws AmbiguousFunctionException, UndefinedFunctionException {
 
     final GetFunctionMetaRequest.Builder builder = GetFunctionMetaRequest.newBuilder();
     builder.setSignature(signature);

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java
index 26fc564..a534805 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java
@@ -18,6 +18,7 @@
 
 package org.apache.tajo.catalog;
 
+import org.apache.tajo.catalog.exception.AmbiguousFunctionException;
 import org.apache.tajo.catalog.exception.UndefinedFunctionException;
 import org.apache.tajo.catalog.exception.UndefinedPartitionException;
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
@@ -210,9 +211,9 @@ public interface CatalogService {
 
   boolean dropFunction(String signature);
 
-  FunctionDesc getFunction(String signature, DataType... paramTypes) throws UndefinedFunctionException;
+  FunctionDesc getFunction(String signature, DataType... paramTypes) throws AmbiguousFunctionException, UndefinedFunctionException;
 
-  FunctionDesc getFunction(String signature, FunctionType funcType, DataType... paramTypes) throws UndefinedFunctionException;
+  FunctionDesc getFunction(String signature, FunctionType funcType, DataType... paramTypes) throws AmbiguousFunctionException, UndefinedFunctionException;
 
   boolean containFunction(String signature, DataType... paramTypes);
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java
index 424861b..7bffe3a 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java
@@ -31,6 +31,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.SchemaProto;
 import org.apache.tajo.common.ProtoObject;
 import org.apache.tajo.common.TajoDataTypes.DataType;
 import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.exception.TajoRuntimeException;
 import org.apache.tajo.json.GsonObject;
 import org.apache.tajo.util.StringUtils;
 import org.apache.tajo.util.TUtil;
@@ -419,8 +420,7 @@ public class Schema implements ProtoObject<SchemaProto>, Cloneable, GsonObject {
   public synchronized Schema addColumn(String name, TypeDesc typeDesc) {
     String normalized = name;
     if(fieldsByQualifiedName.containsKey(normalized)) {
-      LOG.error("Already exists column " + normalized);
-      throw new DuplicateColumnException(normalized);
+      throw new TajoRuntimeException(new DuplicateColumnException(normalized));
     }
 
     Column newCol = new Column(normalized, typeDesc);

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java
index d1f17fd..56c11e1 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java
@@ -20,10 +20,16 @@ package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.common.TajoDataTypes.DataType;
 import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
 
 import static org.apache.tajo.function.FunctionUtil.buildSimpleFunctionSignature;
 
 public class AmbiguousFunctionException extends CatalogException {
+
+  public AmbiguousFunctionException(PrimitiveProtos.ReturnState state) {
+    super(state);
+  }
+
   public AmbiguousFunctionException(String funcName, DataType[] parameters) {
     super(Errors.ResultCode.AMBIGUOUS_FUNCTION, buildSimpleFunctionSignature(funcName, parameters));
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java
index 65ff746..27f5534 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java
@@ -18,12 +18,15 @@
 
 package org.apache.tajo.catalog.exception;
 
-import org.apache.tajo.common.TajoDataTypes.DataType;
 import org.apache.tajo.error.Errors;
-
-import static org.apache.tajo.function.FunctionUtil.buildSimpleFunctionSignature;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class AmbiguousTableException extends CatalogException {
+
+  public AmbiguousTableException(ReturnState state) {
+    super(state);
+  }
+
   public AmbiguousTableException(String tableName) {
     super(Errors.ResultCode.AMBIGUOUS_TABLE, tableName);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java
index 7098800..e19199c 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java
@@ -19,11 +19,16 @@
 package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.error.Errors.ResultCode;
-import org.apache.tajo.exception.TajoRuntimeException;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
-public class CatalogException extends TajoRuntimeException {
+public class CatalogException extends TajoException {
   private static final long serialVersionUID = -26362412527118618L;
 
+  public CatalogException(ReturnState state) {
+    super(state);
+  }
+
   public CatalogException(ResultCode code, String...args) {
     super(code, args);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java
index 121a289..88b067a 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java
@@ -19,10 +19,15 @@
 package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class DuplicateColumnException extends CatalogException {
 	private static final long serialVersionUID = 6766228091940775275L;
 
+  public DuplicateColumnException(ReturnState state) {
+    super(state);
+  }
+
 	public DuplicateColumnException(String columnName) {
 		super(Errors.ResultCode.DUPLICATE_COLUMN, columnName);
 	}

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java
index 69e37d3..8725d49 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java
@@ -20,8 +20,14 @@ package org.apache.tajo.catalog.exception;
 
 
 import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class DuplicateDatabaseException extends CatalogException {
+
+  public DuplicateDatabaseException(ReturnState state) {
+    super(state);
+  }
 	public DuplicateDatabaseException(String dbName) {
 		super(Errors.ResultCode.DUPLICATE_DATABASE, dbName);
 	}

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java
index c510b16..b9e71c2 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java
@@ -19,10 +19,15 @@
 package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class DuplicateIndexException extends CatalogException {
   private static final long serialVersionUID = 3705839985189534673L;
 
+  public DuplicateIndexException(ReturnState state) {
+    super(state);
+  }
+
   public DuplicateIndexException(String indexName) {
     super(Errors.ResultCode.DUPLICATE_INDEX, indexName);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java
index bdec4fc..bbb50b9 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java
@@ -19,10 +19,15 @@
 package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class DuplicatePartitionException extends CatalogException {
   private static final long serialVersionUID = 277182608283894930L;
 
+  public DuplicatePartitionException(ReturnState state) {
+    super(state);
+  }
+
   public DuplicatePartitionException(String partitionName) {
     super(Errors.ResultCode.DUPLICATE_PARTITION, partitionName);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java
index 74fa39f..2111186 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java
@@ -20,10 +20,15 @@ package org.apache.tajo.catalog.exception;
 
 
 import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class DuplicateTableException extends CatalogException {
 	private static final long serialVersionUID = -641623770742392865L;
 
+  public DuplicateTableException(ReturnState state) {
+    super(state);
+  }
+
   public DuplicateTableException(String relName) {
     super(Errors.ResultCode.DUPLICATE_TABLE, relName);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java
index 43b7410..39d6130 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java
@@ -20,10 +20,15 @@ package org.apache.tajo.catalog.exception;
 
 
 import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class UndefinedColumnException extends CatalogException {
 	private static final long serialVersionUID = 277182608283894937L;
 
+  public UndefinedColumnException(ReturnState state) {
+    super(state);
+  }
+
 	public UndefinedColumnException(String columnName) {
 		super(ResultCode.UNDEFINED_COLUMN, columnName);
 	}

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java
index 8294add..75dcd49 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java
@@ -20,10 +20,15 @@ package org.apache.tajo.catalog.exception;
 
 
 import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class UndefinedDatabaseException extends CatalogException {
 	private static final long serialVersionUID = 277182608283894937L;
 
+  public UndefinedDatabaseException(ReturnState state) {
+    super(state);
+  }
+
 	public UndefinedDatabaseException(String dbName) {
 		super(Errors.ResultCode.UNDEFINED_DATABASE, dbName);
 	}

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java
index 175b597..0ac2a93 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java
@@ -19,17 +19,19 @@
 package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.common.TajoDataTypes;
-import org.apache.tajo.error.Errors;
 import org.apache.tajo.error.Errors.ResultCode;
-import org.apache.tajo.exception.TajoException;
-import org.apache.tajo.exception.TajoRuntimeException;
 import org.apache.tajo.function.FunctionUtil;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 import java.util.Collection;
 
 public class UndefinedFunctionException extends CatalogException {
 	private static final long serialVersionUID = 5062193018697228028L;
 
+  public UndefinedFunctionException(ReturnState state) {
+    super(state);
+  }
+
   public UndefinedFunctionException(String signature) {
     super(ResultCode.UNDEFINED_FUNCTION, signature);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java
index 282f0a2..1033c44 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java
@@ -19,11 +19,16 @@
 package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class UndefinedPartitionException extends CatalogException {
 
   private static final long serialVersionUID = 277182608283894938L;
 
+  public UndefinedPartitionException(ReturnState state) {
+    super(state);
+  }
+
   public UndefinedPartitionException(String partitionName) {
     super(ResultCode.UNDEFINED_PARTITION, partitionName);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java
index 2513783..bbdb69d 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java
@@ -21,10 +21,15 @@ package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class UndefinedTableException extends CatalogException {
 	private static final long serialVersionUID = 277182608283894937L;
 
+  public UndefinedTableException(ReturnState state) {
+    super(state);
+  }
+
   public UndefinedTableException(String dbName, String tbName) {
 		super(ResultCode.UNDEFINED_TABLE, CatalogUtil.buildFQName(dbName, tbName));
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java
index ffe5789..f3faf6e 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java
@@ -19,10 +19,15 @@
 package org.apache.tajo.catalog.exception;
 
 import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
 
 public class UndefinedTablespaceException extends CatalogException {
 	private static final long serialVersionUID = 277182608283894937L;
 
+  public UndefinedTablespaceException(ReturnState state) {
+    super(state);
+  }
+
 	public UndefinedTablespaceException(String spaceName) {
 		super(Errors.ResultCode.UNDEFINED_TABLESPACE, spaceName);
 	}

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java b/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java
index cf1a24a..4c251af 100644
--- a/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java
+++ b/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java
@@ -22,6 +22,7 @@ import org.apache.tajo.catalog.exception.DuplicateColumnException;
 import org.apache.tajo.catalog.json.CatalogGsonHelper;
 import org.apache.tajo.catalog.proto.CatalogProtos.SchemaProto;
 import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.exception.TajoRuntimeException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -191,7 +192,7 @@ public class TestSchema {
     assertEquals(schema.size(), schema3.size());
 	}
 	
-	@Test(expected = DuplicateColumnException.class)
+	@Test(expected = TajoRuntimeException.class)
 	public final void testAddExistColumn() {
     Schema schema = new Schema();
     schema.addColumn("abc", Type.FLOAT8);

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java b/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java
index 5ae5969..39b3cb9 100644
--- a/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java
+++ b/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java
@@ -47,7 +47,7 @@ public class HiveCatalogUtil {
     }
   }
 
-  public static TajoDataTypes.Type getTajoFieldType(String dataType)  {
+  public static TajoDataTypes.Type getTajoFieldType(String dataType) throws CatalogException {
     Preconditions.checkNotNull(dataType);
 
     if(dataType.equalsIgnoreCase(serdeConstants.INT_TYPE_NAME)) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
index 4ed1ae8..e2dcfcd 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
@@ -547,20 +547,22 @@ public class CatalogServer extends AbstractService {
 
     @Override
     public TableResponse getTableDesc(RpcController controller,
-                                       TableIdentifierProto request) throws ServiceException {
+                                      TableIdentifierProto request) {
       String dbName = request.getDatabaseName();
       String tbName = request.getTableName();
 
-      if (metaDictionary.isSystemDatabase(dbName)) {
-        return TableResponse.newBuilder()
-            .setState(OK)
-            .setTable(metaDictionary.getTableDesc(tbName))
-            .build();
-      } else {
-        rlock.lock();
-        try {
-          boolean contain;
+      rlock.lock();
+      try {
+
+        if (metaDictionary.isSystemDatabase(dbName)) {
+
+          return TableResponse.newBuilder()
+              .setState(OK)
+              .setTable(metaDictionary.getTableDesc(tbName))
+              .build();
 
+        } else {
+          boolean contain;
           contain = store.existDatabase(dbName);
 
           if (contain) {
@@ -580,17 +582,17 @@ public class CatalogServer extends AbstractService {
                 .setState(errUndefinedDatabase(dbName))
                 .build();
           }
+        }
 
-        } catch (Throwable t) {
-          printStackTraceIfError(LOG, t);
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
 
-          return TableResponse.newBuilder()
-              .setState(returnError(t))
-              .build();
+        return TableResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
 
-        } finally {
-          rlock.unlock();
-        }
+      } finally {
+        rlock.unlock();
       }
     }
 
@@ -718,15 +720,15 @@ public class CatalogServer extends AbstractService {
       String dbName = request.getDatabaseName();
       String tbName = request.getTableName();
 
-      if (metaDictionary.isSystemDatabase(dbName)) {
-        return metaDictionary.existTable(tbName) ? OK : errUndefinedTable(tbName);
+      rlock.lock();
+      try {
 
-      } else {
-        rlock.lock();
-        try {
+        if (metaDictionary.isSystemDatabase(dbName)) {
+          return metaDictionary.existTable(tbName) ? OK : errUndefinedTable(tbName);
 
-          boolean contain = store.existDatabase(dbName);
+        } else {
 
+          boolean contain = store.existDatabase(dbName);
           if (contain) {
             if (store.existTable(dbName, tbName)) {
               return OK;
@@ -736,14 +738,14 @@ public class CatalogServer extends AbstractService {
           } else {
             return errUndefinedDatabase(dbName);
           }
+        }
 
-        } catch (Throwable t) {
-          printStackTraceIfError(LOG, t);
-          return returnError(t);
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
 
-        } finally {
-          rlock.unlock();
-        }
+      } finally {
+        rlock.unlock();
       }
     }
     

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
index f798c1d..b59d61c 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
@@ -91,7 +91,7 @@ public class InfoSchemaMetadataDictionary {
     return systemTableNames;
   }
   
-  private TableDescriptor getTableDescriptor(String tableName) {
+  private TableDescriptor getTableDescriptor(String tableName) throws UndefinedTableException {
     TableDescriptor tableDescriptor = null;
     
     if (tableName == null || tableName.isEmpty()) {
@@ -106,11 +106,15 @@ public class InfoSchemaMetadataDictionary {
         break;
       }
     }
-    
+
+    if (tableDescriptor == null) {
+      throw new UndefinedTableException(tableName);
+    }
+
     return tableDescriptor;
   }
   
-  public CatalogProtos.TableDescProto getTableDesc(String tableName) {
+  public CatalogProtos.TableDescProto getTableDesc(String tableName) throws UndefinedTableException {
     TableDescriptor tableDescriptor;
     
     tableDescriptor = getTableDescriptor(tableName);
@@ -121,7 +125,7 @@ public class InfoSchemaMetadataDictionary {
     return tableDescriptor.getTableDescription();
   }
   
-  public boolean existTable(String tableName) {
+  public boolean existTable(String tableName) throws UndefinedTableException {
     return getTableDescriptor(tableName) != null;
   }
   

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
index b62624a..a3eb0c3 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
@@ -170,16 +170,12 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
             createBaseTable();
             LOG.info("The base tables of CatalogServer are created.");
           } catch (CatalogException ce) {
-            try {
-              dropBaseTable();
-            } catch (Throwable t) {
-              LOG.error(t, t);
-            }
+            dropBaseTable();
             throw ce;
           }
         }
      }
-    } catch (Exception se) {
+    } catch (Throwable se) {
       throw new TajoInternalError(se);
     }
   }
@@ -200,7 +196,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     return catalogUri;
   }
 
-  protected boolean isConnValid(int timeout) throws CatalogException {
+  protected boolean isConnValid(int timeout) {
     boolean isValid = false;
 
     try {
@@ -703,7 +699,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     }
   }
 
-  private TableSpaceInternal getTableSpaceInfo(String spaceName) {
+  private TableSpaceInternal getTableSpaceInfo(String spaceName) throws UndefinedTablespaceException {
     Connection conn = null;
     PreparedStatement pstmt = null;
     ResultSet res = null;
@@ -742,7 +738,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       }
       return res.getInt(1);
     } catch (SQLException se) {
-      throw new UndefinedTableException(databaseName, tableName);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -1034,7 +1030,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
   }
 
-  private Map<String, String> getTableOptions(final int tableId) throws CatalogException {
+  private Map<String, String> getTableOptions(final int tableId) {
     Connection conn = null;
     PreparedStatement pstmt = null;
     ResultSet res = null;
@@ -1335,7 +1331,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     }
   }
 
-  private int getDatabaseId(String databaseName) throws SQLException {
+  private int getDatabaseId(String databaseName) throws SQLException, UndefinedDatabaseException {
     String sql = String.format("SELECT DB_ID from %s WHERE DB_NAME = ?", TB_DATABASES);
 
     if (LOG.isDebugEnabled()) {
@@ -1394,7 +1390,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
   }
 
   public void dropTableInternal(Connection conn, String databaseName, final String tableName)
-      throws SQLException {
+      throws SQLException, UndefinedDatabaseException {
 
     PreparedStatement pstmt = null;
 
@@ -1507,7 +1503,9 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     }
   }
 
-  public Pair<Integer, String> getDatabaseIdAndUri(String databaseName) throws SQLException {
+  public Pair<Integer, String> getDatabaseIdAndUri(String databaseName)
+      throws SQLException, UndefinedDatabaseException {
+
     String sql =
         "SELECT DB_ID, SPACE_URI from " + TB_DATABASES + " natural join " + TB_SPACES + " WHERE db_name = ?";
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
index bcd9ce9..c822482 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
@@ -22,26 +22,13 @@
 package org.apache.tajo.catalog.store;
 
 import com.google.common.collect.Maps;
-
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.tajo.TajoConstants;
-import org.apache.tajo.catalog.CatalogConstants;
-import org.apache.tajo.catalog.CatalogUtil;
-import org.apache.tajo.catalog.FunctionDesc;
-import org.apache.tajo.catalog.Schema;
-import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.exception.*;
 import org.apache.tajo.catalog.proto.CatalogProtos;
-import org.apache.tajo.catalog.proto.CatalogProtos.ColumnProto;
-import org.apache.tajo.catalog.proto.CatalogProtos.DatabaseProto;
-import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto;
-import org.apache.tajo.catalog.proto.CatalogProtos.SortSpecProto;
-import org.apache.tajo.catalog.proto.CatalogProtos.TableDescProto;
-import org.apache.tajo.catalog.proto.CatalogProtos.TableDescriptorProto;
-import org.apache.tajo.catalog.proto.CatalogProtos.TableOptionProto;
-import org.apache.tajo.catalog.proto.CatalogProtos.TablePartitionProto;
-import org.apache.tajo.catalog.proto.CatalogProtos.TableStatsProto;
+import org.apache.tajo.catalog.proto.CatalogProtos.*;
 import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueProto;
 import org.apache.tajo.util.KeyValueSet;
 import org.apache.tajo.util.TUtil;
@@ -50,7 +37,7 @@ import java.io.IOException;
 import java.util.*;
 
 import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceType;
-import static org.apache.tajo.catalog.proto.CatalogProtos.TablespaceProto;
+import static org.apache.tajo.catalog.proto.CatalogProtos.*;
 
 /**
  * CatalogServer guarantees that all operations are thread-safe.
@@ -198,7 +185,7 @@ public class MemStore implements CatalogStore {
    * Get a database namespace from a Map instance.
    */
   private <T> Map<String, T> checkAndGetDatabaseNS(final Map<String, Map<String, T>> databaseMap,
-                                                   String databaseName) {
+                                                   String databaseName) throws UndefinedDatabaseException {
     if (databaseMap.containsKey(databaseName)) {
       return databaseMap.get(databaseName);
     } else {
@@ -372,7 +359,8 @@ public class MemStore implements CatalogStore {
     partitions.put(tableName, protoMap);
   }
 
-  private void dropPartition(String databaseName, String tableName, String partitionName) {
+  private void dropPartition(String databaseName, String tableName, String partitionName)
+      throws UndefinedPartitionException {
     if(!partitions.containsKey(tableName)) {
       throw new UndefinedPartitionException(partitionName);
     } else {

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
index dd8e2a2..9d767a0 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
@@ -64,15 +64,15 @@ public class XMLCatalogSchemaManager {
   private final Unmarshaller unmarshaller;
   private StoreObject catalogStore;
   
-  public XMLCatalogSchemaManager(String schemaPath) throws CatalogException {
+  public XMLCatalogSchemaManager(String schemaPath) {
     this.schemaPath = schemaPath;
     try {
       JAXBContext context = JAXBContext.newInstance(StoreObject.class);
       unmarshaller = context.createUnmarshaller();
       
       loadFromXmlFiles();
-    } catch (Exception e) {
-      throw new TajoInternalError(e);
+    } catch (Throwable t) {
+      throw new TajoInternalError(t);
     }
   }
   
@@ -489,7 +489,7 @@ public class XMLCatalogSchemaManager {
     return files;
   }
   
-  protected void mergeXmlSchemas(final List<StoreObject> storeObjects) throws CatalogException {
+  protected void mergeXmlSchemas(final List<StoreObject> storeObjects) {
     if (storeObjects.size() <= 0) {
       throw new TajoInternalError("Unable to find a schema file.");
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java
index 77a7000..72f7f7a 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java
@@ -416,8 +416,8 @@ public class TajoAdmin {
       } else {
         writer.write("ERROR:" + status.getErrorMessage());
       }
-    } catch (SQLException e) {
-      writer.write("ERROR:" + e.getMessage());
+    } catch (Throwable t) {
+      writer.write("ERROR:" + t.getMessage());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
index c6409f1..eadd4df 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
@@ -34,6 +34,7 @@ import org.apache.tajo.client.*;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.conf.TajoConf.ConfVars;
 import org.apache.tajo.exception.ReturnStateUtil;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.service.ServiceTrackerFactory;
 import org.apache.tajo.util.FileUtil;
@@ -296,7 +297,7 @@ public class TajoCli {
     }
   }
 
-  private void processSessionVarCommand(String[] confCommands) throws SQLException {
+  private void processSessionVarCommand(String[] confCommands) throws TajoException {
     for (String eachParam: confCommands) {
       String[] tokens = eachParam.split("=");
       if (tokens.length != 2) {
@@ -488,7 +489,7 @@ public class TajoCli {
     return 0;
   }
 
-  private void executeJsonQuery(String json) throws SQLException {
+  private void executeJsonQuery(String json) throws TajoException {
 
     long startTime = System.currentTimeMillis();
     ClientProtos.SubmitQueryResponse response = client.executeQueryWithJson(json);
@@ -581,7 +582,7 @@ public class TajoCli {
     }
   }
 
-  private void waitForQueryCompleted(QueryId queryId) throws SQLException {
+  private void waitForQueryCompleted(QueryId queryId) {
     // if query is empty string
     if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
       return;

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java
index e75171d..3682a74 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java
@@ -20,6 +20,7 @@ package org.apache.tajo.cli.tsql.commands;
 
 import com.google.protobuf.ServiceException;
 import org.apache.tajo.cli.tsql.TajoCli;
+import org.apache.tajo.exception.TajoException;
 
 import java.sql.SQLException;
 
@@ -51,7 +52,7 @@ public class ConnectDatabaseCommand extends TajoShellCommand {
             context.getOutput().write(String.format("You are now connected to database \"%s\" as user \"%s\".%n",
                 context.getCurrentDatabase(), client.getUserInfo().getUserName()));
           }
-        } catch (SQLException se) {
+        } catch (TajoException se) {
           if (se.getMessage() != null) {
             context.getOutput().write(se.getMessage());
           } else {

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java
index c1c286d..0ae07d5 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java
@@ -21,6 +21,7 @@ package org.apache.tajo.cli.tsql.commands;
 import com.google.protobuf.ServiceException;
 import org.apache.tajo.SessionVars;
 import org.apache.tajo.cli.tsql.TajoCli;
+import org.apache.tajo.exception.NoSuchSessionVariableException;
 import org.apache.tajo.util.StringUtils;
 
 import java.sql.SQLException;
@@ -46,13 +47,13 @@ public class SetCommand extends TajoShellCommand {
     }
   }
 
-  private void updateSessionVariable(String key, String val) throws SQLException {
+  private void updateSessionVariable(String key, String val) throws NoSuchSessionVariableException {
     Map<String, String> variables = new HashMap<String, String>();
     variables.put(key, val);
     client.updateSessionVariables(variables);
   }
 
-  public void set(String key, String val) throws SQLException {
+  public void set(String key, String val) throws NoSuchSessionVariableException {
     SessionVars sessionVar;
 
     if (SessionVars.exists(key)) { // if the variable is one of the session variables

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-client/pom.xml b/tajo-client/pom.xml
index e6be476..1044d28 100644
--- a/tajo-client/pom.xml
+++ b/tajo-client/pom.xml
@@ -51,8 +51,8 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <source>1.6</source>
-          <target>1.6</target>
+          <source>1.7</source>
+          <target>1.7</target>
           <encoding>${project.build.sourceEncoding}</encoding>
         </configuration>
       </plugin>

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java
index 5e923e0..bc63f84 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java
@@ -22,9 +22,11 @@ import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.exception.*;
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto;
+import org.apache.tajo.exception.TajoException;
 
 import java.io.Closeable;
 import java.net.URI;
@@ -39,7 +41,7 @@ public interface CatalogAdminClient extends Closeable {
    * @return True if created successfully.
    * @throws java.sql.SQLException
    */
-  boolean createDatabase(final String databaseName) throws SQLException;
+  boolean createDatabase(final String databaseName) throws DuplicateDatabaseException;
   /**
    * Does the database exist?
    *
@@ -47,7 +49,7 @@ public interface CatalogAdminClient extends Closeable {
    * @return True if so.
    * @throws java.sql.SQLException
    */
-  boolean existDatabase(final String databaseName) throws SQLException;
+  boolean existDatabase(final String databaseName);
   /**
    * Drop the database
    *
@@ -55,9 +57,9 @@ public interface CatalogAdminClient extends Closeable {
    * @return True if the database is dropped successfully.
    * @throws java.sql.SQLException
    */
-  boolean dropDatabase(final String databaseName) throws SQLException;
+  boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException;
 
-  List<String> getAllDatabaseNames() throws SQLException;
+  List<String> getAllDatabaseNames();
 
   /**
    * Does the table exist?
@@ -65,7 +67,7 @@ public interface CatalogAdminClient extends Closeable {
    * @param tableName The table name to be checked. This name is case sensitive.
    * @return True if so.
    */
-  boolean existTable(final String tableName) throws SQLException;
+  boolean existTable(final String tableName);
 
   /**
    * Create an external table.
@@ -79,7 +81,7 @@ public interface CatalogAdminClient extends Closeable {
    * @throws java.sql.SQLException
    */
   TableDesc createExternalTable(final String tableName, final Schema schema, final URI path,
-                                       final TableMeta meta) throws SQLException;
+                                       final TableMeta meta) throws DuplicateTableException;
 
   /**
    * Create an external table.
@@ -95,7 +97,7 @@ public interface CatalogAdminClient extends Closeable {
    */
   TableDesc createExternalTable(final String tableName, final Schema schema, final URI path,
                                        final TableMeta meta, final PartitionMethodDesc partitionMethodDesc)
-      throws SQLException;
+      throws DuplicateTableException;
 
   /**
    * Drop a table
@@ -104,7 +106,7 @@ public interface CatalogAdminClient extends Closeable {
    * @return True if the table is dropped successfully.
    * @throws java.sql.SQLException
    */
-  boolean dropTable(final String tableName) throws SQLException;
+  boolean dropTable(final String tableName) throws UndefinedTableException;
 
   /**
    * Drop a table.
@@ -114,7 +116,7 @@ public interface CatalogAdminClient extends Closeable {
    * @return True if the table is dropped successfully.
    * @throws java.sql.SQLException
    */
-  boolean dropTable(final String tableName, final boolean purge) throws SQLException;
+  boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException;
 
   /**
    * Get a list of table names.
@@ -124,7 +126,7 @@ public interface CatalogAdminClient extends Closeable {
    *                     in the current database of this session.
    * @throws java.sql.SQLException
    */
-  List<String> getTableList(@Nullable final String databaseName) throws SQLException;
+  List<String> getTableList(@Nullable final String databaseName);
 
   /**
    * Get a table description
@@ -133,9 +135,9 @@ public interface CatalogAdminClient extends Closeable {
    * @return Table description
    * @throws java.sql.SQLException
    */
-  TableDesc getTableDesc(final String tableName) throws SQLException;
+  TableDesc getTableDesc(final String tableName) throws UndefinedTableException;
 
-  List<CatalogProtos.FunctionDescProto> getFunctions(final String functionName) throws SQLException;
+  List<CatalogProtos.FunctionDescProto> getFunctions(final String functionName);
 
   IndexDescProto getIndex(final String indexName) throws SQLException;
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java
index 8745d19..d4d8a86 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java
@@ -24,16 +24,16 @@ import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.exception.*;
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.proto.CatalogProtos.*;
-import org.apache.tajo.error.Errors.ResultCode;
-import org.apache.tajo.ipc.ClientProtos;
-import org.apache.tajo.ipc.ClientProtos.*;
-import org.apache.tajo.exception.SQLExceptionUtil;
+import org.apache.tajo.error.Errors;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.DropTableRequest;
+import org.apache.tajo.ipc.ClientProtos.GetIndexWithColumnsRequest;
 import org.apache.tajo.rpc.NettyClientBase;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
 import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringListResponse;
 
 import java.io.IOException;
@@ -41,7 +41,7 @@ import java.net.URI;
 import java.sql.SQLException;
 import java.util.List;
 
-import static org.apache.tajo.exception.ReturnStateUtil.isSuccess;
+import static org.apache.tajo.exception.ReturnStateUtil.*;
 import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError;
 import static org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService.BlockingInterface;
 
@@ -53,19 +53,27 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
   }
 
   @Override
-  public boolean createDatabase(final String databaseName) throws SQLException {
+  public boolean createDatabase(final String databaseName) throws DuplicateDatabaseException {
 
     final BlockingInterface stub = conn.getTMStub();
 
     try {
-      return isSuccess(stub.createDatabase(null, conn.getSessionedString(databaseName)));
+      PrimitiveProtos.ReturnState state = stub.createDatabase(null, conn.getSessionedString(databaseName));
+
+      if (isThisError(state, Errors.ResultCode.DUPLICATE_DATABASE)) {
+        throw new DuplicateDatabaseException(state);
+      }
+
+      ensureOk(state);
+      return true;
+
     } catch (ServiceException e) {
       throw new RuntimeException(e);
     }
   }
 
   @Override
-  public boolean existDatabase(final String databaseName) throws SQLException {
+  public boolean existDatabase(final String databaseName) {
 
     final BlockingInterface stub = conn.getTMStub();
 
@@ -77,19 +85,24 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
   }
 
   @Override
-  public boolean dropDatabase(final String databaseName) throws SQLException {
+  public boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException {
 
     final BlockingInterface stub = conn.getTMStub();
 
     try {
-      return isSuccess(stub.dropDatabase(null, conn.getSessionedString(databaseName)));
+      PrimitiveProtos.ReturnState state = stub.dropDatabase(null, conn.getSessionedString(databaseName));
+      if (isThisError(state, Errors.ResultCode.UNDEFINED_DATABASE)) {
+        throw new UndefinedDatabaseException(state);
+      }
+      ensureOk(state);
+      return true;
     } catch (ServiceException e) {
       throw new RuntimeException(e);
     }
   }
 
   @Override
-  public List<String> getAllDatabaseNames() throws SQLException {
+  public List<String> getAllDatabaseNames() {
 
     final BlockingInterface stub = conn.getTMStub();
 
@@ -100,26 +113,34 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
     }
   }
 
-  public boolean existTable(final String tableName) throws SQLException {
+  public boolean existTable(final String tableName) {
 
     final BlockingInterface stub = conn.getTMStub();
 
+    PrimitiveProtos.ReturnState state;
     try {
-      return isSuccess(stub.existTable(null, conn.getSessionedString(tableName)));
+      state = stub.existTable(null, conn.getSessionedString(tableName));
     } catch (ServiceException e) {
       throw new RuntimeException(e);
     }
+
+    if (isThisError(state, Errors.ResultCode.UNDEFINED_TABLE)) {
+      return false;
+    }
+
+    ensureOk(state);
+    return true;
   }
 
   @Override
   public TableDesc createExternalTable(String tableName, Schema schema, URI path, TableMeta meta)
-      throws SQLException {
+      throws DuplicateTableException {
     return createExternalTable(tableName, schema, path, meta, null);
   }
 
   public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path,
                                        final TableMeta meta, final PartitionMethodDesc partitionMethodDesc)
-      throws SQLException {
+      throws DuplicateTableException {
 
     NettyClientBase client = conn.getTajoMasterConnection();
     conn.checkSessionAndGet(client);
@@ -143,20 +164,21 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
       throw new RuntimeException(e);
     }
 
-    if (isSuccess(res.getState())) {
-      return CatalogUtil.newTableDesc(res.getTable());
-    } else {
-      throw SQLExceptionUtil.toSQLException(res.getState());
+    if (isThisError(res.getState(), Errors.ResultCode.DUPLICATE_TABLE)) {
+      throw new DuplicateTableException(res.getState());
     }
+
+    ensureOk(res.getState());
+    return CatalogUtil.newTableDesc(res.getTable());
   }
 
   @Override
-  public boolean dropTable(String tableName) throws SQLException {
+  public boolean dropTable(String tableName) throws UndefinedTableException {
     return dropTable(tableName, false);
   }
 
   @Override
-  public boolean dropTable(final String tableName, final boolean purge) throws SQLException {
+  public boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException {
 
     final BlockingInterface stub = conn.getTMStub();
     final DropTableRequest request = DropTableRequest.newBuilder()
@@ -165,15 +187,24 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
         .setPurge(purge)
         .build();
 
+
+    PrimitiveProtos.ReturnState state;
     try {
-      return isSuccess(stub.dropTable(null, request));
+      state = stub.dropTable(null, request);
     } catch (ServiceException e) {
       throw new RuntimeException(e);
     }
+
+    if (isThisError(state, Errors.ResultCode.UNDEFINED_TABLE)) {
+      throw new UndefinedTableException(state);
+    }
+
+    ensureOk(state);
+    return true;
   }
 
   @Override
-  public List<String> getTableList(@Nullable final String databaseName) throws SQLException {
+  public List<String> getTableList(@Nullable final String databaseName) {
 
     final BlockingInterface stub = conn.getTMStub();
 
@@ -184,12 +215,12 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
       throw new RuntimeException(e);
     }
 
-    throwIfError(response.getState());
+    ensureOk(response.getState());
     return response.getValuesList();
   }
 
   @Override
-  public TableDesc getTableDesc(final String tableName) throws SQLException {
+  public TableDesc getTableDesc(final String tableName) throws UndefinedTableException {
 
     final BlockingInterface stub = conn.getTMStub();
 
@@ -200,12 +231,16 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
       throw new RuntimeException(e);
     }
 
-    throwIfError(res.getState());
+    if (isThisError(res.getState(), Errors.ResultCode.UNDEFINED_TABLE)) {
+      throw new UndefinedTableException(res.getState());
+    }
+
+    ensureOk(res.getState());
     return CatalogUtil.newTableDesc(res.getTable());
   }
 
   @Override
-  public List<FunctionDescProto> getFunctions(final String functionName) throws SQLException {
+  public List<FunctionDescProto> getFunctions(final String functionName) {
 
     final BlockingInterface stub = conn.getTMStub();
 
@@ -217,7 +252,7 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
       throw new RuntimeException(e);
     }
 
-    throwIfError(res.getState());
+    ensureOk(res.getState());
     return res.getFunctionList();
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java
new file mode 100644
index 0000000..2ecc078
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java
@@ -0,0 +1,106 @@
+/**
+ * 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.client;
+
+import com.google.common.collect.Maps;
+import org.apache.tajo.catalog.exception.*;
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.exception.*;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+
+import static org.apache.tajo.error.Errors.ResultCode.*;
+import static org.apache.tajo.exception.ReturnStateUtil.isError;
+
+/**
+ * Exception related utilities. Especially, it provides a way to recover @{link ReturnState} into TajoException.
+ */
+public class ClientExceptionUtil {
+
+  static Map<ResultCode, Class<? extends TajoExceptionInterface>> EXCEPTIONS = Maps.newHashMap();
+
+  static {
+
+    // General Errors
+    ADD_EXCEPTION(INTERNAL_ERROR, TajoInternalError.class);
+    ADD_EXCEPTION(FEATURE_NOT_SUPPORTED, UnsupportedException.class);
+
+    ADD_EXCEPTION(UNDEFINED_TABLESPACE, UndefinedTablespaceException.class);
+    ADD_EXCEPTION(UNDEFINED_DATABASE, UndefinedDatabaseException.class);
+    // ADD_EXCEPTION(UNDEFINED_SCHEMA, );
+    ADD_EXCEPTION(UNDEFINED_TABLE, UndefinedTableException.class);
+    ADD_EXCEPTION(UNDEFINED_COLUMN, UndefinedColumnException.class);
+    ADD_EXCEPTION(UNDEFINED_FUNCTION, UndefinedFunctionException.class);
+    ADD_EXCEPTION(UNDEFINED_PARTITION, UndefinedPartitionException.class);
+    ADD_EXCEPTION(UNDEFINED_OPERATOR, UndefinedOperatorException.class);
+
+    ADD_EXCEPTION(DUPLICATE_TABLESPACE, DuplicateTableException.class);
+    ADD_EXCEPTION(DUPLICATE_DATABASE, DuplicateDatabaseException.class);
+    // ADD_EXCEPTION(DUPLICATE_SCHEMA, );
+    ADD_EXCEPTION(DUPLICATE_TABLE, DuplicateTableException.class);
+    ADD_EXCEPTION(DUPLICATE_COLUMN, DuplicateColumnException.class);
+    // ADD_EXCEPTION(DUPLICATE_ALIAS, );
+    ADD_EXCEPTION(DUPLICATE_INDEX, DuplicateIndexException.class);
+    ADD_EXCEPTION(DUPLICATE_PARTITION, DuplicatePartitionException.class);
+
+    ADD_EXCEPTION(AMBIGUOUS_TABLE, AmbiguousTableException.class);
+    ADD_EXCEPTION(AMBIGUOUS_COLUMN, AmbiguousColumnException.class);
+  }
+
+  private static void ADD_EXCEPTION(ResultCode code, Class<? extends TajoExceptionInterface> cls) {
+    EXCEPTIONS.put(code, cls);
+  }
+
+  public static void throwIfError(ReturnState state) throws TajoException {
+    if (isError(state)) {
+      throw toTajoException(state);
+    }
+  }
+
+  public static TajoException toTajoException(ReturnState state) {
+
+    if (state.getReturnCode() == ResultCode.INTERNAL_ERROR) {
+      throw new TajoInternalError(state);
+
+    } else if (EXCEPTIONS.containsKey(state.getReturnCode())) {
+      Object exception = null;
+      try {
+        Class clazz = EXCEPTIONS.get(state.getReturnCode());
+        Constructor c = clazz.getConstructor(ReturnState.class);
+        exception = c.newInstance(new Object[]{state});
+      } catch (Throwable t) {
+        throw new TajoInternalError(t);
+      }
+
+      if (exception instanceof TajoException) {
+        return (TajoException) exception;
+      } else if (exception instanceof TajoRuntimeException) {
+        throw ((TajoRuntimeException) exception);
+      } else {
+        throw ((TajoError) exception);
+      }
+
+    } else {
+      throw new TajoInternalError("Unregistred Exception (" + state.getReturnCode().name() +"): "
+          + state.getMessage());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java b/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java
index acbc33f..48ba5f6 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java
@@ -18,10 +18,11 @@
 
 package org.apache.tajo.client;
 
-import com.google.protobuf.ServiceException;
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.exception.TajoRuntimeException;
 
-public class InvalidClientSessionException extends ServiceException {
-  public InvalidClientSessionException(String message) {
-    super(message);
+public class InvalidClientSessionException extends TajoRuntimeException {
+  public InvalidClientSessionException(String sessionId) {
+    super(Errors.ResultCode.INVALID_SESSION, sessionId);
   }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
index ffe3d96..966bddf 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
@@ -18,9 +18,11 @@
 
 package org.apache.tajo.client;
 
-import com.google.protobuf.ServiceException;
 import org.apache.tajo.QueryId;
 import org.apache.tajo.auth.UserRoleInfo;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.exception.NoSuchSessionVariableException;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto;
 import org.apache.tajo.ipc.ClientProtos.QueryInfoProto;
@@ -28,14 +30,11 @@ import org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse;
 import org.apache.tajo.jdbc.TajoMemoryResultSet;
 
 import java.io.Closeable;
-import java.io.IOException;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.List;
 import java.util.Map;
 
-import static org.apache.tajo.TajoIdProtos.SessionIdProto;
-
 public interface QueryClient extends Closeable {
 
   boolean isConnected();
@@ -59,32 +58,32 @@ public interface QueryClient extends Closeable {
    * Call to QueryMaster closing query resources
    * @param queryId
    */
-  void closeQuery(final QueryId queryId) throws SQLException;
+  void closeQuery(final QueryId queryId);
 
   void closeNonForwardQuery(final QueryId queryId) throws SQLException;
 
-  String getCurrentDatabase() throws SQLException;
+  String getCurrentDatabase();
 
-  Boolean selectDatabase(final String databaseName) throws SQLException;
+  Boolean selectDatabase(final String databaseName) throws UndefinedDatabaseException;
 
-  Map<String, String> updateSessionVariables(final Map<String, String> variables) throws SQLException;
+  Map<String, String> updateSessionVariables(final Map<String, String> variables) throws NoSuchSessionVariableException;
 
-  Map<String, String> unsetSessionVariables(final List<String> variables) throws SQLException;
+  Map<String, String> unsetSessionVariables(final List<String> variables) throws NoSuchSessionVariableException;
 
-  String getSessionVariable(final String varname) throws SQLException;
+  String getSessionVariable(final String varname) throws NoSuchSessionVariableException;
 
-  Boolean existSessionVariable(final String varname) throws SQLException;
+  Boolean existSessionVariable(final String varname);
 
-  Map<String, String> getAllSessionVariables() throws SQLException;
+  Map<String, String> getAllSessionVariables();
 
   /**
    * It submits a query statement and get a response immediately.
    * The response only contains a query id, and submission status.
    * In order to get the result, you should use {@link #getQueryResult(org.apache.tajo.QueryId)}.
    */
-  SubmitQueryResponse executeQuery(final String sql) throws SQLException;
+  SubmitQueryResponse executeQuery(final String sql);
 
-  SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException;
+  SubmitQueryResponse executeQueryWithJson(final String json);
 
   /**
    * It submits a query statement and get a response.
@@ -94,11 +93,11 @@ public interface QueryClient extends Closeable {
    *
    * @return If failed, return null.
    */
-  ResultSet executeQueryAndGetResult(final String sql) throws SQLException;
+  ResultSet executeQueryAndGetResult(final String sql) throws TajoException;
 
-  ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException;
+  ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException;
 
-  QueryStatus getQueryStatus(QueryId queryId) throws SQLException;
+  QueryStatus getQueryStatus(QueryId queryId);
 
   ResultSet getQueryResult(QueryId queryId) throws SQLException;
 
@@ -108,17 +107,17 @@ public interface QueryClient extends Closeable {
 
   TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException;
 
-  boolean updateQuery(final String sql) throws SQLException;
+  boolean updateQuery(final String sql) throws TajoException;
 
-  boolean updateQueryWithJson(final String json) throws SQLException;
+  boolean updateQueryWithJson(final String json) throws TajoException;
 
   List<ClientProtos.BriefQueryInfo> getRunningQueryList() throws SQLException;
 
-  List<ClientProtos.BriefQueryInfo> getFinishedQueryList() throws SQLException;
+  List<ClientProtos.BriefQueryInfo> getFinishedQueryList();
 
   List<ClientProtos.WorkerResourceInfo> getClusterInfo() throws SQLException;
 
-  QueryStatus killQuery(final QueryId queryId) throws SQLException;
+  QueryStatus killQuery(final QueryId queryId);
 
   QueryInfoProto getQueryInfo(final QueryId queryId) throws SQLException;
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
index e7317e5..02110c0 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
@@ -27,7 +27,10 @@ import org.apache.tajo.auth.UserRoleInfo;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.exception.NoSuchSessionVariableException;
 import org.apache.tajo.exception.SQLExceptionUtil;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.QueryMasterClientProtocol;
 import org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService.BlockingInterface;
@@ -45,6 +48,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
+import static org.apache.tajo.exception.ReturnStateUtil.ensureOk;
 import static org.apache.tajo.exception.ReturnStateUtil.isSuccess;
 import static org.apache.tajo.exception.ReturnStateUtil.returnError;
 import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError;
@@ -95,56 +99,56 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public void closeQuery(QueryId queryId) throws SQLException {
+  public void closeQuery(QueryId queryId) {
     closeNonForwardQuery(queryId);
   }
 
   @Override
-  public void closeNonForwardQuery(QueryId queryId) throws SQLException {
+  public void closeNonForwardQuery(QueryId queryId) {
     try {
-      throwIfError(conn.getTMStub().closeNonForwardQuery(null, buildQueryIdRequest(queryId)));
+      ensureOk(conn.getTMStub().closeNonForwardQuery(null, buildQueryIdRequest(queryId)));
     } catch (ServiceException e) {
       throw new RuntimeException(e);
     }
   }
 
   @Override
-  public String getCurrentDatabase() throws SQLException {
+  public String getCurrentDatabase() {
     return conn.getCurrentDatabase();
   }
 
   @Override
-  public Boolean selectDatabase(String databaseName) throws SQLException {
+  public Boolean selectDatabase(String databaseName) throws UndefinedDatabaseException {
     return conn.selectDatabase(databaseName);
   }
 
   @Override
-  public Map<String, String> updateSessionVariables(Map<String, String> variables) throws SQLException {
+  public Map<String, String> updateSessionVariables(Map<String, String> variables) throws NoSuchSessionVariableException {
     return conn.updateSessionVariables(variables);
   }
 
   @Override
-  public Map<String, String> unsetSessionVariables(List<String> variables) throws SQLException {
+  public Map<String, String> unsetSessionVariables(List<String> variables) throws NoSuchSessionVariableException {
     return conn.unsetSessionVariables(variables);
   }
 
   @Override
-  public String getSessionVariable(String varname) throws SQLException {
+  public String getSessionVariable(String varname) throws NoSuchSessionVariableException {
     return conn.getSessionVariable(varname);
   }
 
   @Override
-  public Boolean existSessionVariable(String varname) throws SQLException {
+  public Boolean existSessionVariable(String varname) {
     return conn.existSessionVariable(varname);
   }
 
   @Override
-  public Map<String, String> getAllSessionVariables() throws SQLException {
+  public Map<String, String> getAllSessionVariables() {
     return conn.getAllSessionVariables();
   }
 
   @Override
-  public ClientProtos.SubmitQueryResponse executeQuery(final String sql) throws SQLException {
+  public ClientProtos.SubmitQueryResponse executeQuery(final String sql) {
 
     final BlockingInterface stub = conn.getTMStub();
     final QueryRequest request = buildQueryRequest(sql, false);
@@ -165,7 +169,7 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public ClientProtos.SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException {
+  public ClientProtos.SubmitQueryResponse executeQueryWithJson(final String json) {
     final BlockingInterface stub = conn.getTMStub();
     final QueryRequest request = buildQueryRequest(json, true);
 
@@ -177,10 +181,10 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public ResultSet executeQueryAndGetResult(String sql) throws SQLException {
+  public ResultSet executeQueryAndGetResult(String sql) throws TajoException {
 
     ClientProtos.SubmitQueryResponse response = executeQuery(sql);
-    throwIfError(response.getState());
+    ensureOk(response.getState());
 
     QueryId queryId = new QueryId(response.getQueryId());
 
@@ -195,10 +199,10 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException {
+  public ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException {
 
     ClientProtos.SubmitQueryResponse response = executeQueryWithJson(json);
-    throwIfError(response.getState());
+    ensureOk(response.getState());
 
     QueryId queryId = new QueryId(response.getQueryId());
 
@@ -212,7 +216,7 @@ public class QueryClientImpl implements QueryClient {
     }
   }
 
-  private ResultSet getQueryResultAndWait(QueryId queryId) throws SQLException {
+  public ResultSet getQueryResultAndWait(QueryId queryId) {
 
     if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
       return createNullResultSet(queryId);
@@ -235,8 +239,27 @@ public class QueryClientImpl implements QueryClient {
     }
   }
 
+  public GetQueryStatusResponse getRawQueryStatus(QueryId queryId) {
+
+    final BlockingInterface stub = conn.getTMStub();
+    final GetQueryStatusRequest request = GetQueryStatusRequest.newBuilder()
+        .setSessionId(conn.sessionId)
+        .setQueryId(queryId.getProto())
+        .build();
+
+    GetQueryStatusResponse res;
+    try {
+      res = stub.getQueryStatus(null, request);
+    } catch (ServiceException t) {
+      throw new RuntimeException(t);
+    }
+
+    ensureOk(res.getState());
+    return res;
+  }
+
   @Override
-  public QueryStatus getQueryStatus(QueryId queryId) throws SQLException {
+  public QueryStatus getQueryStatus(QueryId queryId) {
 
     final BlockingInterface stub = conn.getTMStub();
     final GetQueryStatusRequest request = GetQueryStatusRequest.newBuilder()
@@ -251,19 +274,19 @@ public class QueryClientImpl implements QueryClient {
       throw new RuntimeException(t);
     }
 
-    throwIfError(res.getState());
+    ensureOk(res.getState());
     return new QueryStatus(res);
   }
 
   @Override
-  public ResultSet getQueryResult(QueryId queryId) throws SQLException {
+  public ResultSet getQueryResult(QueryId queryId) {
 
     if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
       return createNullResultSet(queryId);
     }
 
     GetQueryResultResponse response = getResultResponse(queryId);
-    throwIfError(response.getState());
+    ensureOk(response.getState());
     TableDesc tableDesc = CatalogUtil.newTableDesc(response.getTableDesc());
     return new FetchResultSet(this, tableDesc.getLogicalSchema(), queryId, defaultFetchRows);
   }
@@ -274,7 +297,7 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public GetQueryResultResponse getResultResponse(QueryId queryId) throws SQLException {
+  public GetQueryResultResponse getResultResponse(QueryId queryId) {
     if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
       return null;
     }
@@ -292,7 +315,7 @@ public class QueryClientImpl implements QueryClient {
       throw new RuntimeException(t);
     }
 
-    throwIfError(response.getState());
+    ensureOk(response.getState());
     return response;
   }
 
@@ -324,7 +347,7 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public boolean updateQuery(final String sql) throws SQLException {
+  public boolean updateQuery(final String sql) throws TajoException {
 
     final BlockingInterface stub = conn.getTMStub();
     final QueryRequest request = buildQueryRequest(sql, false);
@@ -336,14 +359,14 @@ public class QueryClientImpl implements QueryClient {
       throw new RuntimeException(e);
     }
 
-    throwIfError(response.getState());
+    ClientExceptionUtil.throwIfError(response.getState());
     conn.updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
 
     return true;
   }
 
   @Override
-  public boolean updateQueryWithJson(final String json) throws SQLException {
+  public boolean updateQueryWithJson(final String json) throws TajoException {
 
     final BlockingInterface stub = conn.getTMStub();
     final QueryRequest request = buildQueryRequest(json, true);
@@ -355,7 +378,7 @@ public class QueryClientImpl implements QueryClient {
       throw new RuntimeException(e);
     }
 
-    throwIfError(response.getState());
+    ClientExceptionUtil.throwIfError(response.getState());
     return true;
   }
 
@@ -376,7 +399,7 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public List<ClientProtos.BriefQueryInfo> getFinishedQueryList() throws SQLException {
+  public List<ClientProtos.BriefQueryInfo> getFinishedQueryList() {
 
     final BlockingInterface stub = conn.getTMStub();
 
@@ -387,7 +410,7 @@ public class QueryClientImpl implements QueryClient {
       throw new RuntimeException(e);
     }
 
-    throwIfError(res.getState());
+    ensureOk(res.getState());
     return res.getQueryListList();
   }
 
@@ -411,7 +434,7 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public QueryStatus killQuery(final QueryId queryId) throws SQLException {
+  public QueryStatus killQuery(final QueryId queryId) {
 
     final BlockingInterface stub = conn.getTMStub();
     QueryStatus status = getQueryStatus(queryId);


Mime
View raw message