Repository: hive Updated Branches: refs/heads/master bbfc4d9d2 -> 19999dad8
HIVE-14985 : Remove UDF-s created during test runs (Peter Vary, reviewed by Sergey Shelukhin) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/19999dad Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/19999dad Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/19999dad Branch: refs/heads/master Commit: 19999dad89557a1121bd26b804e449fb09825564 Parents: bbfc4d9 Author: Sergey Shelukhin <[email protected]> Authored: Thu Oct 20 13:04:29 2016 -0700 Committer: Sergey Shelukhin <[email protected]> Committed: Thu Oct 20 13:04:29 2016 -0700 ---------------------------------------------------------------------- .../org/apache/hadoop/hive/ql/QTestUtil.java | 43 +++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/19999dad/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java ---------------------------------------------------------------------- diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java index 0525335..a873721 100644 --- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java +++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java @@ -165,6 +165,7 @@ public class QTestUtil { private final Set<String> qJavaVersionSpecificOutput; private static final String SORT_SUFFIX = ".sorted"; private final HashSet<String> srcTables; + private final Set<String> srcUDFs; private final MiniClusterType clusterType; private final FsType fsType; private ParseDriver pd; @@ -213,6 +214,30 @@ public class QTestUtil { return srcTables; } + /** + * Returns the default UDF names which should not be removed when resetting the test database + * @return The list of the UDF names not to remove + */ + private Set<String> getSrcUDFs() { + HashSet<String> srcUDFs = new HashSet<String>(); + // FIXME: moved default value to here...for now + // i think this features is never really used from the command line + String defaultTestSrcUDFs = "qtest_get_java_boolean"; + for (String srcUDF : System.getProperty("test.src.udfs", defaultTestSrcUDFs).trim().split(",")) + { + srcUDF = srcUDF.trim(); + if (!srcUDF.isEmpty()) { + srcUDFs.add(srcUDF); + } + } + if (srcUDFs.isEmpty()) { + throw new RuntimeException("Source UDFs cannot be empty"); + } + return srcUDFs; + } + + + public HiveConf getConf() { return conf; } @@ -527,6 +552,7 @@ public class QTestUtil { this.logDir = logDir; this.useHBaseMetastore = useHBaseMetastore; this.srcTables=getSrcTables(); + this.srcUDFs = getSrcUDFs(); // HIVE-14443 move this fall-back logic to CliConfigs if (confDir != null && !confDir.isEmpty()) { @@ -892,6 +918,19 @@ public class QTestUtil { } } + public void clearUDFsCreatedDuringTests() throws Exception { + if (System.getenv(QTEST_LEAVE_FILES) != null) { + return; + } + // Delete functions created by the tests + // It is enough to remove functions from the default database, other databases are dropped + for (String udfName : db.getFunctions(DEFAULT_DATABASE_NAME, ".*")) { + if (!srcUDFs.contains(udfName)) { + db.dropFunction(DEFAULT_DATABASE_NAME, udfName); + } + } + } + /** * Clear out any side effects of running tests */ @@ -933,7 +972,7 @@ public class QTestUtil { } } if (!DEFAULT_DATABASE_NAME.equals(dbName)) { - // Drop cascade, may need to drop functions + // Drop cascade, functions dropped by cascade db.dropDatabase(dbName, true, true, true); } } @@ -980,6 +1019,7 @@ public class QTestUtil { db = Hive.get(conf); // propagate new conf to meta store clearTablesCreatedDuringTests(); + clearUDFsCreatedDuringTests(); clearKeysCreatedInTests(); } @@ -1001,6 +1041,7 @@ public class QTestUtil { } clearTablesCreatedDuringTests(); + clearUDFsCreatedDuringTests(); clearKeysCreatedInTests(); File cleanupFile = new File(cleanupScript);
