asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dl...@apache.org
Subject [01/24] asterixdb git commit: [NO ISSUE][COMP] Function references cleanup
Date Wed, 08 Nov 2017 21:51:40 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 63645130f -> 7c53fcf40


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
index c271365..6e6ffeb 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
@@ -39,13 +39,13 @@ import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
 import org.apache.asterix.lang.sqlpp.visitor.CheckDatasetOnlyResolutionVisitor;
 import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppExpressionScopingVisitor;
 import org.apache.asterix.metadata.declared.MetadataProvider;
-import org.apache.asterix.metadata.utils.MetadataConstants;
+import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 
 public class VariableCheckAndRewriteVisitor extends AbstractSqlppExpressionScopingVisitor
{
 
-    protected final FunctionSignature datasetFunction =
-            new FunctionSignature(MetadataConstants.METADATA_DATAVERSE_NAME, "dataset", 1);
+    private static final FunctionSignature FN_DATASET = new FunctionSignature(BuiltinFunctions.DATASET);
+
     protected final boolean overwrite;
     protected final MetadataProvider metadataProvider;
 
@@ -79,7 +79,7 @@ public class VariableCheckAndRewriteVisitor extends AbstractSqlppExpressionScopi
                     fa, parent);
             if (resolvedExpr.getKind() == Kind.CALL_EXPRESSION) {
                 CallExpr callExpr = (CallExpr) resolvedExpr;
-                if (callExpr.getFunctionSignature().equals(datasetFunction)) {
+                if (callExpr.getFunctionSignature().equals(FN_DATASET)) {
                     // The field access is resolved to be a dataset access in the form of
"dataverse.dataset".
                     return resolvedExpr;
                 }
@@ -172,7 +172,7 @@ public class VariableCheckAndRewriteVisitor extends AbstractSqlppExpressionScopi
         String fullyQualifiedName = dataverseName == null ? datasetName : dataverseName +
"." + datasetName;
         List<Expression> argList = new ArrayList<>();
         argList.add(new LiteralExpr(new StringLiteral(fullyQualifiedName)));
-        return new CallExpr(datasetFunction, argList);
+        return new CallExpr(new FunctionSignature(BuiltinFunctions.DATASET), argList);
     }
 
     private boolean datasetExists(String dataverseName, String datasetName) throws CompilationException
{

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
index 8a8465d..06bb1b9 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
@@ -36,6 +36,7 @@ import org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
 
 public class FunctionMapUtil {
 
+    public static final String CONCAT = "concat";
     private final static String CORE_AGGREGATE_PREFIX = "coll_";
     private final static String CORE_SQL_AGGREGATE_PREFIX = "array_";
     private final static String INTERNAL_SQL_AGGREGATE_PREFIX = "sql-";
@@ -44,7 +45,7 @@ public class FunctionMapUtil {
     private static final Map<String, String> LIST_INPUT_FUNCTION_MAP = new HashMap<>();
 
     static {
-        LIST_INPUT_FUNCTION_MAP.put("concat", "string-concat");
+        LIST_INPUT_FUNCTION_MAP.put(CONCAT, BuiltinFunctions.STRING_CONCAT.getName());
         LIST_INPUT_FUNCTION_MAP.put("greatest", CORE_SQL_AGGREGATE_PREFIX + "max");
         LIST_INPUT_FUNCTION_MAP.put("least", CORE_SQL_AGGREGATE_PREFIX + "min");
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppDeleteRewriteVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppDeleteRewriteVisitor.java
b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppDeleteRewriteVisitor.java
index 680ce55..4cda253 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppDeleteRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppDeleteRewriteVisitor.java
@@ -42,6 +42,7 @@ import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
 import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
 import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppAstVisitor;
+import org.apache.asterix.om.functions.BuiltinFunctions;
 
 /**
  * This class rewrites delete statement to contain a query that specifying
@@ -58,8 +59,7 @@ public class SqlppDeleteRewriteVisitor extends AbstractSqlppAstVisitor<Void,
Voi
                 : dataverseName.getValue() + "." + datasetName.getValue();
         LiteralExpr argumentLiteral = new LiteralExpr(new StringLiteral(arg));
         arguments.add(argumentLiteral);
-        CallExpr callExpression =
-                new CallExpr(new FunctionSignature(FunctionConstants.ASTERIX_NS, "dataset",
1), arguments);
+        CallExpr callExpression = new CallExpr(new FunctionSignature(BuiltinFunctions.DATASET),
arguments);
 
         // From clause.
         VariableExpr var = deleteStmt.getVariableExpr();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
index 96c5987..a935b3b 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
@@ -58,15 +58,12 @@ import org.apache.asterix.lang.sqlpp.expression.IndependentSubquery;
 import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
 import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
-import org.apache.asterix.metadata.utils.MetadataConstants;
+import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.core.algebra.base.Counter;
-import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 
 public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleExpressionVisitor
{
 
-    protected final FunctionSignature resolveFunction =
-            new FunctionSignature(MetadataConstants.METADATA_DATAVERSE_NAME, "resolve", FunctionIdentifier.VARARGS);
     protected final ScopeChecker scopeChecker = new ScopeChecker();
     protected final LangRewritingContext context;
 
@@ -389,7 +386,7 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
         String varName = SqlppVariableUtil.toUserDefinedVariableName(expr.getVar().getValue()).getValue();
         argList.add(new LiteralExpr(new StringLiteral(varName)));
         argList.addAll(liveVars);
-        return new CallExpr(resolveFunction, argList);
+        return new CallExpr(new FunctionSignature(BuiltinFunctions.RESOLVE), argList);
     }
 
     // Adds a new encountered alias identifier into a scope

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index d3a64d8..7c4d15c 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -64,6 +64,7 @@ import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
 import org.apache.asterix.common.config.DatasetConfig.IndexType;
 import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Literal;
@@ -165,6 +166,7 @@ import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
 import org.apache.asterix.lang.sqlpp.util.ExpressionToVariableUtil;
 import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
 import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
+import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.common.utils.Triple;
 import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
@@ -1856,7 +1858,7 @@ Expression NotExpr()throws ParseException:
   (<NOT> { not = true; } )? inputExpr = RelExpr()
   {
     if(not){
-        FunctionSignature signature = new FunctionSignature(null, "not", 1);
+        FunctionSignature signature = new FunctionSignature(BuiltinFunctions.NOT);
         return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr)));
     } else {
         return inputExpr;
@@ -1985,16 +1987,22 @@ Expression IsExpr() throws ParseException:
     Expression expr = null;
     Expression operand = null;
     boolean not = false;
+    FunctionIdentifier fn = null;
 }
 {
     operand = LikeExpr()
-    ( <IS> (<NOT> { not = true; })? (<NULL> | <MISSING> | <UNKOWN>)
+    ( <IS>
+        (<NOT> { not = true; })?
+        (
+            <NULL> { fn = BuiltinFunctions.IS_NULL; } |
+            <MISSING> { fn = BuiltinFunctions.IS_MISSING; } |
+            <UNKOWN> { fn = BuiltinFunctions.IS_UNKNOWN; }
+        )
       {
-        String functionName = "is-" + token.image.toLowerCase();
-        FunctionSignature signature = new FunctionSignature(null, functionName, 1);
+        FunctionSignature signature = new FunctionSignature(fn);
         expr = new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(operand)));
         if(not) {
-           FunctionSignature notSignature = new FunctionSignature(null, "not", 1);
+           FunctionSignature notSignature = new FunctionSignature(BuiltinFunctions.NOT);
            expr = new CallExpr(notSignature, new ArrayList<Expression>(Collections.singletonList(expr)));
         }
       }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/common/ExpressionTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/common/ExpressionTypeComputer.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/common/ExpressionTypeComputer.java
index 5933dd9..e4cf000 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/common/ExpressionTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/common/ExpressionTypeComputer.java
@@ -68,7 +68,7 @@ public class ExpressionTypeComputer implements IExpressionTypeComputer {
         FunctionIdentifier fi = expr.getFunctionIdentifier();
         // Note: built-in functions + udfs
         IResultTypeComputer rtc;
-        FunctionSignature signature = new FunctionSignature(fi.getNamespace(), fi.getName(),
fi.getArity());
+        FunctionSignature signature = new FunctionSignature(fi);
         if (BuiltinFunctions.isBuiltinCompilerFunction(signature, true)) {
             rtc = BuiltinFunctions.getResultTypeComputer(fi);
         } else {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index 863847b..cdb0dc0 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -825,7 +825,7 @@ public class BuiltinFunctions {
     public static final FunctionIdentifier NUMERIC_ADD = AlgebricksBuiltinFunctions.NUMERIC_ADD;
     public static final FunctionIdentifier IS_MISSING = AlgebricksBuiltinFunctions.IS_MISSING;
     public static final FunctionIdentifier IS_NULL = AlgebricksBuiltinFunctions.IS_NULL;
-    public static final FunctionIdentifier IS_UNKOWN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier IS_UNKNOWN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "is-unknown", 1);
     public static final FunctionIdentifier IS_BOOLEAN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "is-boolean", 1);
@@ -883,7 +883,7 @@ public class BuiltinFunctions {
 
         // first, take care of Algebricks builtin functions
         addFunction(IS_MISSING, BooleanOnlyTypeComputer.INSTANCE, true);
-        addFunction(IS_UNKOWN, BooleanOnlyTypeComputer.INSTANCE, true);
+        addFunction(IS_UNKNOWN, BooleanOnlyTypeComputer.INSTANCE, true);
         addFunction(IS_NULL, BooleanOrMissingTypeComputer.INSTANCE, true);
         addFunction(IS_SYSTEM_NULL, ABooleanTypeComputer.INSTANCE, true);
         addFunction(IS_BOOLEAN, ABooleanTypeComputer.INSTANCE, true);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/FunctionInfoRepository.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/FunctionInfoRepository.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/FunctionInfoRepository.java
index b4622b5..20839f9 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/FunctionInfoRepository.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/FunctionInfoRepository.java
@@ -29,12 +29,12 @@ public class FunctionInfoRepository {
     private final Map<FunctionSignature, IFunctionInfo> functionMap;
 
     public FunctionInfoRepository() {
-        functionMap = new ConcurrentHashMap<FunctionSignature, IFunctionInfo>();
+        functionMap = new ConcurrentHashMap<>();
     }
 
     public IFunctionInfo get(String namespace, String name, int arity) {
-        FunctionSignature fname = new FunctionSignature(namespace, name, arity);
-        return functionMap.get(fname);
+        FunctionSignature functionSignature = new FunctionSignature(namespace, name, arity);
+        return functionMap.get(functionSignature);
     }
 
     public IFunctionInfo get(FunctionIdentifier fid) {
@@ -42,7 +42,7 @@ public class FunctionInfoRepository {
     }
 
     public void put(FunctionIdentifier fid, IFunctionInfo fInfo) {
-        FunctionSignature functionSignature = new FunctionSignature(fid.getNamespace(), fid.getName(),
fid.getArity());
+        FunctionSignature functionSignature = new FunctionSignature(fid);
         functionMap.put(functionSignature, fInfo);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7c53fcf4/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsUnknownDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsUnknownDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsUnknownDescriptor.java
index bf080d3..0a8d86d 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsUnknownDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsUnknownDescriptor.java
@@ -61,7 +61,7 @@ public class IsUnknownDescriptor extends AbstractScalarFunctionDynamicDescriptor
 
     @Override
     public FunctionIdentifier getIdentifier() {
-        return BuiltinFunctions.IS_UNKOWN;
+        return BuiltinFunctions.IS_UNKNOWN;
     }
 
 }


Mime
View raw message