diff --git itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java index ff640d3..df17057 100644 --- itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java +++ itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java @@ -165,6 +165,7 @@ private final Set qJavaVersionSpecificOutput; private static final String SORT_SUFFIX = ".sorted"; private final HashSet srcTables; + private final Set srcUDFs; private final MiniClusterType clusterType; private final FsType fsType; private ParseDriver pd; @@ -213,6 +214,30 @@ 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 getSrcUDFs() { + HashSet srcUDFs = new HashSet(); + // 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 QTestUtil(String outDir, String logDir, MiniClusterType clusterType, 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 void clearKeysCreatedInTests() { } } + 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 void clearTablesCreatedDuringTests() throws Exception { } } 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 void clearTestSideEffects() throws Exception { db = Hive.get(conf); // propagate new conf to meta store clearTablesCreatedDuringTests(); + clearUDFsCreatedDuringTests(); clearKeysCreatedInTests(); } @@ -1001,6 +1041,7 @@ public void cleanUp(String tname) throws Exception { } clearTablesCreatedDuringTests(); + clearUDFsCreatedDuringTests(); clearKeysCreatedInTests(); File cleanupFile = new File(cleanupScript);