diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index f45b90d..fbce336 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -5883,6 +5883,9 @@ public Function get_function(String dbName, String funcName) throw new NoSuchObjectException( "Function " + dbName + "." + funcName + " does not exist"); } + } catch (NoSuchObjectException e) { + ex = e; + rethrowException(e); } catch (Exception e) { ex = e; throw newMetaException(e); diff --git a/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStoreClient.java b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStoreClient.java new file mode 100644 index 0000000..105408d --- /dev/null +++ b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStoreClient.java @@ -0,0 +1,71 @@ +/** + * 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.hadoop.hive.metastore; + +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.api.*; +import org.apache.hadoop.util.StringUtils; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.concurrent.TimeUnit; + +/** + * Test the HiveMetaStoreClient functionality + * Currently only for getFunction, when there queried function is not found. + */ +public class TestHiveMetaStoreClient { + protected static HiveMetaStoreClient client; + protected static HiveConf hiveConf; + protected static Warehouse warehouse; + + @BeforeClass + public static void setUp() throws Exception { + hiveConf = new HiveConf(TestHiveMetaStoreClient.class); + hiveConf.set(HiveConf.ConfVars.METASTORE_EXPRESSION_PROXY_CLASS.varname, + MockPartitionExpressionForMetastore.class.getCanonicalName()); + hiveConf.setTimeVar(HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, 10 * 1000, + TimeUnit.MILLISECONDS); + try { + client = new HiveMetaStoreClient(hiveConf); + } catch (Throwable e) { + System.err.println("Unable to open the metastore"); + System.err.println(StringUtils.stringifyException(e)); + throw e; + } + } + + @AfterClass + public static void tearDown() throws Exception { + try { + client.close(); + } catch (Throwable e) { + System.err.println("Unable to close metastore"); + System.err.println(StringUtils.stringifyException(e)); + throw e; + } + } + + @Test(expected=NoSuchObjectException.class) + public void testNoSuchFunction() throws Exception { + client.getFunction("default","invalidfunction"); + } +} \ No newline at end of file