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:01:46 UTC
svn commit: r1418581 - in /incubator/hcatalog/trunk: ./
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 01:01:44 2012
New Revision: 1418581
URL: http://svn.apache.org/viewvc?rev=1418581&view=rev
Log:
HCAT-561 HCatClient should differentiate between "partition not available" and other generic errors.
Added:
incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ObjectNotFoundException.java
Modified:
incubator/hcatalog/trunk/CHANGES.txt
incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java
incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java
incubator/hcatalog/trunk/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java
Modified: incubator/hcatalog/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/CHANGES.txt?rev=1418581&r1=1418580&r2=1418581&view=diff
==============================================================================
--- incubator/hcatalog/trunk/CHANGES.txt (original)
+++ incubator/hcatalog/trunk/CHANGES.txt Sat Dec 8 01:01:44 2012
@@ -151,6 +151,8 @@ Trunk (unreleased changes)
OPTIMIZATIONS
BUG FIXES
+ HCAT-561 HCatClient should differentiate between "partition not available" and other generic errors.(mithunr via avandana)
+
HCAT-563 hcat script should look in the correct dir for the storage handler jars (arpitgupta via khorgath)
HCAT-559 Fix trivial build warnings in HCat trunk (mithunr via avandana)
Modified: incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java?rev=1418581&r1=1418580&r2=1418581&view=diff
==============================================================================
--- incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java (original)
+++ incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ConnectionFailureException.java Sat Dec 8 01:01:44 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/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java?rev=1418581&r1=1418580&r2=1418581&view=diff
==============================================================================
--- incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java (original)
+++ incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatClientHMSImpl.java Sat Dec 8 01:01:44 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(
@@ -210,7 +210,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) {
@@ -243,7 +243,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) {
@@ -260,7 +260,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) {
@@ -295,7 +295,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(
@@ -314,7 +314,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(
@@ -345,7 +345,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;
@@ -377,7 +377,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);
}
}
@@ -393,7 +393,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) {
@@ -419,7 +419,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(
@@ -439,7 +439,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) {
@@ -475,7 +475,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) {
@@ -585,7 +585,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);
}
@@ -667,7 +667,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);
}
Added: incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ObjectNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ObjectNotFoundException.java?rev=1418581&view=auto
==============================================================================
--- incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ObjectNotFoundException.java (added)
+++ incubator/hcatalog/trunk/webhcat/java-client/src/main/java/org/apache/hcatalog/api/ObjectNotFoundException.java Sat Dec 8 01:01:44 2012
@@ -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.hcatalog.api;
+
+import org.apache.hcatalog.common.HCatException;
+
+/**
+ * This exception is thrown when a Database, Table or Partition
+ * specified in an HCatalog query is not found.
+ */
+public class ObjectNotFoundException extends HCatException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param message Exception message.
+ * @param cause The wrapped Throwable that caused this exception.
+ */
+ public ObjectNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Modified: incubator/hcatalog/trunk/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java?rev=1418581&r1=1418580&r2=1418581&view=diff
==============================================================================
--- incubator/hcatalog/trunk/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java (original)
+++ incubator/hcatalog/trunk/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java Sat Dec 8 01:01:44 2012
@@ -46,8 +46,10 @@ import org.junit.Test;
import org.slf4j.Logger;
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;
+import static org.junit.Assert.assertArrayEquals;
public class TestHCatClient {
private static final Logger LOG = LoggerFactory.getLogger(TestHCatClient.class);
@@ -402,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);
+ }
+ }
}