diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveMetastoreClientWrapper.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveMetastoreClientWrapper.java index 77d80390af6d1..3da18751aa519 100644 --- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveMetastoreClientWrapper.java +++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveMetastoreClientWrapper.java @@ -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) diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShim.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShim.java index 0b58724285e4e..929d90e53d392 100644 --- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShim.java +++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShim.java @@ -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; @@ -76,18 +74,6 @@ public interface HiveShim extends Serializable { */ List 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 diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV100.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV100.java index e2f79d7c25b88..e5f3b6770786f 100644 --- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV100.java +++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV100.java @@ -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; @@ -115,23 +113,6 @@ public List 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 { diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV230.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV230.java index ac76cbab4f60d..c373b6964efc8 100644 --- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV230.java +++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV230.java @@ -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; @@ -77,11 +75,6 @@ public List 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 {