tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [3/8] tajo git commit: TAJO-1748: Refine client APIs to throw specific exceptions.
Date Thu, 13 Aug 2015 11:52:40 GMT
http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedFunctionException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedFunctionException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedFunctionException.java
new file mode 100644
index 0000000..0b22970
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedFunctionException.java
@@ -0,0 +1,35 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UndefinedFunctionException extends TajoException {
+	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/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedIndexException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedIndexException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedIndexException.java
new file mode 100644
index 0000000..3f4db74
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedIndexException.java
@@ -0,0 +1,38 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UndefinedIndexException extends TajoException {
+  private static final long serialVersionUID = 3705839985189534673L;
+
+  public UndefinedIndexException(ReturnState state) {
+    super(state);
+  }
+
+  public UndefinedIndexException(String tableName, String columnName) {
+    super(ResultCode.UNDEFINED_INDEX_FOR_COLUMNS, tableName, columnName);
+  }
+
+  public UndefinedIndexException(String indexName) {
+    super(ResultCode.UNDEFINED_INDEX_NAME, indexName);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionException.java
new file mode 100644
index 0000000..c0ec7d5
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionException.java
@@ -0,0 +1,35 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UndefinedPartitionException extends TajoException {
+
+  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/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionKeyException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionKeyException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionKeyException.java
new file mode 100644
index 0000000..19219ff
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionKeyException.java
@@ -0,0 +1,34 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UndefinedPartitionKeyException extends TajoException {
+
+  @SuppressWarnings("unused")
+  public UndefinedPartitionKeyException(ReturnState state) {
+    super(state);
+  }
+
+  public UndefinedPartitionKeyException(String partitionKey) {
+    super(ResultCode.UNDEFINED_PARTITION_KEY, partitionKey);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionMethodException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionMethodException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionMethodException.java
new file mode 100644
index 0000000..459269c
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedPartitionMethodException.java
@@ -0,0 +1,35 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UndefinedPartitionMethodException extends TajoException {
+
+  private static final long serialVersionUID = 277182608283894949L;
+
+  public UndefinedPartitionMethodException(ReturnState state) {
+    super(state);
+  }
+
+  public UndefinedPartitionMethodException(String partitionName) {
+    super(ResultCode.UNDEFINED_PARTITION_METHOD, partitionName);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedTableException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedTableException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedTableException.java
new file mode 100644
index 0000000..6060142
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedTableException.java
@@ -0,0 +1,39 @@
+/**
+ * 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.exception;
+
+
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UndefinedTableException extends TajoException {
+	private static final long serialVersionUID = 277182608283894937L;
+
+  public UndefinedTableException(ReturnState state) {
+    super(state);
+  }
+
+  public UndefinedTableException(String dbName, String tbName) {
+		super(ResultCode.UNDEFINED_TABLE, dbName + "." + tbName);
+  }
+
+	public UndefinedTableException(String relName) {
+		super(ResultCode.UNDEFINED_TABLE, relName);
+	}
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedTablespaceException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedTablespaceException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedTablespaceException.java
new file mode 100644
index 0000000..eef1648
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedTablespaceException.java
@@ -0,0 +1,34 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UndefinedTablespaceException extends TajoException {
+	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/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UnimplementedException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UnimplementedException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UnimplementedException.java
deleted file mode 100644
index b32079f..0000000
--- a/tajo-common/src/main/java/org/apache/tajo/exception/UnimplementedException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tajo.exception;
-
-import org.apache.tajo.error.Errors;
-
-public class UnimplementedException extends TajoRuntimeException {
-  private static final long serialVersionUID = -5467580471721530536L;
-
-  public UnimplementedException() {
-    super(Errors.ResultCode.NOT_IMPLEMENTED,
-        Thread.currentThread().getStackTrace()[1].getClassName());
-  }
-
-  public UnimplementedException(String featureName) {
-    super(Errors.ResultCode.NOT_IMPLEMENTED, featureName);
-  }
-}

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UnknownDataFormatException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UnknownDataFormatException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UnknownDataFormatException.java
new file mode 100644
index 0000000..74ee125
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UnknownDataFormatException.java
@@ -0,0 +1,36 @@
+/*
+ * 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.exception;
+
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UnknownDataFormatException extends TajoException {
+
+  private static final long serialVersionUID = -2630390595968966164L;
+
+  public UnknownDataFormatException(ReturnState state) {
+    super(state);
+
+  }
+
+  public UnknownDataFormatException(String dataFormat) {
+    super(Errors.ResultCode.UNKNOWN_DATAFORMAT, dataFormat);
+  }
+}

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

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedDataTypeException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedDataTypeException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedDataTypeException.java
new file mode 100644
index 0000000..65ec777
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedDataTypeException.java
@@ -0,0 +1,35 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UnsupportedDataTypeException extends TajoException {
+
+  private static final long serialVersionUID = -2630390595968966164L;
+
+  public UnsupportedDataTypeException(ReturnState state) {
+    super(state);
+  }
+
+  public UnsupportedDataTypeException(String dataType) {
+    super(Errors.ResultCode.UNKNOWN_DATAFORMAT, dataType);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/java/org/apache/tajo/storage/VTuple.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/storage/VTuple.java b/tajo-common/src/main/java/org/apache/tajo/storage/VTuple.java
index 12570d7..90bb7fa 100644
--- a/tajo-common/src/main/java/org/apache/tajo/storage/VTuple.java
+++ b/tajo-common/src/main/java/org/apache/tajo/storage/VTuple.java
@@ -24,7 +24,7 @@ import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.Inet4Datum;
 import org.apache.tajo.datum.IntervalDatum;
 import org.apache.tajo.datum.ProtobufDatum;
-import org.apache.tajo.exception.UnimplementedException;
+import org.apache.tajo.exception.NotImplementedException;
 import org.apache.tajo.util.datetime.TimeMeta;
 
 import java.net.InetAddress;
@@ -185,11 +185,11 @@ public class VTuple implements Tuple, Cloneable {
   }
 
   public InetAddress getIPv6(int fieldId) {
-    throw new UnimplementedException("IPv6 is unsupported yet");
+    throw new NotImplementedException("IPv6 is unsupported yet");
   }
 
   public byte[] getIPv6Bytes(int fieldId) {
-    throw new UnimplementedException("IPv6 is unsupported yet");
+    throw new NotImplementedException("IPv6 is unsupported yet");
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-common/src/main/proto/errors.proto
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/proto/errors.proto b/tajo-common/src/main/proto/errors.proto
index 0bc0069..4057456 100644
--- a/tajo-common/src/main/proto/errors.proto
+++ b/tajo-common/src/main/proto/errors.proto
@@ -79,9 +79,12 @@ enum ResultCode {
   INVALID_RPC_CALL              = 204; // When invalid RPC call is invoked (e.g., wrong message and absent fields)
 
   // Query Management and Scheduler
-  NO_SUCH_QUERYID               = 301; // No query id in TajoMaster
-  NO_DATA                       = 302; // No data due to query fail or error
-  INCOMPLETE_QUERY              = 303; // It occurs when a client requests something of a completed query.
+  QUERY_FAILED                  = 301; // SQLState: ? - Query failed
+  QUERY_KILLED                  = 302; // SQLState: ? - Query killed
+  QUERY_TIMEOUT                 = 303; // SQLState: ? - Timeout for the query
+  QUERY_NOT_FOUND               = 304; // No such query in TajoMaster
+  NO_DATA                       = 305; // No data due to query fail or error
+  INCOMPLETE_QUERY              = 306; // It occurs when a client requests something of a completed query.
 
   // Session
   INVALID_SESSION               = 401; // Session already was invalid
@@ -154,11 +157,15 @@ enum ResultCode {
   CAT_UPGRADE_REQUIRED                  = 901;  // Migration
   CAT_CANNOT_CONNECT                    = 902;  // Cannot connect metadata server
 
-  // MetaData Connector (MDC)
-  MDC_NO_MATCHED_DATATYPE               = 910;  // No matched data type between Tajo and connector
+  // Linked Metadata (LMD)
+  LMD_NO_MATCHED_DATATYPE               = 910;  // No matched data type between Tajo and connector
 
   // Storage and Data Format
-  UNKNOWN_DATAFORMAT                    = 1001; // Unknown Data Format
+  UNAVAILABLE_TABLE_LOCATION            = 1001; // SQLState: ? - Unavailable table location
+  UNKNOWN_DATAFORMAT                    = 1002; // SQLState: ? - Unknown Data Format
+  UNSUPPORTED_DATATYPE                  = 1003; // SQLState: ? - Unsupported data type
+  INVALID_TABLE_PROPERTY                = 1004; // SQLState: ? - Invalid Table Property
+  MISSING_TABLE_PROPERTY                = 1005; // SQLState: ? - Missing table property
 
 
   CLIENT_CONNECTION_EXCEPTION           = 1101; // SQLState: 08000 - Client connection error

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/engine/function/FailFunction.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/FailFunction.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/FailFunction.java
new file mode 100644
index 0000000..9dc3ded
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/FailFunction.java
@@ -0,0 +1,70 @@
+/*
+ * 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.engine.function;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.exception.TajoInternalError;
+import org.apache.tajo.plan.function.GeneralFunction;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+    functionName = "fail",
+    description = "Cause some error if the second parameter value is greater than the first parameter",
+    example = "> SELECT fail(1, col1, 'message');\n"
+        + "1",
+    returnType = Type.INT4,
+    paramTypes = {
+        @ParamTypes(paramTypes = {Type.INT4, Type.INT4, Type.TEXT}),
+    }
+)
+public class FailFunction extends GeneralFunction {
+
+  public FailFunction() {
+    super(new Column[]{
+        new Column("trigger", TajoDataTypes.Type.INT4),
+        new Column("input_number", TajoDataTypes.Type.INT4),
+        new Column("message", TajoDataTypes.Type.TEXT)
+    });
+  }
+
+  @Override
+  public Datum eval(Tuple params) {
+
+    // to skip the plannin phase
+    if (params.isBlankOrNull(0) && params.isBlankOrNull(1)) {
+      return DatumFactory.createInt4(params.getInt4(0));
+    }
+
+    final int trigger = params.getInt4(0);
+    final int num = params.getInt4(1);
+    final String msg = params.getText(2);
+
+    if (num >= trigger) {
+      throw new TajoInternalError(msg);
+    }
+
+    return DatumFactory.createInt4(params.getInt4(0));
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java b/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
index 67ae684..d89a404 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
@@ -31,6 +31,7 @@ import org.apache.tajo.algebra.CreateIndex.IndexMethodSpec;
 import org.apache.tajo.algebra.LiteralValue.LiteralType;
 import org.apache.tajo.algebra.Sort.SortSpec;
 import org.apache.tajo.engine.parser.SQLParser.*;
+import org.apache.tajo.exception.SQLSyntaxError;
 import org.apache.tajo.storage.StorageConstants;
 import org.apache.tajo.util.StringUtils;
 
@@ -62,7 +63,7 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
       parser.addErrorListener(new SQLErrorListener());
       context = parser.sql();
     } catch (SQLParseError e) {
-      throw new SQLSyntaxError(e);
+      throw new SQLSyntaxError(e.getMessage());
     }
     return visitSql(context);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLSyntaxError.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLSyntaxError.java b/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLSyntaxError.java
deleted file mode 100644
index 0b50d4b..0000000
--- a/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLSyntaxError.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tajo.engine.parser;
-
-
-import org.apache.tajo.error.Errors;
-import org.apache.tajo.exception.TajoRuntimeException;
-import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
-import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
-
-public class SQLSyntaxError extends TajoRuntimeException {
-  private static final long serialVersionUID = 5388279335175632067L;
-
-  private transient String detailedMessage;
-
-  public SQLSyntaxError(String errorMessage) {
-    super(Errors.ResultCode.SYNTAX_ERROR, errorMessage);
-  }
-
-  public SQLSyntaxError(SQLParseError e) {
-    super(Errors.ResultCode.SYNTAX_ERROR, e.getMessageHeader());
-  }
-
-  @Override
-  public String getMessage() {
-    if (detailedMessage == null) {
-      if (getCause() != null) {
-        detailedMessage = getCause().getMessage();
-      } else {
-        detailedMessage = String.format("ERROR: %s\n", super.getMessage());
-      }
-    }
-    return detailedMessage;
-  }
-}

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlanner.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlanner.java
index 0983dc6..ec85544 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlanner.java
@@ -21,16 +21,13 @@
  */
 package org.apache.tajo.engine.planner;
 
-import org.apache.tajo.worker.TaskAttemptContext;
-import org.apache.tajo.plan.logical.LogicalNode;
 import org.apache.tajo.engine.planner.physical.PhysicalExec;
-import org.apache.tajo.exception.InternalException;
+import org.apache.tajo.plan.logical.LogicalNode;
+import org.apache.tajo.worker.TaskAttemptContext;
 
 /**
  * This class generates a physical execution plan.
  */
 public interface PhysicalPlanner {
-  PhysicalExec createPlan(TaskAttemptContext context,
-                          LogicalNode logicalPlan)
-      throws InternalException;
+  PhysicalExec createPlan(TaskAttemptContext context, LogicalNode logicalPlan);
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlannerImpl.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlannerImpl.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlannerImpl.java
index 7b1b1d7..5bbf3a9 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlannerImpl.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/PhysicalPlannerImpl.java
@@ -16,9 +16,6 @@
  * limitations under the License.
  */
 
-/**
- *
- */
 package org.apache.tajo.engine.planner;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -38,7 +35,7 @@ import org.apache.tajo.engine.planner.enforce.Enforcer;
 import org.apache.tajo.engine.planner.global.DataChannel;
 import org.apache.tajo.engine.planner.physical.*;
 import org.apache.tajo.engine.query.QueryContext;
-import org.apache.tajo.exception.InternalException;
+import org.apache.tajo.exception.TajoInternalError;
 import org.apache.tajo.plan.serder.PlanProto.DistinctGroupbyEnforcer;
 import org.apache.tajo.plan.serder.PlanProto.DistinctGroupbyEnforcer.DistinctAggregationAlgorithm;
 import org.apache.tajo.plan.serder.PlanProto.DistinctGroupbyEnforcer.MultipleAggregationStage;
@@ -83,8 +80,7 @@ public class PhysicalPlannerImpl implements PhysicalPlanner {
     this.conf = conf;
   }
 
-  public PhysicalExec createPlan(final TaskAttemptContext context, final LogicalNode logicalPlan)
-      throws InternalException {
+  public PhysicalExec createPlan(final TaskAttemptContext context, final LogicalNode logicalPlan) {
 
     PhysicalExec execPlan;
 
@@ -101,7 +97,7 @@ public class PhysicalPlannerImpl implements PhysicalPlanner {
         return execPlan;
       }
     } catch (IOException ioe) {
-      throw new InternalException(ioe);
+      throw new TajoInternalError(ioe);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
index 07445a4..b10dd1b 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
@@ -29,9 +29,6 @@ import org.apache.tajo.ExecutionBlockId;
 import org.apache.tajo.SessionVars;
 import org.apache.tajo.algebra.JoinType;
 import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.exception.AmbiguousFunctionException;
-import org.apache.tajo.catalog.exception.CatalogException;
-import org.apache.tajo.catalog.exception.UndefinedFunctionException;
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.common.TajoDataTypes;
@@ -40,9 +37,11 @@ import org.apache.tajo.engine.planner.global.builder.DistinctGroupbyBuilder;
 import org.apache.tajo.engine.planner.global.rewriter.GlobalPlanRewriteEngine;
 import org.apache.tajo.engine.planner.global.rewriter.GlobalPlanRewriteRuleProvider;
 import org.apache.tajo.engine.query.QueryContext;
-import org.apache.tajo.exception.*;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.exception.TajoInternalError;
+import org.apache.tajo.exception.NotImplementedException;
+import org.apache.tajo.exception.UnsupportedException;
 import org.apache.tajo.plan.LogicalPlan;
-import org.apache.tajo.plan.PlanningException;
 import org.apache.tajo.plan.Target;
 import org.apache.tajo.plan.expr.*;
 import org.apache.tajo.plan.logical.*;
@@ -346,32 +345,32 @@ public class GlobalPlanner {
     }
   }
 
-  private AggregationFunctionCallEval createSumFunction(EvalNode[] args) throws CatalogException {
+  private AggregationFunctionCallEval createSumFunction(EvalNode[] args) throws TajoException {
     FunctionDesc functionDesc = null;
     functionDesc = getCatalog().getFunction("sum", CatalogProtos.FunctionType.AGGREGATION,
         args[0].getValueType());
     return new AggregationFunctionCallEval(functionDesc, args);
   }
 
-  private AggregationFunctionCallEval createCountFunction(EvalNode [] args) throws CatalogException {
+  private AggregationFunctionCallEval createCountFunction(EvalNode [] args) throws TajoException {
     FunctionDesc functionDesc = getCatalog().getFunction("count", CatalogProtos.FunctionType.AGGREGATION,
         args[0].getValueType());
     return new AggregationFunctionCallEval(functionDesc, args);
   }
 
-  private AggregationFunctionCallEval createCountRowFunction(EvalNode[] args) throws CatalogException {
+  private AggregationFunctionCallEval createCountRowFunction(EvalNode[] args) throws TajoException {
     FunctionDesc functionDesc = getCatalog().getFunction("count", CatalogProtos.FunctionType.AGGREGATION,
         new TajoDataTypes.DataType[]{});
     return new AggregationFunctionCallEval(functionDesc, args);
   }
 
-  private AggregationFunctionCallEval createMaxFunction(EvalNode [] args) throws CatalogException {
+  private AggregationFunctionCallEval createMaxFunction(EvalNode [] args) throws TajoException {
     FunctionDesc functionDesc = getCatalog().getFunction("max", CatalogProtos.FunctionType.AGGREGATION,
         args[0].getValueType());
     return new AggregationFunctionCallEval(functionDesc, args);
   }
 
-  private AggregationFunctionCallEval createMinFunction(EvalNode [] args) throws CatalogException {
+  private AggregationFunctionCallEval createMinFunction(EvalNode [] args) throws TajoException {
     FunctionDesc functionDesc = getCatalog().getFunction("min", CatalogProtos.FunctionType.AGGREGATION,
         args[0].getValueType());
     return new AggregationFunctionCallEval(functionDesc, args);
@@ -847,7 +846,7 @@ public class GlobalPlanner {
       // Verify supported partition types
       PartitionMethodDesc partitionMethod = currentNode.getPartitionMethod();
       if (partitionMethod.getPartitionType() != CatalogProtos.PartitionType.COLUMN) {
-        throw new UnimplementedException("partition type '" + partitionMethod.getPartitionType().name() + "'");
+        throw new NotImplementedException("partition type '" + partitionMethod.getPartitionType().name() + "'");
       }
 
       if (hasUnionChild(currentNode)) { // if it has union children

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java b/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
index 2ad45ba..20780ec 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
@@ -36,10 +36,12 @@ import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.engine.parser.SQLAnalyzer;
-import org.apache.tajo.engine.parser.SQLSyntaxError;
+import org.apache.tajo.exception.SQLSyntaxError;
 import org.apache.tajo.engine.query.QueryContext;
 import org.apache.tajo.exception.ExceptionUtil;
 import org.apache.tajo.exception.ReturnStateUtil;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.exception.TajoRuntimeException;
 import org.apache.tajo.master.TajoMaster.MasterContext;
 import org.apache.tajo.master.exec.DDLExecutor;
 import org.apache.tajo.master.exec.QueryExecutor;
@@ -305,6 +307,10 @@ public class GlobalEngine extends AbstractService {
 
           TablespaceManager.get(tableDesc.getUri()).get().verifySchemaToWrite(tableDesc, outSchema);
 
+        } catch (TajoException t) {
+          state.addVerification(t);
+        } catch (TajoRuntimeException t) {
+          state.addVerification(t);
         } catch (Throwable t) {
           state.addVerification(SyntaxErrorUtil.makeSyntaxError(t.getMessage()));
         }

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java b/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java
index 27aabfc..3ec09aa 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java
@@ -38,10 +38,11 @@ import org.apache.tajo.catalog.CatalogServer;
 import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.FunctionDesc;
 import org.apache.tajo.catalog.LocalCatalogWrapper;
-import org.apache.tajo.catalog.exception.DuplicateDatabaseException;
+import org.apache.tajo.exception.DuplicateDatabaseException;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.conf.TajoConf.ConfVars;
 import org.apache.tajo.engine.function.FunctionLoader;
+import org.apache.tajo.exception.DuplicateTablespaceException;
 import org.apache.tajo.function.FunctionSignature;
 import org.apache.tajo.master.rm.TajoResourceManager;
 import org.apache.tajo.metrics.ClusterResourceMetricSet;
@@ -371,7 +372,9 @@ public class TajoMaster extends CompositeService {
     }
   }
 
-  private void checkBaseTBSpaceAndDatabase() throws IOException, DuplicateDatabaseException {
+  private void checkBaseTBSpaceAndDatabase()
+      throws IOException, DuplicateDatabaseException, DuplicateTablespaceException {
+
     if (!catalog.existTablespace(DEFAULT_TABLESPACE_NAME)) {
       catalog.createTablespace(DEFAULT_TABLESPACE_NAME, context.getConf().getVar(ConfVars.WAREHOUSE_DIR));
     } else {

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java b/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java
index 72e52b2..d6ace8f 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java
@@ -33,14 +33,16 @@ import org.apache.tajo.QueryIdFactory;
 import org.apache.tajo.TajoIdProtos;
 import org.apache.tajo.TajoProtos.QueryState;
 import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
 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.conf.TajoConf;
 import org.apache.tajo.conf.TajoConf.ConfVars;
 import org.apache.tajo.engine.query.QueryContext;
+import org.apache.tajo.exception.QueryNotFoundException;
 import org.apache.tajo.exception.ReturnStateUtil;
+import org.apache.tajo.exception.UnavailableTableLocationException;
+import org.apache.tajo.exception.UndefinedDatabaseException;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.*;
 import org.apache.tajo.ipc.TajoMasterClientProtocol;
@@ -186,7 +188,6 @@ public class TajoMasterClientService extends AbstractService {
           context.getSessionManager().removeVariable(sessionId, unsetVariable);
         }
 
-
         builder.setState(OK);
         builder.setSessionVars(new KeyValueSet(context.getSessionManager().getAllVariables(sessionId)).getProto());
         return builder.build();
@@ -540,9 +541,13 @@ public class TajoMasterClientService extends AbstractService {
 
         QueryId queryId = new QueryId(request.getQueryId());
         NonForwardQueryResultScanner queryResultScanner = session.getNonForwardQueryResultScanner(queryId);
+
         if (queryResultScanner == null) {
+
           QueryInfo queryInfo = context.getQueryJobManager().getFinishedQuery(queryId);
-          Preconditions.checkNotNull(queryInfo, "QueryInfo cannot be NULL.");
+          if (queryInfo == null) {
+            throw new QueryNotFoundException(queryId.toString());
+          }
 
           TableDesc resultTableDesc = queryInfo.getResultDesc();
           Preconditions.checkNotNull(resultTableDesc, "QueryInfo::getResultDesc results in NULL.");
@@ -603,7 +608,7 @@ public class TajoMasterClientService extends AbstractService {
     }
 
     @Override
-    public GetQueryInfoResponse getQueryInfo(RpcController controller, QueryIdRequest request) throws ServiceException {
+    public GetQueryInfoResponse getQueryInfo(RpcController controller, QueryIdRequest request) {
       GetQueryInfoResponse.Builder builder = GetQueryInfoResponse.newBuilder();
 
       try {
@@ -620,9 +625,11 @@ public class TajoMasterClientService extends AbstractService {
           queryInfo = queryInProgress.getQueryInfo();
         }
 
-        if (queryInfo != null) {
-          builder.setQueryInfo(queryInfo.getProto());
+        if (queryInfo == null) {
+          throw new QueryNotFoundException(queryId.toString());
         }
+
+        builder.setQueryInfo(queryInfo.getProto());
         builder.setState(OK);
 
       } catch (Throwable t) {
@@ -697,14 +704,11 @@ public class TajoMasterClientService extends AbstractService {
     @Override
     public ReturnState createDatabase(RpcController controller, SessionedStringProto request) throws ServiceException {
       try {
-        Session session = context.getSessionManager().getSession(request.getSessionId().getId());
-        QueryContext queryContext = new QueryContext(conf, session);
+        final Session session = context.getSessionManager().getSession(request.getSessionId().getId());
+        final QueryContext queryContext = new QueryContext(conf, session);
 
-        if (context.getGlobalEngine().getDDLExecutor().createDatabase(queryContext, request.getValue(), null, false)) {
-          return OK;
-        } else {
-          return errDuplicateDatabase(request.getValue());
-        }
+        context.getGlobalEngine().getDDLExecutor().createDatabase(queryContext, request.getValue(), null, false);
+        return OK;
 
       } catch (Throwable t) {
         printStackTraceIfError(LOG, t);
@@ -731,14 +735,11 @@ public class TajoMasterClientService extends AbstractService {
     @Override
     public ReturnState dropDatabase(RpcController controller, SessionedStringProto request) throws ServiceException {
       try {
-        Session session = context.getSessionManager().getSession(request.getSessionId().getId());
-        QueryContext queryContext = new QueryContext(conf, session);
+        final Session session = context.getSessionManager().getSession(request.getSessionId().getId());
+        final QueryContext queryContext = new QueryContext(conf, session);
 
-        if (context.getGlobalEngine().getDDLExecutor().dropDatabase(queryContext, request.getValue(), false)) {
-          return OK;
-        } else {
-          return errUndefinedDatabase(request.getValue());
-        }
+        context.getGlobalEngine().getDDLExecutor().dropDatabase(queryContext, request.getValue(), false);
+        return OK;
 
       } catch (Throwable t) {
         printStackTraceIfError(LOG, t);
@@ -873,7 +874,7 @@ public class TajoMasterClientService extends AbstractService {
         FileSystem fs = path.getFileSystem(conf);
 
         if (!fs.exists(path)) {
-          throw new IOException("No such a directory: " + path);
+          throw new UnavailableTableLocationException(path.toString(), "no such a directory");
         }
 
         Schema schema = new Schema(request.getSchema());

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java
index a43b95e..38f722d 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java
@@ -24,12 +24,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.exception.DuplicateTableException;
-import org.apache.tajo.catalog.exception.UndefinedTablespaceException;
+import org.apache.tajo.exception.*;
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
 import org.apache.tajo.engine.query.QueryContext;
-import org.apache.tajo.exception.TajoException;
-import org.apache.tajo.exception.TajoInternalError;
 import org.apache.tajo.master.TajoMaster;
 import org.apache.tajo.plan.logical.CreateTableNode;
 import org.apache.tajo.plan.util.PlannerUtil;
@@ -110,17 +107,13 @@ public class CreateTableExecutor {
     }
 
     tableSpace.createTable(desc, ifNotExists);
-
-    if (catalog.createTable(desc)) {
-      LOG.info("Table " + desc.getName() + " is created (" + desc.getStats().getNumBytes() + ")");
-      return desc;
-    } else {
-      LOG.info("Table creation " + tableName + " is failed.");
-      throw new TajoInternalError("Cannot create table \"" + tableName + "\"");
-    }
+    catalog.createTable(desc);
+    return desc;
   }
 
-  private TableDesc handlExistence(boolean ifNotExists, String qualifiedName) throws DuplicateTableException {
+  private TableDesc handlExistence(boolean ifNotExists, String qualifiedName)
+      throws DuplicateTableException, UndefinedTableException {
+
     if (ifNotExists) {
       LOG.info("relation \"" + qualifiedName + "\" is already exists.");
       return catalog.getTableDesc(qualifiedName);

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
index 19eba3e..f7e2fe9 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
@@ -27,19 +27,19 @@ import org.apache.tajo.algebra.AlterTableOpType;
 import org.apache.tajo.algebra.AlterTablespaceSetType;
 import org.apache.tajo.annotation.Nullable;
 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.AlterTablespaceProto;
 import org.apache.tajo.catalog.proto.CatalogProtos.PartitionKeyProto;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.engine.query.QueryContext;
-import org.apache.tajo.exception.TajoException;
-import org.apache.tajo.exception.TajoInternalError;
+import org.apache.tajo.exception.*;
 import org.apache.tajo.master.TajoMaster;
 import org.apache.tajo.plan.LogicalPlan;
 import org.apache.tajo.plan.logical.*;
 import org.apache.tajo.plan.util.PlannerUtil;
+import org.apache.tajo.storage.FileTablespace;
 import org.apache.tajo.storage.StorageUtil;
+import org.apache.tajo.storage.Tablespace;
 import org.apache.tajo.storage.TablespaceManager;
 import org.apache.tajo.util.Pair;
 
@@ -203,7 +203,8 @@ public class DDLExecutor {
    * Alter a given table
    */
   public static void alterTablespace(final TajoMaster.MasterContext context, final QueryContext queryContext,
-                                     final AlterTablespaceNode alterTablespace) {
+                                     final AlterTablespaceNode alterTablespace)
+      throws UndefinedTablespaceException, InsufficientPrivilegeException {
 
     final CatalogService catalog = context.getCatalog();
     final String spaceName = alterTablespace.getTablespaceName();
@@ -228,7 +229,7 @@ public class DDLExecutor {
 
   // Database Section
   //--------------------------------------------------------------------------
-  public boolean createDatabase(@Nullable QueryContext queryContext, String databaseName,
+  public void createDatabase(@Nullable QueryContext queryContext, String databaseName,
                                 @Nullable String tablespace,
                                 boolean ifNotExists) throws IOException, DuplicateDatabaseException {
 
@@ -244,30 +245,27 @@ public class DDLExecutor {
     if (exists) {
       if (ifNotExists) {
         LOG.info("database \"" + databaseName + "\" is already exists.");
-        return true;
+        return;
       } else {
         throw new DuplicateDatabaseException(databaseName);
       }
     }
 
-    if (catalog.createDatabase(databaseName, tablespaceName)) {
-      String normalized = databaseName;
-      Path databaseDir = StorageUtil.concatPath(context.getConf().getVar(TajoConf.ConfVars.WAREHOUSE_DIR), normalized);
-      FileSystem fs = databaseDir.getFileSystem(context.getConf());
-      fs.mkdirs(databaseDir);
-    }
-
-    return true;
+    catalog.createDatabase(databaseName, tablespaceName);
+    String normalized = databaseName;
+    Path databaseDir = StorageUtil.concatPath(context.getConf().getVar(TajoConf.ConfVars.WAREHOUSE_DIR), normalized);
+    FileSystem fs = databaseDir.getFileSystem(context.getConf());
+    fs.mkdirs(databaseDir);
   }
 
-  public boolean dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists)
-      throws UndefinedDatabaseException {
+  public void dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists)
+      throws UndefinedDatabaseException, InsufficientPrivilegeException {
 
     boolean exists = catalog.existDatabase(databaseName);
     if (!exists) {
       if (ifExists) { // DROP DATABASE IF EXISTS
         LOG.info("database \"" + databaseName + "\" does not exists.");
-        return true;
+        return;
       } else { // Otherwise, it causes an exception.
         throw new UndefinedDatabaseException(databaseName);
       }
@@ -277,9 +275,7 @@ public class DDLExecutor {
       throw new RuntimeException("ERROR: Cannot drop the current open database");
     }
 
-    boolean result = catalog.dropDatabase(databaseName);
-    LOG.info("database " + databaseName + " is dropped.");
-    return result;
+    catalog.dropDatabase(databaseName);
   }
 
   //--------------------------------------------------------------------------
@@ -293,8 +289,8 @@ public class DDLExecutor {
    * @param tableName to be dropped
    * @param purge     Remove all data if purge is true.
    */
-  public boolean dropTable(QueryContext queryContext, String tableName, boolean ifExists, boolean purge)
-      throws UndefinedTableException {
+  public void dropTable(QueryContext queryContext, String tableName, boolean ifExists, boolean purge)
+      throws TajoException {
 
     String databaseName;
     String simpleTableName;
@@ -312,7 +308,7 @@ public class DDLExecutor {
     if (!exists) {
       if (ifExists) { // DROP TABLE IF EXISTS
         LOG.info("relation \"" + qualifiedName + "\" is already exists.");
-        return true;
+        return;
       } else { // Otherwise, it causes an exception.
         throw new UndefinedTableException(qualifiedName);
       }
@@ -328,9 +324,7 @@ public class DDLExecutor {
         throw new InternalError(e.getMessage());
       }
     }
-
     LOG.info(String.format("relation \"%s\" is " + (purge ? " purged." : " dropped."), qualifiedName));
-    return true;
   }
 
   /**
@@ -361,15 +355,20 @@ public class DDLExecutor {
         throw new UndefinedTableException(qualifiedName);
       }
 
-      Path warehousePath = new Path(TajoConf.getWarehouseDir(context.getConf()), databaseName);
+      // only file-based tablespace is supported yet.
       TableDesc tableDesc = catalog.getTableDesc(databaseName, simpleTableName);
-      Path tablePath = new Path(tableDesc.getUri());
-      if (tablePath.getParent() == null ||
-          !tablePath.getParent().toUri().getPath().equals(warehousePath.toUri().getPath())) {
-        throw new IOException("Can't truncate external table:" + eachTableName + ", data dir=" + tablePath +
-            ", warehouse dir=" + warehousePath);
+
+      if (tableDesc.isExternal()) {
+        throw new UnsupportedException("table truncation on an external table '" + eachTableName + "'");
+      }
+
+      Tablespace space = TablespaceManager.get(tableDesc.getUri()).get();
+
+      if (space instanceof FileTablespace) {
+        tableDescList.add(tableDesc);
+      } else {
+        throw new UnsupportedException("table truncation on " + space.getName() + " storage");
       }
-      tableDescList.add(tableDesc);
     }
 
     for (TableDesc eachTable : tableDescList) {
@@ -397,8 +396,7 @@ public class DDLExecutor {
    */
   public void alterTable(TajoMaster.MasterContext context, final QueryContext queryContext,
                          final AlterTableNode alterTable)
-      throws IOException, UndefinedTableException, DuplicateTableException, DuplicateColumnException,
-      DuplicatePartitionException, UndefinedPartitionException, UndefinedPartitionKeyException, AmbiguousPartitionDirectoryExistException {
+      throws IOException, TajoException {
 
     final CatalogService catalog = context.getCatalog();
     final String tableName = alterTable.getTableName();
@@ -563,7 +561,7 @@ public class DDLExecutor {
   }
 
   private boolean ensureColumnPartitionKeys(String tableName, String[] columnNames)
-      throws UndefinedPartitionKeyException {
+      throws UndefinedPartitionKeyException, UndefinedTableException {
 
     for(String columnName : columnNames) {
       if (!ensureColumnPartitionKeys(tableName, columnName)) {
@@ -573,7 +571,7 @@ public class DDLExecutor {
     return true;
   }
 
-  private boolean ensureColumnPartitionKeys(String tableName, String columnName) {
+  private boolean ensureColumnPartitionKeys(String tableName, String columnName) throws UndefinedTableException {
     final TableDesc tableDesc = catalog.getTableDesc(tableName);
     if (tableDesc.getPartitionMethod().getExpressionSchema().contains(columnName)) {
       return true;
@@ -582,7 +580,7 @@ public class DDLExecutor {
     }
   }
 
-  private boolean ensureColumnExistance(String tableName, String columnName) {
+  private boolean ensureColumnExistance(String tableName, String columnName) throws UndefinedTableException {
     final TableDesc tableDesc = catalog.getTableDesc(tableName);
     return tableDesc.getSchema().containsByName(columnName);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
index 3f65831..bd5d696 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
@@ -26,7 +26,7 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.tajo.*;
 import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.exception.DuplicateIndexException;
+import org.apache.tajo.exception.DuplicateIndexException;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.statistics.TableStats;
 import org.apache.tajo.common.TajoDataTypes;
@@ -37,7 +37,6 @@ import org.apache.tajo.engine.planner.global.MasterPlan;
 import org.apache.tajo.engine.planner.physical.EvalExprExec;
 import org.apache.tajo.engine.planner.physical.InsertRowsExec;
 import org.apache.tajo.engine.query.QueryContext;
-import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.SerializedResultSet;
 import org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse;
 import org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse.ResultType;
@@ -61,7 +60,6 @@ import org.apache.tajo.plan.verifier.VerifyException;
 import org.apache.tajo.session.Session;
 import org.apache.tajo.storage.*;
 import org.apache.tajo.util.ProtoUtil;
-import org.apache.tajo.util.metrics.TajoMetrics;
 import org.apache.tajo.worker.TaskAttemptContext;
 
 import java.io.IOException;

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/querymaster/Query.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/querymaster/Query.java b/tajo-core/src/main/java/org/apache/tajo/querymaster/Query.java
index f351143..b09d5fd 100644
--- a/tajo-core/src/main/java/org/apache/tajo/querymaster/Query.java
+++ b/tajo-core/src/main/java/org/apache/tajo/querymaster/Query.java
@@ -45,6 +45,7 @@ import org.apache.tajo.engine.planner.global.ExecutionBlock;
 import org.apache.tajo.engine.planner.global.ExecutionBlockCursor;
 import org.apache.tajo.engine.planner.global.ExecutionQueue;
 import org.apache.tajo.engine.planner.global.MasterPlan;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.exception.TajoInternalError;
 import org.apache.tajo.plan.logical.*;
 import org.apache.tajo.engine.query.QueryContext;
@@ -473,7 +474,7 @@ public class Query implements EventHandler<QueryEvent> {
         try {
           LogicalRootNode rootNode = lastStage.getMasterPlan().getLogicalPlan().getRootBlock().getRoot();
           space.rollbackTable(rootNode.getChild());
-        } catch (IOException e) {
+        } catch (Throwable e) {
           LOG.warn(query.getId() + ", failed processing cleanup storage when query failed:" + e.getMessage(), e);
         }
       }
@@ -522,17 +523,11 @@ public class Query implements EventHandler<QueryEvent> {
           }
 
           // Store partitions to CatalogStore using alter table statement.
-          boolean result = catalog.addPartitions(databaseName, simpleTableName, partitions, true);
-          if (result) {
-            LOG.info(String.format("Complete adding for partition %s", partitions.size()));
-          } else {
-            LOG.info(String.format("Incomplete adding for partition %s", partitions.size()));
-          }
+          catalog.addPartitions(databaseName, simpleTableName, partitions, true);
         } else {
           LOG.info("Can't find partitions for adding.");
         }
 
-
       } catch (Exception e) {
         query.eventHandler.handle(new QueryDiagnosticsUpdateEvent(query.id, ExceptionUtils.getStackTrace(e)));
         return QueryState.QUERY_ERROR;

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/querymaster/QueryMasterTask.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/querymaster/QueryMasterTask.java b/tajo-core/src/main/java/org/apache/tajo/querymaster/QueryMasterTask.java
index ac1bab5..c6e2b35 100644
--- a/tajo-core/src/main/java/org/apache/tajo/querymaster/QueryMasterTask.java
+++ b/tajo-core/src/main/java/org/apache/tajo/querymaster/QueryMasterTask.java
@@ -37,6 +37,7 @@ import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.engine.planner.global.MasterPlan;
 import org.apache.tajo.engine.query.QueryContext;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.ipc.TajoWorkerProtocol;
 import org.apache.tajo.master.cluster.WorkerConnectionInfo;
 import org.apache.tajo.master.event.*;
@@ -370,7 +371,7 @@ public class QueryMasterTask extends CompositeService {
         LogicalRootNode rootNode = plan.getRootBlock().getRoot();
         try {
           space.rollbackTable(rootNode.getChild());
-        } catch (IOException e) {
+        } catch (Throwable e) {
           LOG.warn(query.getId() + ", failed processing cleanup storage when query failed:" + e.getMessage(), e);
         }
       }

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/querymaster/Repartitioner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/querymaster/Repartitioner.java b/tajo-core/src/main/java/org/apache/tajo/querymaster/Repartitioner.java
index fdaa0bc..53f5504 100644
--- a/tajo-core/src/main/java/org/apache/tajo/querymaster/Repartitioner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/querymaster/Repartitioner.java
@@ -39,19 +39,21 @@ import org.apache.tajo.engine.planner.global.ExecutionBlock;
 import org.apache.tajo.engine.planner.global.MasterPlan;
 import org.apache.tajo.engine.planner.global.rewriter.rules.GlobalPlanRewriteUtil;
 import org.apache.tajo.engine.utils.TupleUtil;
-import org.apache.tajo.exception.InternalException;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.exception.TajoInternalError;
+import org.apache.tajo.exception.UndefinedTableException;
+import org.apache.tajo.plan.PlanningException;
+import org.apache.tajo.plan.logical.*;
+import org.apache.tajo.plan.logical.SortNode.SortPurpose;
 import org.apache.tajo.plan.serder.PlanProto.DistinctGroupbyEnforcer.MultipleAggregationStage;
 import org.apache.tajo.plan.serder.PlanProto.EnforceProperty;
-import org.apache.tajo.querymaster.Task.IntermediateEntry;
-import org.apache.tajo.plan.logical.SortNode.SortPurpose;
 import org.apache.tajo.plan.util.PlannerUtil;
-import org.apache.tajo.plan.PlanningException;
-import org.apache.tajo.plan.logical.*;
+import org.apache.tajo.querymaster.Task.IntermediateEntry;
 import org.apache.tajo.storage.*;
 import org.apache.tajo.storage.fragment.FileFragment;
 import org.apache.tajo.storage.fragment.Fragment;
-import org.apache.tajo.util.Pair;
 import org.apache.tajo.unit.StorageUnit;
+import org.apache.tajo.util.Pair;
 import org.apache.tajo.util.TUtil;
 import org.apache.tajo.util.TajoIdUtils;
 import org.apache.tajo.worker.FetchImpl;
@@ -77,7 +79,7 @@ public class Repartitioner {
   private final static String UNKNOWN_HOST = "unknown";
 
   public static void scheduleFragmentsForJoinQuery(TaskSchedulerContext schedulerContext, Stage stage)
-      throws IOException {
+      throws IOException, TajoException {
     ExecutionBlock execBlock = stage.getBlock();
     QueryMasterTask.QueryMasterTaskContext masterContext = stage.getContext();
 
@@ -282,7 +284,7 @@ public class Repartitioner {
                                                        Fragment[] fragments,
                                                        ScanNode[] broadcastScans,
                                                        long[] broadcastStats,
-                                                       Fragment[] broadcastFragments) throws IOException {
+                                                       Fragment[] broadcastFragments) throws IOException, TajoException {
     MasterPlan masterPlan = stage.getMasterPlan();
     ExecutionBlock execBlock = stage.getBlock();
     // The hash map is modeling as follows:
@@ -597,7 +599,7 @@ public class Repartitioner {
     } else if (channel.getShuffleType() == RANGE_SHUFFLE) {
       scheduleRangeShuffledFetches(schedulerContext, masterPlan, stage, channel, maxNum);
     } else {
-      throw new InternalException("Cannot support partition type");
+      throw new TajoInternalError("Cannot support partition type");
     }
   }
 
@@ -639,8 +641,10 @@ public class Repartitioner {
       String storeType = PlannerUtil.getStoreType(masterPlan.getLogicalPlan());
       CatalogService catalog = stage.getContext().getQueryMasterContext().getWorkerContext().getCatalog();
       LogicalRootNode rootNode = masterPlan.getLogicalPlan().getRootBlock().getRoot();
-      TableDesc tableDesc = PlannerUtil.getTableDesc(catalog, rootNode.getChild());
-      if (tableDesc == null) {
+      TableDesc tableDesc = null;
+      try {
+        tableDesc = PlannerUtil.getTableDesc(catalog, rootNode.getChild());
+      } catch (UndefinedTableException e) {
         throw new IOException("Can't get table meta data from catalog: " +
             PlannerUtil.getStoreTableName(masterPlan.getLogicalPlan()));
       }

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/querymaster/Stage.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/querymaster/Stage.java b/tajo-core/src/main/java/org/apache/tajo/querymaster/Stage.java
index 9279f64..cf5cdbd 100644
--- a/tajo-core/src/main/java/org/apache/tajo/querymaster/Stage.java
+++ b/tajo-core/src/main/java/org/apache/tajo/querymaster/Stage.java
@@ -42,6 +42,7 @@ import org.apache.tajo.engine.planner.enforce.Enforcer;
 import org.apache.tajo.engine.planner.global.DataChannel;
 import org.apache.tajo.engine.planner.global.ExecutionBlock;
 import org.apache.tajo.engine.planner.global.MasterPlan;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.ipc.TajoWorkerProtocol;
 import org.apache.tajo.plan.serder.PlanProto.DistinctGroupbyEnforcer.MultipleAggregationStage;
 import org.apache.tajo.plan.serder.PlanProto.EnforceProperty;
@@ -1015,7 +1016,7 @@ public class Stage implements EventHandler<StageEvent> {
       }
     }
 
-    private static void schedule(Stage stage) throws IOException {
+    private static void schedule(Stage stage) throws IOException, TajoException {
       MasterPlan masterPlan = stage.getMasterPlan();
       ExecutionBlock execBlock = stage.getBlock();
       if (stage.getMasterPlan().isLeaf(execBlock.getId()) && execBlock.getScanNodes().length == 1) { // Case 1: Just Scan
@@ -1076,7 +1077,7 @@ public class Stage implements EventHandler<StageEvent> {
       }
     }
 
-    private static void scheduleFragmentsForLeafQuery(Stage stage) throws IOException {
+    private static void scheduleFragmentsForLeafQuery(Stage stage) throws IOException, TajoException {
       ExecutionBlock execBlock = stage.getBlock();
       ScanNode[] scans = execBlock.getScanNodes();
       Preconditions.checkArgument(scans.length == 1, "Must be Scan Query");

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java b/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java
index 630b1e9..705a29d 100644
--- a/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java
+++ b/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java
@@ -8,8 +8,12 @@ import org.apache.tajo.QueryIdFactory;
 import org.apache.tajo.TajoProtos;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.TableDesc;
-import org.apache.tajo.client.*;
+import org.apache.tajo.client.QueryStatus;
+import org.apache.tajo.client.TajoClient;
+import org.apache.tajo.client.TajoClientImpl;
+import org.apache.tajo.client.TajoClientUtil;
 import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.jdbc.FetchResultSet;
 import org.apache.tajo.service.ServiceTrackerFactory;
@@ -40,7 +44,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.apache.tajo.exception.ReturnStateUtil.isError;
-import static org.apache.tajo.exception.ReturnStateUtil.isSuccess;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -394,7 +397,7 @@ public class QueryExecutorServlet extends HttpServlet {
       }
     }
 
-    private QueryStatus waitForComplete(QueryId queryid) throws SQLException {
+    private QueryStatus waitForComplete(QueryId queryid) throws TajoException {
       QueryStatus status = null;
 
       while (!stop.get()) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/worker/TajoQueryEngine.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/worker/TajoQueryEngine.java b/tajo-core/src/main/java/org/apache/tajo/worker/TajoQueryEngine.java
index b47bf2f..e7e81d4 100644
--- a/tajo-core/src/main/java/org/apache/tajo/worker/TajoQueryEngine.java
+++ b/tajo-core/src/main/java/org/apache/tajo/worker/TajoQueryEngine.java
@@ -21,9 +21,8 @@ package org.apache.tajo.worker;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.engine.planner.PhysicalPlanner;
 import org.apache.tajo.engine.planner.PhysicalPlannerImpl;
-import org.apache.tajo.plan.logical.LogicalNode;
 import org.apache.tajo.engine.planner.physical.PhysicalExec;
-import org.apache.tajo.exception.InternalException;
+import org.apache.tajo.plan.logical.LogicalNode;
 
 import java.io.IOException;
 
@@ -35,8 +34,7 @@ public class TajoQueryEngine {
     this.phyPlanner = new PhysicalPlannerImpl(conf);
   }
   
-  public PhysicalExec createPlan(TaskAttemptContext ctx, LogicalNode plan)
-      throws InternalException {
+  public PhysicalExec createPlan(TaskAttemptContext ctx, LogicalNode plan) {
     return phyPlanner.createPlan(ctx, plan);
   }
   

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java
index b807198..046e538 100644
--- a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java
@@ -18,41 +18,27 @@
 
 package org.apache.tajo.ws.rs.resources;
 
-import java.net.URI;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.core.UriInfo;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.TajoConstants;
 import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.proto.CatalogProtos.DatabaseProto;
 import org.apache.tajo.catalog.proto.CatalogProtos.TablespaceProto;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.master.TajoMaster.MasterContext;
-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.NewDatabaseRequest;
 import org.apache.tajo.ws.rs.responses.DatabaseInfoResponse;
 
+import javax.ws.rs.*;
+import javax.ws.rs.core.*;
+import javax.ws.rs.core.Response.Status;
+import java.net.URI;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * Deals with Database Management
  */
@@ -175,19 +161,18 @@ public class DatabasesResource {
       if (request.getDatabaseName() == null || request.getDatabaseName().isEmpty()) {
         return ResourcesUtil.createBadRequestResponse(LOG, "databaseName is null or empty.");
       }
-      
-      boolean databaseCreated =
-          masterContext.getCatalog().createDatabase(request.getDatabaseName(), 
-              TajoConstants.DEFAULT_TABLESPACE_NAME);
-      
-      if (databaseCreated) {
+
+
+      try {
+        masterContext.getCatalog().createDatabase(request.getDatabaseName(),
+                TajoConstants.DEFAULT_TABLESPACE_NAME);
         URI newDatabaseURI = uriInfo.getBaseUriBuilder()
             .path(DatabasesResource.class)
             .path(DatabasesResource.class, "getDatabase")
             .build(request.getDatabaseName());
         return Response.created(newDatabaseURI).build();
-      } else {
-        return ResourcesUtil.createExceptionResponse(LOG, "Failed to create a new database.");
+      } catch (TajoException e) {
+        return ResourcesUtil.createExceptionResponse(LOG, e.getMessage());
       }
     }
   }
@@ -330,12 +315,11 @@ public class DatabasesResource {
       if (!catalogService.existDatabase(databaseName)) {
         return Response.status(Status.NOT_FOUND).build();
       }
-      
-      boolean databaseDropped = catalogService.dropDatabase(databaseName);
-      
-      if (databaseDropped) {
+
+      try {
+        catalogService.dropDatabase(databaseName);
         return Response.ok().build();
-      } else {
+      } catch (TajoException e) {
         return ResourcesUtil.createExceptionResponse(LOG, "Unable to drop a database " + databaseName);
       }
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java
index 8e19fcb..3dba02f 100644
--- a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java
@@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.master.TajoMaster.MasterContext;
 import org.apache.tajo.ws.rs.*;
 
@@ -182,9 +183,14 @@ public class TablesResource {
           !catalogService.existsTable(databaseName, tableName)) {
         return Response.status(Status.NOT_FOUND).build();
       }
-      
-      TableDesc tableDesc = catalogService.getTableDesc(databaseName, tableName);
-      return Response.ok(tableDesc).build();
+
+      TableDesc tableDesc = null;
+      try {
+        tableDesc = catalogService.getTableDesc(databaseName, tableName);
+        return Response.ok(tableDesc).build();
+      } catch (TajoException e) {
+        return ResourcesUtil.createExceptionResponse(LOG, e.getMessage());
+      }
     }
   }
   
@@ -213,7 +219,6 @@ public class TablesResource {
           LOG);
     } catch (Throwable e) {
       LOG.error(e.getMessage(), e);
-      
       response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
     }
     
@@ -245,14 +250,13 @@ public class TablesResource {
       }
       
       String canonicalTableName = CatalogUtil.getCanonicalTableName(databaseName, tableName);
-      boolean tableDropped = 
-          catalogService.dropTable(canonicalTableName);
-      if (tableDropped) {
+
+      try {
+        catalogService.dropTable(canonicalTableName);
         return Response.ok().build();
-      } else {
-        return ResourcesUtil.createExceptionResponse(LOG, "Unable to drop a " + canonicalTableName + " table.");
+      } catch (TajoException e) {
+        return ResourcesUtil.createExceptionResponse(LOG, e.getMessage());
       }
     }
-    
   }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 ec4796f..bcce612 100644
--- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
@@ -29,8 +29,7 @@ import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.catalog.CatalogService;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.TableDesc;
-import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
-import org.apache.tajo.catalog.exception.UndefinedTableException;
+import org.apache.tajo.exception.UndefinedTableException;
 import org.apache.tajo.cli.tsql.ParsedResult;
 import org.apache.tajo.cli.tsql.SimpleParser;
 import org.apache.tajo.client.TajoClient;
@@ -350,7 +349,7 @@ public class QueryTestCaseBase {
     fail("Cannot catch any planning error from: " + query);
   }
 
-  protected ResultSet executeString(String sql) throws Exception {
+  protected ResultSet executeString(String sql) throws TajoException {
     return client.executeQueryAndGetResult(sql);
   }
 
@@ -632,7 +631,6 @@ public class QueryTestCaseBase {
    * @param result Query result to be compared.
    */
   public final void assertResultSet(String message, ResultSet result, String resultFileName) throws IOException {
-    FileSystem fs = currentQueryPath.getFileSystem(testBase.getTestingCluster().getConfiguration());
     Path resultFile = getResultFile(resultFileName);
     try {
       verifyResultText(message, result, resultFile);
@@ -683,7 +681,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 SQLException {
+  public void assertDatabaseNotExists(String databaseName) {
     assertTrue(!client.existDatabase(databaseName));
   }
 
@@ -693,7 +691,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 SQLException {
+  public void assertTableExists(String tableName) {
     assertTrue(client.existTable(tableName));
   }
 
@@ -702,7 +700,7 @@ public class QueryTestCaseBase {
    *
    * @param tableName The table name to be checked. This name is case sensitive.
    */
-  public void assertTableNotExists(String tableName) throws SQLException {
+  public void assertTableNotExists(String tableName) {
     assertTrue(!client.existTable(tableName));
   }
 
@@ -790,7 +788,12 @@ public class QueryTestCaseBase {
     return queryFilePath;
   }
 
-  private Path getResultFile(String fileName) throws IOException {
+  protected String getResultContents(String fileName) throws IOException {
+    Path resultFile = getResultFile(getMethodName() + ".result");
+    return FileUtil.readTextFile(new File(resultFile.toUri()));
+  }
+
+  protected Path getResultFile(String fileName) throws IOException {
     Path resultPath = StorageUtil.concatPath(currentResultPath, fileName);
     FileSystem fs = currentResultPath.getFileSystem(testBase.getTestingCluster().getConfiguration());
     assertTrue(resultPath.toString() + " existence check", fs.exists(resultPath));


Mime
View raw message