HCATALOG-592 webhcat - handle change in hive table/partition not found error


git-svn-id: https://svn.apache.org/repos/asf/incubator/hcatalog/trunk@1434375 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 3ad5610..93ad409 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -174,6 +174,8 @@
   OPTIMIZATIONS
 
   BUG FIXES
+  HCAT-592 webhcat - handle change in hive table/partition not found error (thejas via gates)
+
   HCAT-586 checkstyle fails every time complaining that it's own header file does not have the proper header (gates)
 
   HCAT-580 Optimizations in HCAT-538 break e2e tests (daijy via gates)
diff --git a/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/HcatDelegator.java b/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/HcatDelegator.java
index da25ca6..6dbf9e2 100644
--- a/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/HcatDelegator.java
+++ b/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/HcatDelegator.java
@@ -25,7 +25,7 @@
 import java.util.List;
 import java.util.Map;
 import javax.ws.rs.core.Response;
-
+ 
 import org.apache.commons.exec.ExecuteException;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
@@ -113,7 +113,7 @@
             String res = jsonRun(user, exec);
             return JsonBuilder.create(res).build();
         } catch (HcatException e) {
-            if (e.execBean.stderr.indexOf("Error in semantic analysis") > -1) {
+            if (e.execBean.stderr.contains("SemanticException")) {
                 return JsonBuilder.create().
                     put("error", "Database " + db + " does not exist")
                     .put("errorCode", "404")
@@ -256,7 +256,15 @@
                 .put("table", table)
                 .build();
         } catch (HcatException e) {
-            throw new HcatException("unable to describe table: " + table,
+            if (e.execBean.stderr.contains("SemanticException") &&
+                e.execBean.stderr.contains("Table not found")) {
+                return JsonBuilder.create().
+                    put("error", "Table" + db + "." + table + " does not exist" )
+                    .put("errorCode", "404")
+                    .put("table", table)
+                    .put("database", db).build();
+            }
+            throw new HcatException("unable to describe database: " + db,
                 e.execBean, exec);
         }
     }
@@ -631,6 +639,19 @@
                 .put("partition", partition)
                 .build();
         } catch (HcatException e) {
+            if (e.execBean.stderr.contains("SemanticException") &&
+                e.execBean.stderr.contains("Partition not found")) {
+                String emsg = "Partition " + partition + " for table " 
+                    + table + " does not exist" + db + "." + table + " does not exist";
+                return JsonBuilder.create()
+                    .put("error", emsg)
+                    .put("errorCode", "404")
+                    .put("database", db)
+                    .put("table", table)
+                    .put("partition", partition)
+                    .build();
+            }
+
             throw new HcatException("unable to show partition: "
                 + table + " " + partition,
                 e.execBean,