http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
index e4ee4ea..f91288d 100644
--- a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.QueryId;
 import org.apache.tajo.TajoProtos;
+import org.apache.tajo.exception.ReturnStateUtil;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse;
 import org.apache.tajo.master.QueryInProgress;
@@ -264,8 +265,8 @@ public class QueryResource {
       
       SubmitQueryResponse response = 
         masterContext.getGlobalEngine().executeQuery(session, 
request.getQuery(), false);
-      if (response.hasResultCode() && 
ClientProtos.ResultCode.ERROR.equals(response.getResultCode())) {
-        return ResourcesUtil.createExceptionResponse(LOG, 
response.getErrorMessage());
+      if (ReturnStateUtil.isError(response.getState())) {
+        return ResourcesUtil.createExceptionResponse(LOG, 
response.getState().getMessage());
       } else {
         JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
           
JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, 
UriInfo.class);
@@ -282,7 +283,7 @@ public class QueryResource {
           queryResponse.setUri(queryURI);
         }
 
-        queryResponse.setResultCode(response.getResultCode());
+        queryResponse.setResultCode(response.getState().getReturnCode());
         queryResponse.setQuery(request.getQuery());
         return Response.status(Status.OK).entity(queryResponse).build();
       }

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java
 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java
index 2f52198..40e3f25 100644
--- 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java
+++ 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java
@@ -24,7 +24,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.QueryId;
 import org.apache.tajo.catalog.TableDesc;
-import org.apache.tajo.ipc.ClientProtos.ResultCode;
+import org.apache.tajo.error.Errors.ResultCode;
 import org.apache.tajo.master.QueryInfo;
 import org.apache.tajo.master.TajoMaster.MasterContext;
 import org.apache.tajo.master.exec.NonForwardQueryResultFileScanner;
@@ -201,7 +201,7 @@ public class QueryResultResource {
         GetQueryResultDataResponse response = new GetQueryResultDataResponse();
         
         if (queryInfo == null) {
-          response.setResultCode(ResultCode.ERROR);
+          response.setResultCode(ResultCode.INTERNAL_ERROR);
           response.setErrorMessage("Unable to find a query info for requested 
id : " + queryId);
           return Response.status(Status.NOT_FOUND).entity(response).build();
         }
@@ -232,7 +232,7 @@ public class QueryResultResource {
         LOG.error(e.getMessage(), e);
         
         GetQueryResultDataResponse response = new GetQueryResultDataResponse();
-        response.setResultCode(ResultCode.ERROR);
+        response.setResultCode(ResultCode.INTERNAL_ERROR);
         response.setErrorMessage(e.getMessage());
         
response.setErrorTrace(org.apache.hadoop.util.StringUtils.stringifyException(e));
         return 
Response.status(Status.INTERNAL_SERVER_ERROR).entity(response).build();

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java
index 25aa798..8456202 100644
--- 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java
+++ 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java
@@ -21,23 +21,18 @@ package org.apache.tajo.ws.rs.resources;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.TajoConstants;
-import org.apache.tajo.ipc.ClientProtos;
+import org.apache.tajo.error.Errors.ResultCode;
 import org.apache.tajo.master.TajoMaster;
 import org.apache.tajo.master.TajoMaster.MasterContext;
 import org.apache.tajo.session.InvalidSessionException;
 import org.apache.tajo.session.Session;
-import org.apache.tajo.ws.rs.JerseyResourceDelegate;
-import org.apache.tajo.ws.rs.JerseyResourceDelegateContext;
-import org.apache.tajo.ws.rs.JerseyResourceDelegateContextKey;
-import org.apache.tajo.ws.rs.JerseyResourceDelegateUtil;
-import org.apache.tajo.ws.rs.ResourcesUtil;
+import org.apache.tajo.ws.rs.*;
 import org.apache.tajo.ws.rs.requests.NewSessionRequest;
 import org.apache.tajo.ws.rs.responses.ExceptionResponse;
 import org.apache.tajo.ws.rs.responses.NewSessionResponse;
 
 import javax.ws.rs.*;
 import javax.ws.rs.core.*;
-
 import java.net.URI;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -132,7 +127,7 @@ public class SessionsResource {
         LOG.info("Session " + sessionId + " is created. ");
         
         sessionResponse.setId(sessionId);
-        sessionResponse.setResultCode(ClientProtos.ResultCode.OK);
+        sessionResponse.setResultCode(ResultCode.OK);
         
sessionResponse.setVariables(masterContext.getSessionManager().getAllVariables(sessionId));
         
         JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
@@ -147,7 +142,7 @@ public class SessionsResource {
         LOG.error(e.getMessage(), e);
         
         NewSessionResponse sessionResponse = new NewSessionResponse();
-        sessionResponse.setResultCode(ClientProtos.ResultCode.ERROR);
+        sessionResponse.setResultCode(ResultCode.INTERNAL_ERROR);
         sessionResponse.setMessage(e.getMessage());
 
         return 
Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(sessionResponse).build();
@@ -155,7 +150,7 @@ public class SessionsResource {
         LOG.error(e.getMessage(), e);
         
         NewSessionResponse sessionResponse = new NewSessionResponse();
-        sessionResponse.setResultCode(ClientProtos.ResultCode.ERROR);
+        sessionResponse.setResultCode(ResultCode.INTERNAL_ERROR);
         sessionResponse.setMessage(e.getMessage());
 
         return 
Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(sessionResponse).build();

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java
 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java
index 512f20f..66884bf 100644
--- 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java
+++ 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java
@@ -19,23 +19,25 @@
 package org.apache.tajo.ws.rs.responses;
 
 import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.error.Errors.ResultCode;
 import org.apache.tajo.ipc.ClientProtos;
 
 import com.google.gson.annotations.Expose;
 
 public class GetQueryResultDataResponse {
 
-  @Expose private ClientProtos.ResultCode resultCode;
+  @Expose private ResultCode resultCode;
   @Expose private Schema schema;
   @Expose private int bytesNum;
   @Expose private ResultSetInfoResponse resultset;
   @Expose private String errorMessage;
   @Expose private String errorTrace;
   
-  public ClientProtos.ResultCode getResultCode() {
+  public ResultCode getResultCode() {
     return resultCode;
   }
-  public void setResultCode(ClientProtos.ResultCode resultCode) {
+  public void setResultCode(ResultCode resultCode) {
     this.resultCode = resultCode;
   }
   public Schema getSchema() {

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetSubmitQueryResponse.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetSubmitQueryResponse.java
 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetSubmitQueryResponse.java
index 5654508..50eeb6b 100644
--- 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetSubmitQueryResponse.java
+++ 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetSubmitQueryResponse.java
@@ -19,20 +19,22 @@
 package org.apache.tajo.ws.rs.responses;
 
 import com.google.gson.annotations.Expose;
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.error.Errors.ResultCode;
 import org.apache.tajo.ipc.ClientProtos;
 
 import java.net.URI;
 
 public class GetSubmitQueryResponse {
-  @Expose private ClientProtos.ResultCode resultCode;
+  @Expose private ResultCode resultCode;
   @Expose private String query;
   @Expose private URI uri;
 
-  public ClientProtos.ResultCode getResultCode() {
+  public ResultCode getResultCode() {
     return resultCode;
   }
 
-  public void setResultCode(ClientProtos.ResultCode resultCode) {
+  public void setResultCode(ResultCode resultCode) {
     this.resultCode = resultCode;
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java
 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java
index 67b5b33..cbc8f1d 100644
--- 
a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java
+++ 
b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java
@@ -18,10 +18,9 @@
 
 package org.apache.tajo.ws.rs.responses;
 
-import org.apache.tajo.ipc.ClientProtos;
-import org.apache.tajo.util.TUtil;
-
 import com.google.gson.annotations.Expose;
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.util.TUtil;
 
 import java.util.Map;
 
@@ -29,7 +28,7 @@ public class NewSessionResponse {
 
   @Expose private String id;
   @Expose private String message;
-  @Expose private ClientProtos.ResultCode resultCode;
+  @Expose private ResultCode resultCode;
   @Expose private Map<String, String> variables;
 
   public String getId() {
@@ -48,11 +47,11 @@ public class NewSessionResponse {
     this.message = message;
   }
 
-  public ClientProtos.ResultCode getResultCode() {
+  public ResultCode getResultCode() {
     return resultCode;
   }
 
-  public void setResultCode(ClientProtos.ResultCode resultCode) {
+  public void setResultCode(ResultCode resultCode) {
     this.resultCode = resultCode;
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java 
b/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java
index 6691df1..eae9e8c 100644
--- a/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java
+++ b/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java
@@ -47,6 +47,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.UUID;
 
 public class LocalTajoTestingUtility {
@@ -139,7 +140,7 @@ public class LocalTajoTestingUtility {
     return util;
   }
 
-  public ResultSet execute(String query) throws IOException, ServiceException {
+  public ResultSet execute(String query) throws IOException, SQLException {
     return client.executeQueryAndGetResult(query);
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java 
b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
index 995d448..295ddbc 100644
--- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
@@ -57,22 +57,13 @@ import org.junit.runner.Description;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.lang.annotation.*;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 import static org.junit.Assert.*;
 
@@ -208,7 +199,7 @@ public class QueryTestCaseBase {
   }
 
   @AfterClass
-  public static void tearDownClass() throws ServiceException {
+  public static void tearDownClass() throws SQLException {
     for (String tableName : createdTableGlobalSet) {
       client.updateQuery("DROP TABLE IF EXISTS " + 
CatalogUtil.denormalizeIdentifier(tableName));
     }
@@ -296,7 +287,7 @@ public class QueryTestCaseBase {
 
     Expr expr = sqlParser.parse(query);
     verifier.verify(context, state, expr);
-    if (state.getErrorMessages().size() > 0) {
+    if (state.getErrors().size() > 0) {
       return state;
     }
     LogicalPlan plan = planner.createPlan(context, expr);
@@ -308,8 +299,8 @@ public class QueryTestCaseBase {
 
   public void assertValidSQL(String query) throws PlanningException, 
IOException {
     VerificationState state = verify(query);
-    if (state.getErrorMessages().size() > 0) {
-      fail(state.getErrorMessages().get(0));
+    if (state.getErrors().size() > 0) {
+      fail(state.getErrors().get(0).getMessage());
     }
   }
 
@@ -321,7 +312,7 @@ public class QueryTestCaseBase {
 
   public void assertInvalidSQL(String query) throws PlanningException, 
IOException {
     VerificationState state = verify(query);
-    if (state.getErrorMessages().size() == 0) {
+    if (state.getErrors().size() == 0) {
       fail(PreLogicalPlanVerifier.class.getSimpleName() + " cannot catch any 
verification error: " + query);
     }
   }
@@ -539,7 +530,7 @@ public class QueryTestCaseBase {
       for (String cleanup : annotation.cleanup()) {
         try {
           client.executeQueryAndGetResult(cleanup).close();
-        } catch (ServiceException e) {
+        } catch (SQLException e) {
           // ignore
         }
       }
@@ -668,7 +659,7 @@ public class QueryTestCaseBase {
    * Assert that the database exists.
    * @param databaseName The database name to be checked. This name is case 
sensitive.
    */
-  public void assertDatabaseExists(String databaseName) throws 
ServiceException {
+  public void assertDatabaseExists(String databaseName) throws SQLException {
     assertTrue(client.existDatabase(databaseName));
   }
 
@@ -676,7 +667,7 @@ public class QueryTestCaseBase {
    * Assert that the database does not exists.
    * @param databaseName The database name to be checked. This name is case 
sensitive.
    */
-  public void assertDatabaseNotExists(String databaseName) throws 
ServiceException {
+  public void assertDatabaseNotExists(String databaseName) throws SQLException 
{
     assertTrue(!client.existDatabase(databaseName));
   }
 
@@ -686,7 +677,7 @@ public class QueryTestCaseBase {
    * @param tableName The table name to be checked. This name is case 
sensitive.
    * @throws ServiceException
    */
-  public void assertTableExists(String tableName) throws ServiceException {
+  public void assertTableExists(String tableName) throws SQLException {
     assertTrue(client.existTable(tableName));
   }
 
@@ -695,21 +686,23 @@ public class QueryTestCaseBase {
    *
    * @param tableName The table name to be checked. This name is case 
sensitive.
    */
-  public void assertTableNotExists(String tableName) throws ServiceException {
+  public void assertTableNotExists(String tableName) throws SQLException {
     assertTrue(!client.existTable(tableName));
   }
 
-  public void assertColumnExists(String tableName,String columnName) throws 
ServiceException {
-    TableDesc tableDesc = fetchTableMetaData(tableName);
+  public void assertColumnExists(String tableName,String columnName) throws 
ServiceException, SQLException {
+    TableDesc tableDesc = getTableDesc(tableName);
     assertTrue(tableDesc.getSchema().containsByName(columnName));
   }
 
-  private TableDesc fetchTableMetaData(String tableName) throws 
ServiceException {
+  private TableDesc getTableDesc(String tableName) throws ServiceException, 
SQLException {
     return client.getTableDesc(tableName);
   }
 
-  public void assertTablePropertyEquals(String tableName, String key, String 
expectedValue) throws ServiceException {
-    TableDesc tableDesc = fetchTableMetaData(tableName);
+  public void assertTablePropertyEquals(String tableName, String key, String 
expectedValue)
+      throws ServiceException, SQLException {
+
+    TableDesc tableDesc = getTableDesc(tableName);
     assertEquals(expectedValue, tableDesc.getMeta().getOption(key));
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java 
b/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
index 7be0cab..60349dd 100644
--- a/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
+++ b/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
@@ -59,6 +59,7 @@ import java.io.Writer;
 import java.net.InetSocketAddress;
 import java.net.URI;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.TimeZone;
@@ -618,7 +619,7 @@ public class TajoTestingCluster {
     }
   }
 
-  public static TajoClient newTajoClient(TajoTestingCluster util) throws 
InterruptedException, IOException {
+  public static TajoClient newTajoClient(TajoTestingCluster util) throws 
SQLException, InterruptedException {
     while(true) {
       if(util.getMaster().isMasterRunning()) {
         break;

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java 
b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java
index 6ae52bc..d89bca1 100644
--- a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java
+++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java
@@ -21,7 +21,6 @@ package org.apache.tajo.client;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
-import com.google.protobuf.ServiceException;
 import net.jcip.annotations.NotThreadSafe;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,6 +34,7 @@ import org.apache.tajo.catalog.FunctionDesc;
 import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.error.Errors;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto;
 import org.apache.tajo.ipc.ClientProtos.QueryInfoProto;
@@ -83,7 +83,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testCreateAndDropDatabases() throws ServiceException {
+  public final void testCreateAndDropDatabases() throws SQLException {
     int currentNum = client.getAllDatabaseNames().size();
 
     String prefix = CatalogUtil.normalizeIdentifier("testCreateDatabase_");
@@ -114,7 +114,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testCurrentDatabase() throws IOException, 
ServiceException, InterruptedException {
+  public final void testCurrentDatabase() throws IOException, SQLException, 
InterruptedException {
     int currentNum = client.getAllDatabaseNames().size();
     assertEquals(TajoConstants.DEFAULT_DATABASE_NAME, 
client.getCurrentDatabase());
 
@@ -131,7 +131,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testSelectDatabaseToInvalidOne() throws IOException, 
ServiceException, InterruptedException {
+  public final void testSelectDatabaseToInvalidOne() throws IOException, 
SQLException, InterruptedException {
     int currentNum = client.getAllDatabaseNames().size();
     assertFalse(client.existDatabase("invaliddatabase"));
 
@@ -146,7 +146,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testDropCurrentDatabase() throws IOException, 
ServiceException, InterruptedException {
+  public final void testDropCurrentDatabase() throws IOException, 
SQLException, InterruptedException {
     int currentNum = client.getAllDatabaseNames().size();
     String databaseName = 
CatalogUtil.normalizeIdentifier("testdropcurrentdatabase");
     assertTrue(client.createDatabase(databaseName));
@@ -166,7 +166,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testSessionVariables() throws IOException, 
ServiceException, InterruptedException {
+  public final void testSessionVariables() throws IOException, SQLException, 
InterruptedException {
     String prefixName = "key_";
     String prefixValue = "val_";
 
@@ -212,7 +212,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testKillQuery() throws IOException, ServiceException, 
InterruptedException {
+  public final void testKillQuery() throws IOException, SQLException, 
InterruptedException {
     ClientProtos.SubmitQueryResponse res = client.executeQuery("select 
sleep(1) from lineitem");
     Thread.sleep(1000);
     QueryId queryId = new QueryId(res.getQueryId());
@@ -221,7 +221,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testUpdateQuery() throws IOException, ServiceException {
+  public final void testUpdateQuery() throws IOException, SQLException {
     final String tableName = 
CatalogUtil.normalizeIdentifier("testUpdateQuery");
     Path tablePath = writeTmpTable(tableName);
 
@@ -236,8 +236,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testCreateAndDropExternalTable()
-    throws IOException, ServiceException, SQLException {
+  public final void testCreateAndDropExternalTable() throws IOException, 
SQLException {
     final String tableName = "testCreateAndDropExternalTable";
     Path tablePath = writeTmpTable(tableName);
     LOG.error("Full path:" + tablePath.toUri().getRawPath());
@@ -255,7 +254,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testCreateAndPurgeExternalTable() throws IOException, 
ServiceException, SQLException {
+  public final void testCreateAndPurgeExternalTable() throws IOException, 
SQLException {
     final String tableName = "testCreateAndPurgeExternalTable";
     Path tablePath = writeTmpTable(tableName);
     LOG.error("Full path:" + tablePath.toUri().getRawPath());
@@ -273,7 +272,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testCreateAndDropExternalTableByExecuteQuery() throws 
IOException, ServiceException {
+  public final void testCreateAndDropExternalTableByExecuteQuery() throws 
IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
CatalogUtil.normalizeIdentifier("testCreateAndDropExternalTableByExecuteQuery");
 
@@ -281,7 +280,7 @@ public class TestTajoClient {
     assertFalse(client.existTable(tableName));
 
     String sql = "create external table " + tableName + " (deptname text, 
score int4) " + "using csv location '"
-      + tablePath + "'";
+        + tablePath + "'";
 
     client.executeQueryAndGetResult(sql);
     assertTrue(client.existTable(tableName));
@@ -293,7 +292,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testCreateAndPurgeExternalTableByExecuteQuery() throws 
IOException, ServiceException {
+  public final void testCreateAndPurgeExternalTableByExecuteQuery() throws 
IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
CatalogUtil.normalizeIdentifier("testCreateAndPurgeExternalTableByExecuteQuery");
 
@@ -313,7 +312,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testCreateAndDropTableByExecuteQuery() throws IOException, 
ServiceException, SQLException {
+  public final void testCreateAndDropTableByExecuteQuery() throws IOException, 
SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
CatalogUtil.normalizeIdentifier("testCreateAndDropTableByExecuteQuery");
 
@@ -334,7 +333,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testCreateAndPurgeTableByExecuteQuery() throws 
IOException, ServiceException, SQLException {
+  public final void testCreateAndPurgeTableByExecuteQuery() throws 
IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
CatalogUtil.normalizeIdentifier("testCreateAndPurgeTableByExecuteQuery");
 
@@ -355,20 +354,20 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testDDLByExecuteQuery() throws IOException, 
ServiceException {
+  public final void testDDLByExecuteQuery() throws IOException, SQLException {
     final String tableName = 
CatalogUtil.normalizeIdentifier("testDDLByExecuteQuery");
     Path tablePath = writeTmpTable(tableName);
 
     assertFalse(client.existTable(tableName));
     String sql =
-      "create external table " + tableName + " (deptname text, score int4) "
-        + "using csv location '" + tablePath + "'";
+        "create external table " + tableName + " (deptname text, score int4) "
+            + "using csv location '" + tablePath + "'";
     client.executeQueryAndGetResult(sql);
     assertTrue(client.existTable(tableName));
   }
 
   @Test
-  public final void testGetTableList() throws IOException, ServiceException {
+  public final void testGetTableList() throws IOException, SQLException {
     String tableName1 = "GetTableList1".toLowerCase();
     String tableName2 = "GetTableList2".toLowerCase();
 
@@ -388,7 +387,7 @@ public class TestTajoClient {
   Log LOG = LogFactory.getLog(TestTajoClient.class);
 
   @Test
-  public final void testGetTableDesc() throws IOException, ServiceException, 
SQLException {
+  public final void testGetTableDesc() throws IOException, SQLException {
     final String tableName1 = CatalogUtil.normalizeIdentifier("table3");
     Path tablePath = writeTmpTable(tableName1);
     LOG.error("Full path:" + tablePath.toUri().getRawPath());
@@ -408,8 +407,7 @@ public class TestTajoClient {
   }
 
   //@Test
-  public final void testCreateAndDropTablePartitionedHash1ByExecuteQuery() 
throws IOException,
-    ServiceException, SQLException {
+  public final void testCreateAndDropTablePartitionedHash1ByExecuteQuery() 
throws IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
"testCreateAndDropTablePartitionedHash1ByExecuteQuery";
 
@@ -432,8 +430,7 @@ public class TestTajoClient {
   }
 
   //@Test
-  public final void testCreateAndPurgeTablePartitionedHash1ByExecuteQuery() 
throws IOException,
-    ServiceException, SQLException {
+  public final void testCreateAndPurgeTablePartitionedHash1ByExecuteQuery() 
throws IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
"testCreateAndPurgeTablePartitionedHash1ByExecuteQuery";
 
@@ -456,8 +453,7 @@ public class TestTajoClient {
   }
 
   //@Test
-  public final void testCreateAndDropTablePartitionedHash2ByExecuteQuery() 
throws IOException,
-    ServiceException, SQLException {
+  public final void testCreateAndDropTablePartitionedHash2ByExecuteQuery() 
throws IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
"testCreateAndDropTablePartitionedHash2ByExecuteQuery";
 
@@ -480,8 +476,7 @@ public class TestTajoClient {
   }
 
   //@Test
-  public final void testCreateAndDropTablePartitionedListByExecuteQuery() 
throws IOException,
-    ServiceException, SQLException {
+  public final void testCreateAndDropTablePartitionedListByExecuteQuery() 
throws IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
"testCreateAndDropTablePartitionedListByExecuteQuery";
 
@@ -505,8 +500,7 @@ public class TestTajoClient {
   }
 
   //@Test
-  public final void testCreateAndDropTablePartitionedRangeByExecuteQuery() 
throws IOException,
-    ServiceException, SQLException {
+  public final void testCreateAndDropTablePartitionedRangeByExecuteQuery() 
throws IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
"testCreateAndDropTablePartitionedRangeByExecuteQuery";
 
@@ -525,14 +519,13 @@ public class TestTajoClient {
     FileSystem hdfs = tablePath.getFileSystem(conf);
     assertTrue(hdfs.exists(tablePath));
 
-    client.updateQuery("drop table " + tableName +" purge");
+    client.updateQuery("drop table " + tableName + " purge");
     assertFalse(client.existTable(tableName));
     assertFalse(hdfs.exists(tablePath));
   }
 
   @Test
-  public final void testFailCreateTablePartitionedOtherExceptColumn() throws 
IOException,
-    ServiceException, SQLException {
+  public final void testFailCreateTablePartitionedOtherExceptColumn() throws 
IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = "testFailCreateTablePartitionedOtherExceptColumn";
 
@@ -544,25 +537,39 @@ public class TestTajoClient {
     rangeSql += "PARTITION sub_part2 VALUES LESS THAN (5),";
     rangeSql += "PARTITION sub_part2 VALUES LESS THAN (MAXVALUE) )";
 
-    assertFalse(client.updateQuery(rangeSql));
-
+    try {
+      client.updateQuery(rangeSql);
+      fail();
+    } catch (SQLException se) {
+      assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), 
se.getErrorCode());
+    }
+ 
     String listSql = "create table " + tableName + " (deptname text, score 
int4)";
     listSql += "PARTITION BY LIST (deptname)";
     listSql += "( PARTITION sub_part1 VALUES('r&d', 'design'),";
     listSql += "PARTITION sub_part2 VALUES('sales', 'hr') )";
 
-    assertFalse(client.updateQuery(listSql));
+    try {
+      assertFalse(client.updateQuery(listSql));
+      fail();
+    } catch (SQLException se) {
+      assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), 
se.getErrorCode());
+    }
 
     String hashSql = "create table " + tableName + " (deptname text, score 
int4)";
     hashSql += "PARTITION BY HASH (deptname)";
     hashSql += "PARTITIONS 2";
 
-    assertFalse(client.updateQuery(hashSql));
+    try {
+      assertFalse(client.updateQuery(hashSql));
+      fail();
+    } catch (SQLException se) {
+      assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), 
se.getErrorCode());
+    }
   }
 
   @Test
-  public final void testCreateAndDropTablePartitionedColumnByExecuteQuery() 
throws IOException,
-    ServiceException, SQLException {
+  public final void testCreateAndDropTablePartitionedColumnByExecuteQuery() 
throws IOException, SQLException {
     TajoConf conf = cluster.getConfiguration();
     final String tableName = 
CatalogUtil.normalizeIdentifier("testCreateAndDropTablePartitionedColumnByExecuteQuery");
 
@@ -584,8 +591,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testGetFunctions() throws IOException,
-    ServiceException, SQLException {
+  public final void testGetFunctions() throws IOException, SQLException {
     Collection<FunctionDesc> catalogFunctions = 
cluster.getMaster().getCatalog().getFunctions();
     String functionName = "sum";
     int numFunctions = 0;
@@ -606,8 +612,7 @@ public class TestTajoClient {
   }
 
   @Test
-  public final void testGetFinishedQueryList() throws IOException,
-    ServiceException, SQLException {
+  public final void testGetFinishedQueryList() throws IOException, 
SQLException {
     final String tableName = 
CatalogUtil.normalizeIdentifier("testGetFinishedQueryList");
     String sql = "create table " + tableName + " (deptname text, score int4)";
 
@@ -678,15 +683,15 @@ public class TestTajoClient {
   @Test
   public void testNullCharSessionInCTAS() throws Exception {
     String sql =
-      "create table nullcharsession as select\n" +
-        "  c_custkey,\n" +
-        "  orders.o_orderkey,\n" +
-        "  orders.o_orderstatus \n" +
-        "from\n" +
-        "  orders full outer join customer on c_custkey = o_orderkey\n" +
-        "order by\n" +
-        "  c_custkey,\n" +
-        "  orders.o_orderkey;\n";
+        "create table nullcharsession as select\n" +
+          "  c_custkey,\n" +
+          "  orders.o_orderkey,\n" +
+          "  orders.o_orderstatus \n" +
+          "from\n" +
+          "  orders full outer join customer on c_custkey = o_orderkey\n" +
+          "order by\n" +
+          "  c_custkey,\n" +
+          "  orders.o_orderkey;\n";
 
     Map<String, String> variables = new HashMap<String, String>();
     variables.put(SessionVars.NULL_CHAR.keyname(), "\\\\T");
@@ -720,10 +725,10 @@ public class TestTajoClient {
 
     // text type field's value is replaced with \T
     String expected = "1|1|O\n" +
-      "2|2|O\n" +
-      "3|3|F\n" +
-      "4||\\T\n" +
-      "5||\\T\n";
+        "2|2|O\n" +
+        "3|3|F\n" +
+        "4||\\T\n" +
+        "5||\\T\n";
 
     String resultDatas = new String(buf, 0, readBytes);
 
@@ -757,7 +762,7 @@ public class TestTajoClient {
     assertEquals(2, queryHistory.getStageHistoriesCount());
 
     List<ClientProtos.StageHistoryProto> taskHistories =
-      new ArrayList<StageHistoryProto>(queryHistory.getStageHistoriesList());
+        new ArrayList<StageHistoryProto>(queryHistory.getStageHistoriesList());
     Collections.sort(taskHistories, new Comparator<StageHistoryProto>() {
       @Override
       public int compare(ClientProtos.StageHistoryProto o1, StageHistoryProto 
o2) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java 
b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java
new file mode 100644
index 0000000..d43f61c
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java
@@ -0,0 +1,75 @@
+/**
+ * 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 net.jcip.annotations.NotThreadSafe;
+import org.apache.tajo.TajoTestingCluster;
+import org.apache.tajo.TpchTestBase;
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.SQLException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+@NotThreadSafe
+public class TestTajoClientFailures {
+  private static TajoTestingCluster cluster;
+  private static TajoClient client;
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    cluster = TpchTestBase.getInstance().getTestingCluster();
+    client = cluster.newTajoClient();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    client.close();
+  }
+
+  @Test
+  public final void testCreateDatabase() throws SQLException {
+    assertFalse(client.createDatabase("default")); // duplicate database
+  }
+
+  @Test
+  public final void testDropDatabase() throws SQLException {
+    assertFalse(client.dropDatabase("unknown-database")); // unknown database
+  }
+
+  @Test
+  public final void testDropTable() throws SQLException {
+    assertFalse(client.dropTable("unknown-table")); // unknown table
+  }
+
+  @Test
+  public void testExecuteSQL() throws SQLException {
+    // This is just an error propagation unit test. Specified SQL errors will 
be addressed in other unit tests.
+    ReturnState state = client.executeQuery("select * from 
unknown_table").getState();
+    assertEquals(Errors.ResultCode.UNDEFINED_TABLE, state.getReturnCode());
+
+    state = client.executeQuery("create table default.lineitem (name 
int);").getState();
+    assertEquals(Errors.ResultCode.DUPLICATE_TABLE, state.getReturnCode());
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
index 07a09ad..b9bdbf5 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
@@ -142,18 +142,18 @@ public class ExprTestBase {
     Expr expr = analyzer.parse(parsedResults.get(0).getHistoryStatement());
     VerificationState state = new VerificationState();
     preLogicalPlanVerifier.verify(context, state, expr);
-    if (state.getErrorMessages().size() > 0) {
-      if (!condition && state.getErrorMessages().size() > 0) {
-        throw new PlanningException(state.getErrorMessages().get(0));
+    if (state.getErrors().size() > 0) {
+      if (!condition && state.getErrors().size() > 0) {
+        throw new PlanningException(state.getErrors().get(0));
       }
-      assertFalse(state.getErrorMessages().get(0), true);
+      assertFalse(state.getErrors().get(0).getMessage(), true);
     }
     LogicalPlan plan = planner.createPlan(context, expr, true);
     optimizer.optimize(context, plan);
     annotatedPlanVerifier.verify(context, state, plan);
 
-    if (state.getErrorMessages().size() > 0) {
-      assertFalse(state.getErrorMessages().get(0), true);
+    if (state.getErrors().size() > 0) {
+      assertFalse(state.getErrors().get(0).getMessage(), true);
     }
 
     Target [] targets = plan.getRootBlock().getRawTargets();

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
index b04d544..8d81ae8 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
@@ -21,7 +21,7 @@ package org.apache.tajo.engine.eval;
 import org.apache.tajo.SessionVars;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
-import org.apache.tajo.catalog.exception.NoSuchFunctionException;
+import org.apache.tajo.catalog.exception.UndefinedFunctionException;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.TimestampDatum;
@@ -53,11 +53,11 @@ public class TestSQLExpression extends ExprTestBase {
   public void testNoSuchFunction() throws IOException {
     try {
       testSimpleEval("select test123('abc') col1 ", new String[]{"abc"});
-      fail("This test should throw NoSuchFunctionException");
-    } catch (NoSuchFunctionException e) {
+      fail("This test should throw UndefinedFunctionException");
+    } catch (UndefinedFunctionException e) {
       //success
     } catch (Exception e) {
-      fail("This test should throw NoSuchFunctionException: " + e);
+      fail("This test should throw UndefinedFunctionException: " + e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
 
b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
index bec8cd3..1d35139 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
@@ -20,7 +20,7 @@ package org.apache.tajo.engine.function;
 
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
-import org.apache.tajo.catalog.exception.NoSuchFunctionException;
+import org.apache.tajo.catalog.exception.UndefinedFunctionException;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.engine.eval.ExprTestBase;
 import org.junit.Test;
@@ -151,7 +151,7 @@ public class TestConditionalExpressions extends 
ExprTestBase {
     try {
       testSimpleEval("select coalesce(null, 2, 'value3');", new String[]{"2"});
       fail("coalesce(NULL, INT, TEXT) not defined. So should throw 
exception.");
-    } catch (NoSuchFunctionException e) {
+    } catch (UndefinedFunctionException e) {
       //success
     }
   }
@@ -170,7 +170,7 @@ public class TestConditionalExpressions extends 
ExprTestBase {
     try {
       testSimpleEval("select coalesce(null, 'value2', 3);", new String[]{"2"});
       fail("coalesce(NULL, TEXT, INT) not defined. So should throw 
exception.");
-    } catch (NoSuchFunctionException e) {
+    } catch (UndefinedFunctionException e) {
       //success
     }
   }
@@ -189,14 +189,14 @@ public class TestConditionalExpressions extends 
ExprTestBase {
     try {
       testSimpleEval("select coalesce('value1', null, 3.0);", new 
String[]{"1.0"});
       fail("coalesce(TEXT, NULL, FLOAT8) not defined. So should throw 
exception.");
-    } catch (NoSuchFunctionException e) {
+    } catch (UndefinedFunctionException e) {
       // success
     }
 
     try {
       testSimpleEval("select coalesce(null, 'value2', 3.0);", new 
String[]{"2.0"});
       fail("coalesce(NULL, TEXT, FLOAT8) not defined. So should throw 
exception.");
-    } catch (NoSuchFunctionException e) {
+    } catch (UndefinedFunctionException e) {
       //success
     }
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinQuery.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinQuery.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinQuery.java
index a0b5d9a..ad851e7 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinQuery.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinQuery.java
@@ -29,6 +29,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import java.sql.ResultSet;
+import java.sql.SQLException;
 
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
@@ -45,7 +46,7 @@ public class TestInnerJoinQuery extends TestJoinQuery {
   }
 
   @AfterClass
-  public static void classTearDown() throws ServiceException {
+  public static void classTearDown() throws SQLException {
     TestJoinQuery.classTearDown();
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinWithSubQuery.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinWithSubQuery.java
 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinWithSubQuery.java
index 2bcb5d9..1869946 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinWithSubQuery.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInnerJoinWithSubQuery.java
@@ -29,6 +29,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import java.sql.ResultSet;
+import java.sql.SQLException;
 
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
@@ -45,7 +46,7 @@ public class TestInnerJoinWithSubQuery extends TestJoinQuery {
   }
 
   @AfterClass
-  public static void classTearDown() throws ServiceException {
+  public static void classTearDown() throws SQLException {
     TestJoinQuery.classTearDown();
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinOnPartitionedTables.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinOnPartitionedTables.java
 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinOnPartitionedTables.java
index d769c13..f605ccf 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinOnPartitionedTables.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinOnPartitionedTables.java
@@ -32,6 +32,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import java.sql.ResultSet;
+import java.sql.SQLException;
 
 import static org.apache.tajo.TajoConstants.DEFAULT_DATABASE_NAME;
 import static org.junit.Assert.assertEquals;
@@ -67,7 +68,7 @@ public class TestJoinOnPartitionedTables extends 
TestJoinQuery {
   }
 
   @AfterClass
-  public static void classTearDown() throws ServiceException {
+  public static void classTearDown() throws SQLException {
     TestJoinQuery.classTearDown();
     client.executeQuery("DROP TABLE IF EXISTS customer_parts PURGE");
     client.executeQuery("DROP TABLE IF EXISTS nation_partitioned PURGE");

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
index dd67e06..4ef5e9b 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
@@ -43,6 +43,7 @@ import org.junit.runners.Parameterized.Parameters;
 
 import java.io.File;
 import java.io.OutputStream;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -109,7 +110,7 @@ public class TestJoinQuery extends QueryTestCaseBase {
     }
   }
 
-  public static void classTearDown() throws ServiceException {
+  public static void classTearDown() throws SQLException {
     
testingCluster.setAllTajoDaemonConfValue(ConfVars.$TEST_BROADCAST_JOIN_ENABLED.varname,
         ConfVars.$TEST_BROADCAST_JOIN_ENABLED.defaultVal);
     
testingCluster.setAllTajoDaemonConfValue(ConfVars.$DIST_QUERY_BROADCAST_JOIN_THRESHOLD.varname,
@@ -193,7 +194,7 @@ public class TestJoinQuery extends QueryTestCaseBase {
     addEmptyDataFile("nation_multifile", false);
   }
 
-  protected static void dropCommonTables() throws ServiceException {
+  protected static void dropCommonTables() throws SQLException {
     LOG.info("Clear common tables for join tests");
 
     client.executeQuery("DROP TABLE IF EXISTS jointable11 PURGE;");
@@ -210,7 +211,7 @@ public class TestJoinQuery extends QueryTestCaseBase {
     Tuple createTuple(String[] columnDatas);
   }
 
-  private static String buildSchemaString(String tableName) throws 
ServiceException {
+  private static String buildSchemaString(String tableName) throws 
ServiceException, SQLException {
     TableDesc desc = client.getTableDesc(tableName);
     StringBuffer sb = new StringBuffer();
     for (Column column : desc.getSchema().getRootColumns()) {
@@ -225,7 +226,7 @@ public class TestJoinQuery extends QueryTestCaseBase {
     return sb.toString();
   }
 
-  private static String buildMultifileDDlString(String tableName) throws 
ServiceException {
+  private static String buildMultifileDDlString(String tableName) throws 
ServiceException, SQLException {
     String multiTableName = tableName + "_multifile";
     StringBuilder sb = new StringBuilder("create table 
").append(multiTableName).append(" (");
     sb.append(buildSchemaString(tableName)).append(" )");

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/query/TestMultipleJoinTypes.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestMultipleJoinTypes.java
 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestMultipleJoinTypes.java
index b772d90..b4ab1d7 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestMultipleJoinTypes.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestMultipleJoinTypes.java
@@ -29,6 +29,8 @@ import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import java.sql.SQLException;
+
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
 @NamedTest("TestJoinQuery")
@@ -44,7 +46,7 @@ public class TestMultipleJoinTypes extends TestJoinQuery {
   }
 
   @AfterClass
-  public static void classTearDown() throws ServiceException {
+  public static void classTearDown() throws SQLException {
     TestJoinQuery.classTearDown();
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinQuery.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinQuery.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinQuery.java
index 18eba41..5274d2c 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinQuery.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinQuery.java
@@ -28,6 +28,9 @@ import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
 @NamedTest("TestJoinQuery")
@@ -43,7 +46,7 @@ public class TestOuterJoinQuery extends TestJoinQuery {
   }
 
   @AfterClass
-  public static void classTearDown() throws ServiceException {
+  public static void classTearDown() throws SQLException {
     TestJoinQuery.classTearDown();
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinWithSubQuery.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinWithSubQuery.java
 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinWithSubQuery.java
index 71db027..8e7094d 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinWithSubQuery.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestOuterJoinWithSubQuery.java
@@ -27,6 +27,8 @@ import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import java.sql.SQLException;
+
 import static org.junit.Assert.assertEquals;
 
 @Category(IntegrationTest.class)
@@ -44,7 +46,7 @@ public class TestOuterJoinWithSubQuery extends TestJoinQuery {
   }
 
   @AfterClass
-  public static void classTearDown() throws ServiceException {
+  public static void classTearDown() throws SQLException {
     TestJoinQuery.classTearDown();
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
index ef57356..77bfca6 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestTablePartitions.java
@@ -31,6 +31,7 @@ import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.exception.ReturnStateUtil;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.engine.planner.global.DataChannel;
@@ -864,8 +865,8 @@ public class TestTablePartitions extends QueryTestCaseBase {
     ClientProtos.SubmitQueryResponse response = client.executeQuery("insert 
overwrite into " + tableName
         + " select l_orderkey, l_partkey from lineitem");
 
-    assertTrue(response.hasErrorMessage());
-    assertEquals(response.getErrorMessage(), "INSERT has smaller expressions 
than target columns\n");
+    assertTrue(ReturnStateUtil.isError(response.getState()));
+    assertEquals(response.getState().getMessage(), "INSERT has smaller 
expressions than target columns");
 
     res = executeFile("case14.sql");
     assertResultSet(res, "case14.result");
@@ -890,8 +891,8 @@ public class TestTablePartitions extends QueryTestCaseBase {
       response = client.executeQuery("insert overwrite into " + tableName
         + " select l_returnflag , l_orderkey, l_partkey from lineitem");
 
-      assertTrue(response.hasErrorMessage());
-      assertEquals(response.getErrorMessage(), "INSERT has smaller expressions 
than target columns\n");
+      assertTrue(ReturnStateUtil.isError(response.getState()));
+      assertEquals(response.getState().getMessage(), "INSERT has smaller 
expressions than target columns");
 
       res = executeFile("case15.sql");
       assertResultSet(res, "case15.result");

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/jdbc/TestSQLState.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestSQLState.java 
b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestSQLState.java
new file mode 100644
index 0000000..e711524
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestSQLState.java
@@ -0,0 +1,91 @@
+/*
+ * 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.jdbc;
+
+import com.google.common.collect.Maps;
+import org.apache.hadoop.io.IOUtils;
+import org.apache.tajo.*;
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.client.QueryClient;
+import org.apache.tajo.client.QueryStatus;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.net.InetSocketAddress;
+import java.sql.*;
+import java.util.*;
+
+import static org.apache.tajo.TajoConstants.DEFAULT_DATABASE_NAME;
+import static org.junit.Assert.*;
+
+@Category(IntegrationTest.class)
+public class TestSQLState extends QueryTestCaseBase {
+  private static InetSocketAddress tajoMasterAddress;
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    tajoMasterAddress = 
testingCluster.getMaster().getTajoMasterClientService().getBindAddress();
+    Class.forName("org.apache.tajo.jdbc.TajoDriver").newInstance();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+  }
+
+  static String buildConnectionUri(String hostName, int port, String 
databaseName) {
+    return "jdbc:tajo://" + hostName + ":" + port + "/" + databaseName;
+  }
+
+  private Connection makeConnection() throws SQLException {
+    String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), 
tajoMasterAddress.getPort(),
+        DEFAULT_DATABASE_NAME);
+    Connection conn = DriverManager.getConnection(connUri);
+    assertTrue(conn.isValid(100));
+
+    return conn;
+  }
+
+  public void assertSQLState(String sql, String sqlState) throws SQLException {
+    Connection conn = null;
+    Statement stmt = null;
+    ResultSet res = null;
+
+    try {
+      conn = makeConnection();
+      stmt = conn.createStatement();
+      res = stmt.executeQuery(sql);
+    } catch (SQLException se) {
+      assertEquals(sqlState, se.getSQLState());
+    } catch (Throwable t) {
+      fail(t.getMessage());
+    } finally {
+      CatalogUtil.closeQuietly(stmt, res);
+      CatalogUtil.closeQuietly(conn);
+    }
+  }
+
+  @Test
+  public void testSyntaxError() throws Exception {
+    assertSQLState("selec x,y,x from lineitem", "42601");
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java 
b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
index 0f49bc1..1adad41 100644
--- a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
+++ b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
@@ -619,7 +619,7 @@ public class TestTajoJdbc extends QueryTestCaseBase {
         result  = stmt.executeUpdate("alter table " + tableName + " add 
partition (key = 0.1)");
         assertEquals(result, 1);
      }
-    } finally {
+    } finally {      
       cleanupQuery(resultSet);
       if (stmt != null) {
         stmt.close();

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java
 
b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java
index 7942b5e..210d38d 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java
@@ -22,7 +22,8 @@ import com.google.gson.internal.StringMap;
 import org.apache.tajo.QueryTestCaseBase;
 import org.apache.tajo.TajoConstants;
 import org.apache.tajo.conf.TajoConf.ConfVars;
-import org.apache.tajo.ipc.ClientProtos.ResultCode;
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.exception.ErrorUtil;
 import org.apache.tajo.master.QueryInfo;
 import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
 import org.apache.tajo.ws.rs.requests.NewSessionRequest;
@@ -40,8 +41,6 @@ import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
@@ -95,7 +94,7 @@ public class TestQueryResource extends QueryTestCaseBase {
         .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), 
NewSessionResponse.class);
     
     assertNotNull(response);
-    assertTrue(ResultCode.OK.equals(response.getResultCode()));
+    assertTrue(ErrorUtil.isOk(response.getResultCode()));
     assertTrue(response.getId() != null && !response.getId().isEmpty());
     
     return response.getId();

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java
 
b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java
index 2e45e9a..23d004c 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java
@@ -22,7 +22,9 @@ import org.apache.commons.codec.binary.Base64;
 import org.apache.tajo.QueryTestCaseBase;
 import org.apache.tajo.TajoConstants;
 import org.apache.tajo.conf.TajoConf.ConfVars;
-import org.apache.tajo.ipc.ClientProtos.ResultCode;
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.exception.ErrorUtil;
 import org.apache.tajo.storage.RowStoreUtil;
 import org.apache.tajo.storage.Tuple;
 import org.apache.tajo.util.TUtil;
@@ -53,6 +55,7 @@ import java.net.URI;
 import java.security.MessageDigest;
 import java.util.List;
 
+import static org.apache.tajo.exception.ErrorUtil.isOk;
 import static org.junit.Assert.*;
 
 public class TestQueryResultResource extends QueryTestCaseBase {
@@ -100,7 +103,7 @@ public class TestQueryResultResource extends 
QueryTestCaseBase {
         .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), 
NewSessionResponse.class);
 
     assertNotNull(response);
-    assertTrue(ResultCode.OK.equals(response.getResultCode()));
+    assertTrue(isOk(response.getResultCode()));
     assertTrue(response.getId() != null && !response.getId().isEmpty());
 
     return response.getId();
@@ -140,7 +143,7 @@ public class TestQueryResultResource extends 
QueryTestCaseBase {
 
     assertNotNull(response);
     assertNotNull(response.getResultCode());
-    assertEquals(ResultCode.OK, response.getResultCode());
+    assertTrue(isOk(response.getResultCode()));
     assertNotNull(response.getSchema());
     assertEquals(16, response.getSchema().getRootColumns().size());
     assertNotNull(response.getResultset());
@@ -174,7 +177,7 @@ public class TestQueryResultResource extends 
QueryTestCaseBase {
 
     assertNotNull(response);
     assertNotNull(response.getResultCode());
-    assertEquals(ResultCode.OK, response.getResultCode());
+    assertTrue(ErrorUtil.isOk(response.getResultCode()));
     assertNotNull(response.getSchema());
     assertEquals(16, response.getSchema().getRootColumns().size());
     assertNotNull(response.getResultset());
@@ -236,7 +239,7 @@ public class TestQueryResultResource extends 
QueryTestCaseBase {
 
     assertNotNull(response);
     assertNotNull(response.getResultCode());
-    assertEquals(ResultCode.OK, response.getResultCode());
+    assertTrue(isOk(response.getResultCode()));
     assertNotNull(response.getSchema());
     assertEquals(16, response.getSchema().getRootColumns().size());
     assertNotNull(response.getResultset());

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java
 
b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java
index 26a8da1..5d1ada8 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java
@@ -22,6 +22,8 @@ import org.apache.tajo.QueryTestCaseBase;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.error.Errors.ResultCode;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
 import org.apache.tajo.ws.rs.requests.NewSessionRequest;
@@ -99,7 +101,7 @@ public class TestTablesResource extends QueryTestCaseBase {
                        .request().post(Entity.entity(request, 
MediaType.APPLICATION_JSON), NewSessionResponse.class);
 
                assertNotNull(response);
-               
assertTrue(ClientProtos.ResultCode.OK.equals(response.getResultCode()));
+               assertTrue(ResultCode.OK.equals(response.getResultCode()));
                assertTrue(response.getId() != null && 
!response.getId().isEmpty());
 
                return response.getId();
@@ -115,7 +117,7 @@ public class TestTablesResource extends QueryTestCaseBase {
                                new 
GenericType<GetSubmitQueryResponse>(GetSubmitQueryResponse.class));
 
                assertNotNull(response);
-               assertEquals(ClientProtos.ResultCode.OK, 
response.getResultCode());
+               assertEquals(ResultCode.OK, response.getResultCode());
        }
 
   @Test

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/resources/results/TestTajoCli/testAlterTableAddDropPartition.result
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/resources/results/TestTajoCli/testAlterTableAddDropPartition.result
 
b/tajo-core/src/test/resources/results/TestTajoCli/testAlterTableAddDropPartition.result
index c16c311..d01038a 100644
--- 
a/tajo-core/src/test/resources/results/TestTajoCli/testAlterTableAddDropPartition.result
+++ 
b/tajo-core/src/test/resources/results/TestTajoCli/testAlterTableAddDropPartition.result
@@ -2,7 +2,7 @@ OK
 ERROR: "key2" column is not the partition key of 
"default.testaltertableaddpartition".
 OK
 OK
-ERROR: "key=0.1" is not the partition of "testaltertableaddpartition".
+ERROR: partition 'key=0.1' does not exist
 OK
 OK
 OK

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result 
b/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result
index 183e6c5..e2e6b34 100644
--- a/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result
+++ b/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result
@@ -2,4 +2,4 @@
 -------------------------------
 5
 (1 rows, , 2 B selected)
-ERROR: relation "default.lineitem2" does not exist
+ERROR: relation 'default.lineitem2' does not exist
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result
 
b/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result
index 5c49139..17b4d56 100644
--- 
a/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result
+++ 
b/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result
@@ -3,4 +3,4 @@ Warning: deprecated to directly use config key in 
TajoConf.ConfVars. Please exec
 -------------------------------
 5
 (1 rows, , 2 B selected)
-ERROR: relation "default.lineitem2" does not exist
+ERROR: relation 'default.lineitem2' does not exist
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java
----------------------------------------------------------------------
diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java 
b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java
index d575968..6db1447 100644
--- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java
+++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java
@@ -217,11 +217,7 @@ public class JdbcConnection implements Connection {
 
   @Override
   public String getCatalog() throws SQLException {
-    try {
-      return tajoClient.getCurrentDatabase();
-    } catch (ServiceException e) {
-      throw new SQLException(e);
-    }
+    return tajoClient.getCurrentDatabase();
   }
 
   @Override
@@ -271,21 +267,13 @@ public class JdbcConnection implements Connection {
 
   @Override
   public boolean isValid(int timeout) throws SQLException {
-    try {
-      if (tajoClient.isConnected()) {
-        ResultSet resultSet = tajoClient.executeQueryAndGetResult("SELECT 1;");
-        boolean next = resultSet.next();
-        boolean valid = next && resultSet.getLong(1) == 1;
-        resultSet.close();
-        return valid;
-      } else {
-        return false;
-      }
-    } catch (ServiceException e) {
-      LOG.error("TajoMaster is not available.", e);
-      return false;
-    } catch (IOException e) {
-      LOG.error("JDBC connection is not valid.", e);
+    if (tajoClient.isConnected()) {
+      ResultSet resultSet = tajoClient.executeQueryAndGetResult("SELECT 1;");
+      boolean next = resultSet.next();
+      boolean valid = next && resultSet.getLong(1) == 1;
+      resultSet.close();
+      return valid;
+    } else {
       return false;
     }
   }
@@ -369,22 +357,16 @@ public class JdbcConnection implements Connection {
 
   @Override
   public void setCatalog(String catalog) throws SQLException {
-    try {
-      tajoClient.selectDatabase(catalog);
-    } catch (ServiceException e) {
-      throw new SQLException(e);
-    }
+    tajoClient.selectDatabase(catalog);
   }
 
   @Override
-  public void setClientInfo(Properties properties)
-      throws SQLClientInfoException {
+  public void setClientInfo(Properties properties) throws 
SQLClientInfoException {
     throw new UnsupportedOperationException("setClientInfo");
   }
 
   @Override
-  public void setClientInfo(String name, String value)
-      throws SQLClientInfoException {
+  public void setClientInfo(String name, String value) throws 
SQLClientInfoException {
     throw new UnsupportedOperationException("setClientInfo");
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java
----------------------------------------------------------------------
diff --git 
a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java 
b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java
index d4ef55e..0474258 100644
--- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java
+++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java
@@ -422,11 +422,8 @@ public class TajoDatabaseMetaData implements 
DatabaseMetaData {
   @Override
   public ResultSet getSchemas() throws SQLException {
     String databaseName;
-    try {
-      databaseName = conn.getQueryClient().getCurrentDatabase();
-    } catch (ServiceException e) {
-      throw new SQLException(e);
-    }
+
+    databaseName = conn.getQueryClient().getCurrentDatabase();
 
     MetaDataTuple tuple = new MetaDataTuple(2);
     tuple.put(0, new TextDatum(DEFAULT_SCHEMA_NAME));
@@ -441,11 +438,8 @@ public class TajoDatabaseMetaData implements 
DatabaseMetaData {
   @Override
   public ResultSet getCatalogs() throws SQLException {
     Collection<String> databaseNames;
-    try {
-      databaseNames = conn.getCatalogAdminClient().getAllDatabaseNames();
-    } catch (ServiceException e) {
-      throw new SQLException(e);
-    }
+
+    databaseNames = conn.getCatalogAdminClient().getAllDatabaseNames();
 
     List<MetaDataTuple> tuples = new ArrayList<MetaDataTuple>();
     for (String databaseName : databaseNames) {
@@ -765,11 +759,8 @@ public class TajoDatabaseMetaData implements 
DatabaseMetaData {
   @Override
   public ResultSet getSchemas(String catalog, String schemaPattern) throws 
SQLException {
     String databaseName;
-    try {
-      databaseName = conn.getQueryClient().getCurrentDatabase();
-    } catch (ServiceException e) {
-      throw new SQLException(e);
-    }
+
+    databaseName = conn.getQueryClient().getCurrentDatabase();
 
     MetaDataTuple tuple = new MetaDataTuple(2);
     tuple.put(0, new TextDatum(DEFAULT_SCHEMA_NAME));

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
----------------------------------------------------------------------
diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java 
b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
index 0f80ddf..60f7ca3 100644
--- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
+++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
@@ -18,14 +18,13 @@
 package org.apache.tajo.jdbc;
 
 import com.google.common.collect.Lists;
-import com.google.protobuf.ServiceException;
 import org.apache.tajo.QueryId;
 import org.apache.tajo.SessionVars;
+import org.apache.tajo.exception.SQLExceptionUtil;
 import org.apache.tajo.client.TajoClient;
 import org.apache.tajo.client.TajoClientUtil;
 import org.apache.tajo.ipc.ClientProtos;
 
-import java.io.IOException;
 import java.sql.*;
 import java.util.HashMap;
 import java.util.Map;
@@ -146,15 +145,11 @@ public class TajoStatement implements Statement {
   @Override
   public ResultSet executeQuery(String sql) throws SQLException {
     checkConnection("Can't execute");
+    return executeSQL(sql);
 
-    try {
-      return executeSQL(sql);
-    } catch (Exception e) {
-      throw new SQLException(e.getMessage(), e);
-    }
   }
 
-  protected ResultSet executeSQL(String sql) throws SQLException, 
ServiceException, IOException {
+  protected ResultSet executeSQL(String sql) throws SQLException {
     if (isSetVariableQuery(sql)) {
       return setSessionVariable(tajoClient, sql);
     }
@@ -163,15 +158,7 @@ public class TajoStatement implements Statement {
     }
 
     ClientProtos.SubmitQueryResponse response = tajoClient.executeQuery(sql);
-    if (response.getResultCode() == ClientProtos.ResultCode.ERROR) {
-      if (response.hasErrorMessage()) {
-        throw new ServiceException(response.getErrorMessage());
-      }
-      if (response.hasErrorTrace()) {
-        throw new ServiceException(response.getErrorTrace());
-      }
-      throw new ServiceException("Failed to submit query by unknown reason");
-    }
+    SQLExceptionUtil.throwIfError(response.getState());
 
     QueryId queryId = new QueryId(response.getQueryId());
     if (response.getIsForwarded() && !queryId.isNull()) {
@@ -222,12 +209,7 @@ public class TajoStatement implements Statement {
     }
     Map<String, String> variable = new HashMap<String, String>();
     variable.put(tokens[0].trim(), tokens[1].trim());
-    try {
-      client.updateSessionVariables(variable);
-    } catch (ServiceException e) {
-      throw new SQLException(e.getMessage(), e);
-    }
-
+    client.updateSessionVariables(variable);
     return TajoClientUtil.createNullResultSet();
   }
 
@@ -241,11 +223,7 @@ public class TajoStatement implements Statement {
     if (key.isEmpty()) {
       throw new SQLException("UNSET statement should be <KEY>: " + sql);
     }
-    try {
-      client.unsetSessionVariables(Lists.newArrayList(key));
-    } catch (ServiceException e) {
-      throw new SQLException(e.getMessage(), e);
-    }
+    client.unsetSessionVariables(Lists.newArrayList(key));
 
     return TajoClientUtil.createNullResultSet();
   }
@@ -253,13 +231,8 @@ public class TajoStatement implements Statement {
   @Override
   public int executeUpdate(String sql) throws SQLException {
     checkConnection("Can't execute update");
-    try {
-      tajoClient.executeQuery(sql);
-
-      return 1;
-    } catch (Exception ex) {
-      throw new SQLException(ex.toString());
-    }
+    tajoClient.executeQuery(sql);
+    return 1;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java 
b/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java
index 7467dcd..453edd5 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java
@@ -27,14 +27,16 @@ import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Column;
 import org.apache.tajo.catalog.FunctionDesc;
-import org.apache.tajo.catalog.exception.NoSuchFunctionException;
+import org.apache.tajo.catalog.exception.UndefinedFunctionException;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.datum.*;
-import org.apache.tajo.exception.InternalException;
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.error.Errors.ResultCode;
 import org.apache.tajo.exception.InvalidOperationException;
+import org.apache.tajo.exception.SQLExceptionUtil;
+import org.apache.tajo.function.FunctionUtil;
 import org.apache.tajo.plan.algebra.BaseAlgebraVisitor;
 import org.apache.tajo.plan.expr.*;
-import org.apache.tajo.plan.function.AggFunction;
 import org.apache.tajo.plan.logical.NodeType;
 import org.apache.tajo.plan.nameresolver.NameResolver;
 import org.apache.tajo.plan.nameresolver.NameResolvingMode;
@@ -43,7 +45,7 @@ import org.apache.tajo.util.TUtil;
 import org.apache.tajo.util.datetime.DateTimeUtil;
 import org.apache.tajo.util.datetime.TimeMeta;
 
-import java.io.IOException;
+import java.sql.SQLException;
 import java.util.Set;
 import java.util.Stack;
 import java.util.TimeZone;
@@ -579,7 +581,7 @@ public class ExprAnnotator extends 
BaseAlgebraVisitor<ExprAnnotator.Context, Eva
     stack.pop(); // <--- Pop
 
     if (!catalog.containFunction(expr.getSignature(), paramTypes)) {
-      throw new NoSuchFunctionException(expr.getSignature(), paramTypes);
+      throw new UndefinedFunctionException(expr.getSignature(), paramTypes);
     }
 
     FunctionDesc funcDesc = catalog.getFunction(expr.getSignature(), 
paramTypes);
@@ -605,27 +607,21 @@ public class ExprAnnotator extends 
BaseAlgebraVisitor<ExprAnnotator.Context, Eva
     }
 
 
-    try {
-      FunctionType functionType = funcDesc.getFuncType();
-      if (functionType == FunctionType.GENERAL
-          || functionType == FunctionType.UDF) {
-        return new GeneralFunctionEval(ctx.queryContext, funcDesc, givenArgs);
-      } else if (functionType == FunctionType.AGGREGATION
-          || functionType == FunctionType.UDA) {
-        if (!ctx.currentBlock.hasNode(NodeType.GROUP_BY)) {
-          ctx.currentBlock.setAggregationRequire();
-        }
-        return new AggregationFunctionCallEval(funcDesc, givenArgs);
-      } else if (functionType == FunctionType.DISTINCT_AGGREGATION
-          || functionType == FunctionType.DISTINCT_UDA) {
-        throw new PlanningException("Unsupported function: " + 
funcDesc.toString());
-      } else {
-        throw new PlanningException("Unsupported Function Type: " + 
functionType.name());
+    FunctionType functionType = funcDesc.getFuncType();
+    if (functionType == FunctionType.GENERAL
+        || functionType == FunctionType.UDF) {
+      return new GeneralFunctionEval(ctx.queryContext, funcDesc, givenArgs);
+    } else if (functionType == FunctionType.AGGREGATION
+        || functionType == FunctionType.UDA) {
+      if (!ctx.currentBlock.hasNode(NodeType.GROUP_BY)) {
+        ctx.currentBlock.setAggregationRequire();
       }
-    } catch (InternalException e) {
-      throw new PlanningException(e);
-    } catch (IOException e) {
-      throw new PlanningException(e);
+      return new AggregationFunctionCallEval(funcDesc, givenArgs);
+    } else if (functionType == FunctionType.DISTINCT_AGGREGATION
+        || functionType == FunctionType.DISTINCT_UDA) {
+      throw new PlanningException("Unsupported function: " + 
funcDesc.toString());
+    } else {
+      throw new PlanningException("Unsupported Function Type: " + 
functionType.name());
     }
   }
 
@@ -635,7 +631,7 @@ public class ExprAnnotator extends 
BaseAlgebraVisitor<ExprAnnotator.Context, Eva
     FunctionDesc countRows = catalog.getFunction("count", 
FunctionType.AGGREGATION,
         new DataType[] {});
     if (countRows == null) {
-      throw new NoSuchFunctionException(expr.getSignature(), new DataType[]{});
+      throw new UndefinedFunctionException(expr.getSignature(), new 
DataType[]{});
     }
 
     ctx.currentBlock.setAggregationRequire();
@@ -660,7 +656,7 @@ public class ExprAnnotator extends 
BaseAlgebraVisitor<ExprAnnotator.Context, Eva
     }
 
     if (!catalog.containFunction(setFunction.getSignature(), functionType, 
paramTypes)) {
-      throw new NoSuchFunctionException(setFunction.getSignature(), 
paramTypes);
+      throw new UndefinedFunctionException(setFunction.getSignature(), 
paramTypes);
     }
 
     FunctionDesc funcDesc = catalog.getFunction(setFunction.getSignature(), 
functionType, paramTypes);
@@ -741,7 +737,7 @@ public class ExprAnnotator extends 
BaseAlgebraVisitor<ExprAnnotator.Context, Eva
     // the below checking against WINDOW_FUNCTIONS is a workaround code for 
the above problem.
     if (WINDOW_FUNCTIONS.contains(funcName.toLowerCase())) {
       if (distinct) {
-        throw new NoSuchFunctionException("row_number() does not support 
distinct keyword.");
+        throw new UndefinedFunctionException("row_number() does not support 
distinct keyword.");
       }
       functionType = FunctionType.WINDOW;
     } else {
@@ -749,7 +745,7 @@ public class ExprAnnotator extends 
BaseAlgebraVisitor<ExprAnnotator.Context, Eva
     }
 
     if (!catalog.containFunction(windowFunc.getSignature(), functionType, 
paramTypes)) {
-      throw new NoSuchFunctionException(funcName, paramTypes);
+      throw new UndefinedFunctionException(funcName, paramTypes);
     }
 
     FunctionDesc funcDesc = catalog.getFunction(funcName, functionType, 
paramTypes);

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-plan/src/main/java/org/apache/tajo/plan/ExprNormalizer.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/ExprNormalizer.java 
b/tajo-plan/src/main/java/org/apache/tajo/plan/ExprNormalizer.java
index 2a6cb0b..d61049e 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/ExprNormalizer.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/ExprNormalizer.java
@@ -21,7 +21,7 @@ package org.apache.tajo.plan;
 import com.google.common.collect.Sets;
 import org.apache.tajo.algebra.*;
 import org.apache.tajo.catalog.CatalogUtil;
-import org.apache.tajo.catalog.exception.NoSuchColumnException;
+import org.apache.tajo.catalog.exception.UndefinedColumnException;
 import org.apache.tajo.plan.nameresolver.NameResolver;
 import org.apache.tajo.plan.nameresolver.NameResolvingMode;
 import org.apache.tajo.plan.visitor.SimpleAlgebraVisitor;
@@ -344,7 +344,7 @@ class ExprNormalizer extends 
SimpleAlgebraVisitor<ExprNormalizer.ExprNormalizedR
           String normalized =
               NameResolver.resolve(ctx.plan, ctx.block, expr, 
NameResolvingMode.LEGACY).getQualifiedName();
           expr.setName(normalized);
-        } catch (NoSuchColumnException nsc) {
+        } catch (UndefinedColumnException nsc) {
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanPreprocessor.java
----------------------------------------------------------------------
diff --git 
a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanPreprocessor.java 
b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanPreprocessor.java
index 5fa5a21..2006e88 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanPreprocessor.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanPreprocessor.java
@@ -21,7 +21,7 @@ package org.apache.tajo.plan;
 import org.apache.tajo.SessionVars;
 import org.apache.tajo.algebra.*;
 import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.exception.NoSuchColumnException;
+import org.apache.tajo.catalog.exception.UndefinedColumnException;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.plan.LogicalPlan.QueryBlock;
 import org.apache.tajo.plan.algebra.BaseAlgebraVisitor;
@@ -109,7 +109,7 @@ public class LogicalPlanPreprocessor extends 
BaseAlgebraVisitor<LogicalPlanner.P
 
       // If we cannot find any relation against a qualified column name
       if (relationOp == null) {
-        throw new NoSuchColumnException(CatalogUtil.buildFQName(qualifier, 
"*"));
+        throw new UndefinedColumnException(CatalogUtil.buildFQName(qualifier, 
"*"));
       }
 
       Schema schema = relationOp.getLogicalSchema();
@@ -128,7 +128,7 @@ public class LogicalPlanPreprocessor extends 
BaseAlgebraVisitor<LogicalPlanner.P
       }
 
       if (resolvedColumns.size() == 0) {
-        throw new NoSuchColumnException(asteriskExpr.toString());
+        throw new UndefinedColumnException(asteriskExpr.toString());
       }
 
       return resolvedColumns.toArray(new Column[resolvedColumns.size()]);

Reply via email to