You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hcatalog-commits@incubator.apache.org by av...@apache.org on 2012/12/08 01:00:00 UTC

svn commit: r1418578 - in /incubator/hcatalog/branches/branch-0.4: ./ not/ webhcat/java-client/src/main/java/org/apache/hcatalog/api/ webhcat/java-client/src/test/java/org/apache/hcatalog/api/

Author: avandana
Date: Sat Dec  8 00:59:59 2012
New Revision: 1418578

URL: http://svn.apache.org/viewvc?rev=1418578&view=rev
Log:
HCATALOG-561 HCatClient should differentiate between "partition not available" and other generic errors. (mithun via avandana)

Added:
    incubator/hcatalog/branches/branch-0.4/not/
Modified:
    incubator/hcatalog/branches/branch-0.4/CHANGES.txt
    incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java
    incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java
    incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java

Modified: incubator/hcatalog/branches/branch-0.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hcatalog/branches/branch-0.4/CHANGES.txt?rev=1418578&r1=1418577&r2=1418578&view=diff
==============================================================================
--- incubator/hcatalog/branches/branch-0.4/CHANGES.txt (original)
+++ incubator/hcatalog/branches/branch-0.4/CHANGES.txt Sat Dec  8 00:59:59 2012
@@ -71,6 +71,8 @@ Trunk (unreleased changes)
   OPTIMIZATIONS
 
   BUG FIXES
+  HCAT-561 HCatClient should differentiate between "partition not available" and other generic errors. (mithun via avandana)
+
   HCAT-534 HCat_Drop_Table_3 dfs mkdir failing on hadoop23 (cdrome via toffer)
 
   HCAT-513  Data Store onto HCatalog table fails for dynamic partitioning as the temporary directory gets deleted by the completed map tasks (amalakar via toffer)

