You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ja...@apache.org on 2019/08/01 04:08:33 UTC

[flink] branch release-1.9 updated: [FLINK-13423][hive] Unable to find function in hive 1

This is an automated email from the ASF dual-hosted git repository.

jark pushed a commit to branch release-1.9
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-1.9 by this push:
     new f0220de  [FLINK-13423][hive] Unable to find function in hive 1
f0220de is described below

commit f0220de465cf320a925d4d936afbd51fd0f9991e
Author: Rui Li <li...@apache.org>
AuthorDate: Thu Jul 25 20:52:55 2019 +0800

    [FLINK-13423][hive] Unable to find function in hive 1
    
    This closes #9279
---
 .../table/catalog/hive/client/HiveShimV1.java      |  4 ++++
 .../connectors/hive/TableEnvHiveConnectorTest.java | 26 +++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV1.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV1.java
index 8733100..6afcf5a 100644
--- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV1.java
+++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShimV1.java
@@ -84,9 +84,13 @@ public class HiveShimV1 implements HiveShim {
 			// 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;
 		}
 	}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/batch/connectors/hive/TableEnvHiveConnectorTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/batch/connectors/hive/TableEnvHiveConnectorTest.java
index 2f910a9..7f21bc8 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/batch/connectors/hive/TableEnvHiveConnectorTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/batch/connectors/hive/TableEnvHiveConnectorTest.java
@@ -66,9 +66,7 @@ public class TableEnvHiveConnectorTest {
 		hiveShell.execute("create table db1.part (x int) partitioned by (y int)");
 		hiveShell.insertInto("db1", "src").addRow(1, 1).addRow(2, null).commit();
 
-		TableEnvironment tableEnv = HiveTestUtils.createTableEnv();
-		tableEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
-		tableEnv.useCatalog(hiveCatalog.getName());
+		TableEnvironment tableEnv = getTableEnvWithHiveCatalog();
 
 		// test generating partitions with default name
 		tableEnv.sqlUpdate("insert into db1.part select * from db1.src");
@@ -85,4 +83,26 @@ public class TableEnvHiveConnectorTest {
 
 		hiveShell.execute("drop database db1 cascade");
 	}
+
+	@Test
+	public void testGetNonExistingFunction() throws Exception {
+		hiveShell.execute("create database db1");
+		hiveShell.execute("create table db1.src (d double, s string)");
+		hiveShell.execute("create table db1.dest (x bigint)");
+
+		TableEnvironment tableEnv = getTableEnvWithHiveCatalog();
+
+		// just make sure the query runs through, no need to verify result
+		tableEnv.sqlUpdate("insert into db1.dest select count(d) from db1.src");
+		tableEnv.execute("test");
+
+		hiveShell.execute("drop database db1 cascade");
+	}
+
+	private TableEnvironment getTableEnvWithHiveCatalog() {
+		TableEnvironment tableEnv = HiveTestUtils.createTableEnv();
+		tableEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
+		tableEnv.useCatalog(hiveCatalog.getName());
+		return tableEnv;
+	}
 }