[NO ISSUE][*DB][UDF] Return outcome on create library / function

Change-Id: Iad2485982f24ffe4de2fb34454df03aa891b25bc
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13484
Reviewed-by: Michael Blow <mblow@apache.org>
Reviewed-by: Till Westmann <tillw@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 84a34a9..fbb173a 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -2775,7 +2775,7 @@
         }
     }
 
-    protected void doCreateFunction(MetadataProvider metadataProvider, CreateFunctionStatement cfs,
+    protected CreateResult doCreateFunction(MetadataProvider metadataProvider, CreateFunctionStatement cfs,
             FunctionSignature functionSignature, IStatementRewriter stmtRewriter, IRequestParameters requestParameters)
             throws Exception {
         DataverseName dataverseName = functionSignature.getDataverseName();
@@ -2792,7 +2792,7 @@
             if (existingFunction != null) {
                 if (cfs.getIfNotExists()) {
                     MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
-                    return;
+                    return CreateResult.NOOP;
                 } else if (!cfs.getReplaceIfExists()) {
                     throw new CompilationException(ErrorCode.FUNCTION_EXISTS, cfs.getSourceLocation(),
                             functionSignature.toString(false));
@@ -2951,13 +2951,14 @@
                 MetadataManager.INSTANCE.updateFunction(mdTxnCtx, function);
             }
             MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
+            if (LOGGER.isInfoEnabled()) {
+                LOGGER.info("Installed function: " + functionSignature);
+            }
+            return existingFunction != null ? CreateResult.REPLACED : CreateResult.CREATED;
         } catch (Exception e) {
             abort(e, e, mdTxnCtx);
             throw e;
         }
-        if (LOGGER.isInfoEnabled()) {
-            LOGGER.info("Installed function: " + functionSignature);
-        }
     }
 
     private Triple<TypeSignature, TypeSignature, Datatype> translateFunctionParameterType(
@@ -3199,8 +3200,8 @@
         }
     }
 
-    protected void doCreateLibrary(MetadataProvider metadataProvider, DataverseName dataverseName, String libraryName,
-            String libraryHash, CreateLibraryStatement cls, IHyracksClientConnection hcc,
+    protected CreateResult doCreateLibrary(MetadataProvider metadataProvider, DataverseName dataverseName,
+            String libraryName, String libraryHash, CreateLibraryStatement cls, IHyracksClientConnection hcc,
             IRequestParameters requestParameters) throws Exception {
         JobUtils.ProgressState progress = ProgressState.NO_PROGRESS;
         boolean prepareJobSuccessful = false;
@@ -3257,6 +3258,7 @@
             MetadataManager.INSTANCE.updateLibrary(mdTxnCtx, newLibrary);
 
             MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
+            return existingLibrary != null ? CreateResult.REPLACED : CreateResult.CREATED;
         } catch (Exception e) {
             if (bActiveTxn) {
                 abort(e, e, mdTxnCtx);
@@ -4754,4 +4756,11 @@
             throws CompilationException {
         ExternalDataUtils.validateAdapterSpecificProperties(configuration, srcLoc, warningCollector);
     }
+
+    protected enum CreateResult {
+        NOOP,
+        CREATED,
+        REPLACED
+    }
+
 }