Modified: incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java?rev=1418578&r1=1418577&r2=1418578&view=diff
==============================================================================
--- incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java (original)
+++ incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java Sat Dec  8 00:59:59 2012
@@ -28,8 +28,8 @@ public class ConnectionFailureException 
     private static final long serialVersionUID = 1L;
 
     /**
-     * @param message
-     * @param cause
+     * @param message Exception message.
+     * @param cause The wrapped Throwable that caused this exception.
      */
     public ConnectionFailureException(String message, Throwable cause) {
         super(message, cause);

Modified: incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java?rev=1418578&r1=1418577&r2=1418578&view=diff
==============================================================================
--- incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java (original)
+++ incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java Sat Dec  8 00:59:59 2012
@@ -79,7 +79,7 @@ public class HCatClientHMSImpl extends H
                 db = new HCatDatabase(hiveDB);
             }
         } catch (NoSuchObjectException exp) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while fetching database", exp);
         } catch (MetaException exp) {
             throw new HCatException("MetaException while fetching database",
@@ -120,7 +120,7 @@ public class HCatClientHMSImpl extends H
             hmsClient.dropDatabase(checkDB(dbName), true, ifExists, isCascade);
         } catch (NoSuchObjectException e) {
             if (!ifExists) {
-                throw new HCatException(
+                throw new ObjectNotFoundException(
                         "NoSuchObjectException while dropping db.", e);
             }
         } catch (InvalidOperationException e) {
@@ -162,7 +162,7 @@ public class HCatClientHMSImpl extends H
             throw new ConnectionFailureException(
                     "TException while fetching table.", e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while fetching table.", e);
         }
         return table;
@@ -184,7 +184,7 @@ public class HCatClientHMSImpl extends H
         } catch (MetaException e) {
             throw new HCatException("MetaException while creating table.", e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while creating table.", e);
         } catch (TException e) {
             throw new ConnectionFailureException(
@@ -209,7 +209,7 @@ public class HCatClientHMSImpl extends H
             throw new HCatException("MetaException while updating table schema.", e);
         }
         catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while updating table schema.", e);
         }
         catch (TException e) {
@@ -242,7 +242,7 @@ public class HCatClientHMSImpl extends H
                 throw new HCatException(
                         "MetaException in create table like command.", e);
             } catch (NoSuchObjectException e) {
-                throw new HCatException(
+                throw new ObjectNotFoundException(
                         "NoSuchObjectException in create table like command.",
                         e);
             } catch (TException e) {
@@ -259,7 +259,7 @@ public class HCatClientHMSImpl extends H
             hmsClient.dropTable(checkDB(dbName), tableName,true, ifExists);
         } catch (NoSuchObjectException e) {
             if (!ifExists) {
-                throw new HCatException(
+                throw new ObjectNotFoundException(
                         "NoSuchObjectException while dropping table.", e);
             }
         } catch (MetaException e) {
@@ -294,7 +294,7 @@ public class HCatClientHMSImpl extends H
             throw new ConnectionFailureException(
                     "TException while renaming table", e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while renaming table", e);
         } catch (InvalidOperationException e) {
             throw new HCatException(
@@ -313,7 +313,7 @@ public class HCatClientHMSImpl extends H
                 hcatPtns.add(new HCatPartition(ptn));
             }
         } catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while retrieving partition.", e);
         } catch (MetaException e) {
             throw new HCatException(
@@ -344,7 +344,7 @@ public class HCatClientHMSImpl extends H
             throw new ConnectionFailureException(
                     "TException while retrieving partition.", e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while retrieving partition.", e);
         }
         return partition;
@@ -376,7 +376,7 @@ public class HCatClientHMSImpl extends H
             throw new ConnectionFailureException(
                     "TException while adding partition.", e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException("The table " + partInfo.getTableName()
+            throw new ObjectNotFoundException("The table " + partInfo.getTableName()
                     + " is could not be found.", e);
         }
     }
@@ -392,7 +392,7 @@ public class HCatClientHMSImpl extends H
                     ifExists);
         } catch (NoSuchObjectException e) {
             if (!ifExists) {
-                throw new HCatException(
+                throw new ObjectNotFoundException(
                         "NoSuchObjectException while dropping partition.", e);
             }
         } catch (MetaException e) {
@@ -418,7 +418,7 @@ public class HCatClientHMSImpl extends H
             throw new HCatException("MetaException while fetching partitions.",
                     e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while fetching partitions.", e);
         } catch (TException e) {
             throw new ConnectionFailureException(
@@ -438,7 +438,7 @@ public class HCatClientHMSImpl extends H
             throw new HCatException(
                     "MetaException while marking partition for event.", e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while marking partition for event.",
                     e);
         } catch (UnknownTableException e) {
@@ -474,7 +474,7 @@ public class HCatClientHMSImpl extends H
             throw new HCatException(
                     "MetaException while checking partition for event.", e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while checking partition for event.",
                     e);
         } catch (UnknownTableException e) {
@@ -584,7 +584,7 @@ public class HCatClientHMSImpl extends H
             throw new ConnectionFailureException(
                     "TException while retrieving existing table.", e1);
         } catch (NoSuchObjectException e1) {
-            throw new HCatException(
+            throw new ObjectNotFoundException(
                     "NoSuchObjectException while retrieving existing table.",
                     e1);
         }
@@ -666,7 +666,7 @@ public class HCatClientHMSImpl extends H
             throw new ConnectionFailureException(
                     "TException while adding partition.", e);
         } catch (NoSuchObjectException e) {
-            throw new HCatException("The table "
+            throw new ObjectNotFoundException("The table "
                     + partInfoList.get(0).getTableName()
                     + " is could not be found.", e);
         }

Modified: incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java?rev=1418578&r1=1418577&r2=1418578&view=diff
==============================================================================
--- incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java (original)
+++ incubator/hcatalog/branches/branch-0.4/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java Sat Dec  8 00:59:59 2012
@@ -48,6 +48,7 @@ import org.slf4j.LoggerFactory;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 public class TestHCatClient {
@@ -403,4 +404,77 @@ public class TestHCatClient {
             assertTrue("Unexpected exception: " + exception.getMessage(), false);
         }
     }
+
+    @Test
+    public void testObjectNotFoundException() throws Exception {
+        try {
+
+            HCatClient client = HCatClient.create(new  Configuration(hcatConf));
+            String dbName = "testObjectNotFoundException_DBName";
+            String tableName = "testObjectNotFoundException_TableName";
+            client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE);
+
+            try {    // Test that fetching a non-existent db-name yields ObjectNotFound.
+                client.getDatabase(dbName);
+                assertTrue("Expected ObjectNotFoundException.", false);
+            } catch(Exception exception) {
+                LOG.info("Got exception: ", exception);
+                assertTrue("Expected ObjectNotFoundException. Got:" + exception.getClass(),
+                        exception instanceof ObjectNotFoundException);
+            }
+
+            client.createDatabase(HCatCreateDBDesc.create(dbName).build());
+
+            try {   // Test that fetching a non-existent table-name yields ObjectNotFound.
+                client.getTable(dbName, tableName);
+                assertTrue("Expected ObjectNotFoundException.", false);
+            } catch(Exception exception) {
+                LOG.info("Got exception: ", exception);
+                assertTrue("Expected ObjectNotFoundException. Got:" + exception.getClass(),
+                        exception instanceof ObjectNotFoundException);
+            }
+
+            String partitionColumn = "part";
+
+            List<HCatFieldSchema> columns = Arrays.asList(new HCatFieldSchema("col", Type.STRING, ""));
+            ArrayList<HCatFieldSchema> partitionColumns = new ArrayList<HCatFieldSchema>(
+                    Arrays.asList(new HCatFieldSchema(partitionColumn, Type.STRING, "")));
+            client.createTable(HCatCreateTableDesc.create(dbName, tableName, columns)
+                    .partCols(partitionColumns)
+                    .build());
+
+            Map<String, String> partitionSpec = new HashMap<String, String>();
+            partitionSpec.put(partitionColumn, "foobar");
+            try {  // Test that fetching a non-existent partition yields ObjectNotFound.
+                client.getPartition(dbName, tableName, partitionSpec);
+                assertTrue("Expected ObjectNotFoundException.", false);
+            } catch(Exception exception) {
+                LOG.info("Got exception: ", exception);
+                assertTrue("Expected ObjectNotFoundException. Got:" + exception.getClass(),
+                        exception instanceof ObjectNotFoundException);
+            }
+
+            client.addPartition(HCatAddPartitionDesc.create(dbName, tableName, "", partitionSpec).build());
+
+            // Test that listPartitionsByFilter() returns an empty-set, if the filter selects no partitions.
+            assertEquals("Expected empty set of partitions.",
+                    0, client.listPartitionsByFilter(dbName, tableName, partitionColumn + " < 'foobar'").size());
+
+            try {  // Test that listPartitionsByFilter() throws HCatException if the partition-key is incorrect.
+                partitionSpec.put("NonExistentKey", "foobar");
+                client.getPartition(dbName, tableName, partitionSpec);
+                assertTrue("Expected HCatException.", false);
+            } catch(Exception exception) {
+                LOG.info("Got exception: ", exception);
+                assertTrue("Expected HCatException. Got:" + exception.getClass(),
+                        exception instanceof HCatException);
+                assertFalse("Did not expect ObjectNotFoundException.", exception instanceof ObjectNotFoundException);
+            }
+
+        }
+        catch (Throwable t) {
+            LOG.error("Unexpected exception!", t);
+            assertTrue("Unexpected exception! " + t.getMessage(), false);
+        }
+    }
 }