Skip to content

Commit

Permalink
[FLINK-14673][hive] Shouldn't expect HMS client to throw NoSuchObject…
Browse files Browse the repository at this point in the history
…Exception for non-existing function

Always to check MetaException when getting function with HMS client.

This closes apache#10133.
  • Loading branch information
lirui-apache authored and bowenli86 committed Nov 8, 2019
1 parent 501f640 commit 1806a37
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,19 @@ private IMetaStoreClient createMetastoreClient() {
}

public Function getFunction(String databaseName, String functionName) throws MetaException, TException {
HiveShim hiveShim = HiveShimLoader.loadHiveShim(hiveVersion);
return hiveShim.getFunction(client, databaseName, functionName);
try {
// Hive may not throw NoSuchObjectException if function doesn't exist, instead it throws a MetaException
return client.getFunction(databaseName, functionName);
} catch (MetaException e) {
// need to check the cause and message of this MetaException to decide whether it should actually be a NoSuchObjectException
if (e.getCause() instanceof NoSuchObjectException) {
throw (NoSuchObjectException) e.getCause();
}
if (e.getMessage().startsWith(NoSuchObjectException.class.getSimpleName())) {
throw new NoSuchObjectException(e.getMessage());
}
throw e;
}
}

public void alter_table(String databaseName, String tableName, Table table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
import org.apache.hadoop.hive.metastore.api.ColumnStatisticsData;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.Function;
import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.Table;
import org.apache.hadoop.hive.metastore.api.UnknownDBException;
Expand Down Expand Up @@ -76,18 +74,6 @@ public interface HiveShim extends Serializable {
*/
List<String> getViews(IMetaStoreClient client, String databaseName) throws UnknownDBException, TException;

/**
* Gets a function from a database with the given HMS client.
*
* @param client the Hive Metastore client
* @param dbName name of the database
* @param functionName name of the function
* @return the Function under the specified name
* @throws NoSuchObjectException if the function doesn't exist
* @throws TException for any other generic exceptions caused by Thrift
*/
Function getFunction(IMetaStoreClient client, String dbName, String functionName) throws NoSuchObjectException, TException;

/**
* Moves a particular file or directory to trash.
* The file/directory can potentially be deleted (w/o going to trash) if purge is set to true, or if it cannot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
import org.apache.hadoop.hive.metastore.Warehouse;
import org.apache.hadoop.hive.metastore.api.ColumnStatisticsData;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.Function;
import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.Table;
import org.apache.hadoop.hive.metastore.api.UnknownDBException;
Expand Down Expand Up @@ -115,23 +113,6 @@ public List<String> getViews(IMetaStoreClient client, String databaseName) throw
return views;
}

@Override
public Function getFunction(IMetaStoreClient client, String dbName, String functionName) throws NoSuchObjectException, TException {
try {
// hive-1.x doesn't throw NoSuchObjectException if function doesn't exist, instead it throws a MetaException
return client.getFunction(dbName, functionName);
} catch (MetaException e) {
// need to check the cause and message of this MetaException to decide whether it should actually be a NoSuchObjectException
if (e.getCause() instanceof NoSuchObjectException) {
throw (NoSuchObjectException) e.getCause();
}
if (e.getMessage().startsWith(NoSuchObjectException.class.getSimpleName())) {
throw new NoSuchObjectException(e.getMessage());
}
throw e;
}
}

@Override
public boolean moveToTrash(FileSystem fs, Path path, Configuration conf, boolean purge) throws IOException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient;
import org.apache.hadoop.hive.metastore.TableType;
import org.apache.hadoop.hive.metastore.api.Function;
import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Table;
import org.apache.hadoop.hive.metastore.api.UnknownDBException;
import org.apache.hadoop.hive.ql.udf.generic.SimpleGenericUDAFParameterInfo;
Expand Down Expand Up @@ -77,11 +75,6 @@ public List<String> getViews(IMetaStoreClient client, String databaseName) throw
}
}

@Override
public Function getFunction(IMetaStoreClient client, String dbName, String functionName) throws NoSuchObjectException, TException {
return client.getFunction(dbName, functionName);
}

@Override
public boolean moveToTrash(FileSystem fs, Path path, Configuration conf, boolean purge) throws IOException {
try {
Expand Down

0 comments on commit 1806a37

Please sign in to comment.