Till Westmann has submitted this change and it was merged.

Change subject: [NO ISSUE] Use FunctionSignature more often
......................................................................


[NO ISSUE] Use FunctionSignature more often

- user model changes: no
- storage format changes: no
- interface changes: yes

The metadata entity for a function now accepts a FunctionSignature.
It used to accept a dataverse, a function name, and an arity.

Change-Id: If00a914a1e56190ecd12c2687c32b4edc2895018
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2380
Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhub...@apache.org>
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
M 
asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataTransactionContext.java
M 
asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/FeedConnection.java
M 
asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Function.java
M 
asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java
M 
asterixdb/asterix-metadata/src/test/java/org/apache/asterix/metadata/functions/ExternalFunctionCompilerUtilTest.java
7 files changed, 42 insertions(+), 47 deletions(-)

Approvals:
  Anon. E. Moose #1000171: 
  Jenkins: Verified; No violations found; ; Verified
  Murtadha Hubail: Looks good to me, approved



diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
index c9f777d..e60444f 100755
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
@@ -245,9 +245,11 @@
                     for (String arg : fargs) {
                         args.add(arg);
                     }
-                    Function f = new Function(dataverse, libraryName + "#" + 
function.getName().trim(), args.size(),
-                            args, function.getReturnType().trim(), 
function.getDefinition().trim(),
-                            library.getLanguage().trim(), 
function.getFunctionType().trim(), null);
+                    FunctionSignature signature = new 
FunctionSignature(dataverse,
+                            libraryName + "#" + function.getName().trim(), 
args.size());
+                    Function f = new Function(signature, args, 
function.getReturnType().trim(),
+                            function.getDefinition().trim(), 
library.getLanguage().trim(),
+                            function.getFunctionType().trim(), null);
                     MetadataManager.INSTANCE.addFunction(mdTxnCtx, f);
                     if (LOGGER.isInfoEnabled()) {
                         LOGGER.info("Installed function: " + libraryName + "#" 
+ function.getName().trim());
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 7bf65c7..b64f828 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
@@ -1212,8 +1212,7 @@
             List<Function> functionsInDataverse =
                     MetadataManager.INSTANCE.getDataverseFunctions(mdTxnCtx, 
dataverseName);
             for (Function function : functionsInDataverse) {
-                if (checkWhetherFunctionIsBeingUsed(mdTxnCtx, 
function.getDataverseName(), function.getName(),
-                        function.getArity(), dataverseName)) {
+                if (isFunctionUsed(mdTxnCtx, function.getSignature(), 
dataverseName)) {
                     throw new 
MetadataException(ErrorCode.METADATA_DROP_FUCTION_IN_USE,
                             function.getDataverseName() + "." + 
function.getName() + "@" + function.getArity());
                 }
@@ -1667,14 +1666,14 @@
 
     protected void handleCreateFunctionStatement(MetadataProvider 
metadataProvider, Statement stmt) throws Exception {
         CreateFunctionStatement cfs = (CreateFunctionStatement) stmt;
-        String dataverse = 
getActiveDataverseName(cfs.getFunctionSignature().getNamespace());
-        cfs.getFunctionSignature().setNamespace(dataverse);
-        String functionName = cfs.getFunctionSignature().getName();
+        FunctionSignature signature = cfs.getFunctionSignature();
+        String dataverse = getActiveDataverseName(signature.getNamespace());
+        signature.setNamespace(dataverse);
 
         MetadataTransactionContext mdTxnCtx = 
MetadataManager.INSTANCE.beginTransaction();
         metadataProvider.setMetadataTxnContext(mdTxnCtx);
         MetadataLockUtil.functionStatementBegin(lockManager, 
metadataProvider.getLocks(), dataverse,
-                dataverse + "." + functionName);
+                dataverse + "." + signature.getName());
         try {
             Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx, 
dataverse);
             if (dv == null) {
@@ -1696,10 +1695,10 @@
             List<List<List<String>>> dependencies = 
FunctionUtil.getFunctionDependencies(
                     rewriterFactory.createQueryRewriter(), 
cfs.getFunctionBodyExpression(), metadataProvider);
 
-            Function function = new Function(dataverse, functionName, 
cfs.getFunctionSignature().getArity(),
-                    cfs.getParamList(), Function.RETURNTYPE_VOID, 
cfs.getFunctionBody(),
-                    rewriterFactory instanceof SqlppRewriterFactory ? 
Function.LANGUAGE_SQLPP : Function.LANGUAGE_AQL,
-                    FunctionKind.SCALAR.toString(), dependencies);
+            final String language =
+                    rewriterFactory instanceof SqlppRewriterFactory ? 
Function.LANGUAGE_SQLPP : Function.LANGUAGE_AQL;
+            Function function = new Function(signature, cfs.getParamList(), 
Function.RETURNTYPE_VOID,
+                    cfs.getFunctionBody(), language, 
FunctionKind.SCALAR.toString(), dependencies);
             MetadataManager.INSTANCE.addFunction(mdTxnCtx, function);
 
             MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
@@ -1712,8 +1711,8 @@
         }
     }
 
-    protected boolean 
checkWhetherFunctionIsBeingUsed(MetadataTransactionContext ctx, String 
dataverseName,
-            String functionName, int arity, String currentDataverse) throws 
AlgebricksException {
+    protected boolean isFunctionUsed(MetadataTransactionContext ctx, 
FunctionSignature signature,
+            String currentDataverse) throws AlgebricksException {
         List<Dataverse> allDataverses = 
MetadataManager.INSTANCE.getDataverses(ctx);
         for (Dataverse dataverse : allDataverses) {
             if (currentDataverse != null && 
dataverse.getDataverseName().equals(currentDataverse)) {
@@ -1724,7 +1723,7 @@
                 List<FeedConnection> feedConnections = 
MetadataManager.INSTANCE.getFeedConections(ctx,
                         dataverse.getDataverseName(), feed.getFeedName());
                 for (FeedConnection conn : feedConnections) {
-                    if (conn.containsFunction(dataverseName, functionName, 
arity)) {
+                    if (conn.containsFunction(signature)) {
                         return true;
                     }
                 }
@@ -1745,8 +1744,7 @@
             Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, 
signature);
             if (function == null && !stmtDropFunction.getIfExists()) {
                 throw new AlgebricksException("Unknonw function " + signature);
-            } else if (checkWhetherFunctionIsBeingUsed(mdTxnCtx, 
signature.getNamespace(), signature.getName(),
-                    signature.getArity(), null)) {
+            } else if (isFunctionUsed(mdTxnCtx, signature, null)) {
                 throw new 
MetadataException(ErrorCode.METADATA_DROP_FUCTION_IN_USE, signature);
             } else {
                 MetadataManager.INSTANCE.dropFunction(mdTxnCtx, signature);
diff --git 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataTransactionContext.java
 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataTransactionContext.java
index 961a1ee..a1eb425 100644
--- 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataTransactionContext.java
+++ 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataTransactionContext.java
@@ -157,8 +157,7 @@
     }
 
     public void dropFunction(FunctionSignature signature) {
-        Function function = new Function(signature.getNamespace(), 
signature.getName(), signature.getArity(), null,
-                null, null, null, null, null);
+        Function function = new Function(signature, null, null, null, null, 
null, null);
         droppedCache.addFunctionIfNotExists(function);
         logAndApply(new MetadataLogicalOperation(function, false));
     }
diff --git 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/FeedConnection.java
 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/FeedConnection.java
index 8e14ee5..7572a9a 100644
--- 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/FeedConnection.java
+++ 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/FeedConnection.java
@@ -113,13 +113,7 @@
         return feedId;
     }
 
-    public boolean containsFunction(String dataverseName, String functionName, 
int arity) {
-        for (FunctionSignature signature : this.appliedFunctions) {
-            if (signature.getNamespace().equals(dataverseName) && 
signature.getName().equals(functionName)
-                    && signature.getArity() == arity) {
-                return true;
-            }
-        }
-        return false;
+    public boolean containsFunction(FunctionSignature signature) {
+        return appliedFunctions.contains(signature);
     }
 }
diff --git 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Function.java
 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Function.java
index 8bdbaba..b5721c0 100644
--- 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Function.java
+++ 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Function.java
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.metadata.MetadataCache;
 import org.apache.asterix.metadata.api.IMetadataEntity;
 
@@ -33,9 +34,7 @@
     public static final String RETURNTYPE_VOID = "VOID";
     public static final String NOT_APPLICABLE = "N/A";
 
-    private final String dataverse;
-    private final String name;
-    private final int arity;
+    private final FunctionSignature signature;
     private final List<String> params;
     private final List<List<List<String>>> dependencies;
     private final String body;
@@ -43,16 +42,14 @@
     private final String language;
     private final String kind;
 
-    public Function(String dataverseName, String functionName, int arity, 
List<String> params, String returnType,
-            String functionBody, String language, String functionKind, 
List<List<List<String>>> dependencies) {
-        this.dataverse = dataverseName;
-        this.name = functionName;
+    public Function(FunctionSignature signature, List<String> params, String 
returnType, String functionBody,
+            String language, String functionKind, List<List<List<String>>> 
dependencies) {
+        this.signature = signature;
         this.params = params;
         this.body = functionBody;
         this.returnType = returnType == null ? RETURNTYPE_VOID : returnType;
         this.language = language;
         this.kind = functionKind;
-        this.arity = arity;
         if (dependencies == null) {
             this.dependencies = new ArrayList<>();
             this.dependencies.add(new ArrayList<>());
@@ -62,12 +59,20 @@
         }
     }
 
+    public FunctionSignature getSignature() {
+        return signature;
+    }
+
     public String getDataverseName() {
-        return dataverse;
+        return signature.getNamespace();
     }
 
     public String getName() {
-        return name;
+        return signature.getName();
+    }
+
+    public int getArity() {
+        return signature.getArity();
     }
 
     public List<String> getParams() {
@@ -88,10 +93,6 @@
 
     public String getLanguage() {
         return language;
-    }
-
-    public int getArity() {
-        return arity;
     }
 
     public String getKind() {
diff --git 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java
 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java
index 273c78a..120aa08 100644
--- 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java
+++ 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java
@@ -26,6 +26,7 @@
 import java.util.List;
 
 import org.apache.asterix.builders.OrderedListBuilder;
+import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
 import org.apache.asterix.metadata.bootstrap.MetadataPrimaryIndexes;
 import org.apache.asterix.metadata.bootstrap.MetadataRecordTypes;
@@ -136,9 +137,8 @@
 
         }
 
-        return new Function(dataverseName, functionName, 
Integer.parseInt(arity), params, returnType, definition,
-                language, functionKind, dependencies);
-
+        FunctionSignature signature = new FunctionSignature(dataverseName, 
functionName, Integer.parseInt(arity));
+        return new Function(signature, params, returnType, definition, 
language, functionKind, dependencies);
     }
 
     @Override
diff --git 
a/asterixdb/asterix-metadata/src/test/java/org/apache/asterix/metadata/functions/ExternalFunctionCompilerUtilTest.java
 
b/asterixdb/asterix-metadata/src/test/java/org/apache/asterix/metadata/functions/ExternalFunctionCompilerUtilTest.java
index 5e5b26a..b4bae90 100644
--- 
a/asterixdb/asterix-metadata/src/test/java/org/apache/asterix/metadata/functions/ExternalFunctionCompilerUtilTest.java
+++ 
b/asterixdb/asterix-metadata/src/test/java/org/apache/asterix/metadata/functions/ExternalFunctionCompilerUtilTest.java
@@ -20,6 +20,7 @@
 
 import java.util.LinkedList;
 
+import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.common.transactions.TxnId;
 import org.apache.asterix.metadata.MetadataTransactionContext;
 import org.apache.asterix.metadata.entities.Function;
@@ -35,8 +36,8 @@
     public void test() throws AlgebricksException {
         // given
         MetadataTransactionContext txnCtx = new MetadataTransactionContext(new 
TxnId(1));
-        Function function =
-                new Function("test", "test", 0, new LinkedList<>(), 
"{{ASTRING}}", "", "JAVA", "SCALAR", null);
+        FunctionSignature signature = new FunctionSignature("test", "test", 0);
+        Function function = new Function(signature, new LinkedList<>(), 
"{{ASTRING}}", "", "JAVA", "SCALAR", null);
 
         // when
         ExternalScalarFunctionInfo info =

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2380
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If00a914a1e56190ecd12c2687c32b4edc2895018
Gerrit-PatchSet: 4
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <ti...@apache.org>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Murtadha Hubail <mhub...@apache.org>
Gerrit-Reviewer: Till Westmann <ti...@apache.org>

Reply via email to