>From Ritik Raj <[email protected]>:

Ritik Raj has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20030 )


Change subject: [NO ISSUE][COMP] Restricting pushdown for array functions
......................................................................

[NO ISSUE][COMP] Restricting pushdown for array functions

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

Details:
Since array comparison is not supported for
filter-pushdown, restricting the expression which
can lead to the array comparison.

Change-Id: Ib0525b687bc0e4c41a21b5ff18cca0b891e2c906
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/AbstractFilterPushdownProcessor.java
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/DeltaTableFilterPushdownProcessor.java
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ParquetFilterPushdownProcessor.java
M 
asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnFilterPushdownProcessor.java
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ExternalDatasetFilterPushdownProcessor.java
7 files changed, 149 insertions(+), 84 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/30/20030/1

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/AbstractFilterPushdownProcessor.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/AbstractFilterPushdownProcessor.java
index 593a83f..d284c2e 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/AbstractFilterPushdownProcessor.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/AbstractFilterPushdownProcessor.java
@@ -19,6 +19,7 @@
 package org.apache.asterix.optimizer.rules.pushdown.processor;

 import static org.apache.asterix.metadata.utils.PushdownUtil.getConstant;
+import static org.apache.asterix.metadata.utils.PushdownUtil.getTypeEnv;
 import static org.apache.asterix.metadata.utils.PushdownUtil.isAnd;
 import static org.apache.asterix.metadata.utils.PushdownUtil.isCompare;
 import static org.apache.asterix.metadata.utils.PushdownUtil.isConstant;
@@ -36,6 +37,9 @@
 import java.util.Set;

 import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.optimizer.rules.pushdown.PushdownContext;
 import org.apache.asterix.optimizer.rules.pushdown.descriptor.DefineDescriptor;
 import 
org.apache.asterix.optimizer.rules.pushdown.descriptor.ScanDefineDescriptor;
@@ -117,16 +121,17 @@
      * @param expression the expression to push down
      * @return true if it is NOT pushable, false otherwise
      */
-    protected abstract boolean isNotPushable(AbstractFunctionCallExpression 
expression, int depth);
+    protected abstract boolean isNotPushable(AbstractFunctionCallExpression 
expression);

     /**
      * Handle a compare function
      *
-     * @param expression compare expression
+     * @param expression        compare expression
+     * @param currentDescriptor
      * @return true if the pushdown should continue, false otherwise
      */
-    protected abstract boolean handleCompare(AbstractFunctionCallExpression 
expression, int depth)
-            throws AlgebricksException;
+    protected abstract FilterBranch 
handleCompare(AbstractFunctionCallExpression expression, int depth,
+            UseDescriptor currentDescriptor) throws AlgebricksException;

     /**
      * Handle a value access path expression
@@ -134,10 +139,10 @@
      * @param expression path expression
      * @return true if the pushdown should continue, false otherwise
      */
-    protected final boolean handlePath(AbstractFunctionCallExpression 
expression) throws AlgebricksException {
+    protected final FilterBranch handlePath(AbstractFunctionCallExpression 
expression) throws AlgebricksException {
         IExpectedSchemaNode node = getPathNode(expression);
         if (node == null) {
-            return false;
+            return FilterBranch.NA;
         }
         return handlePath(expression, node);
     }
@@ -149,7 +154,7 @@
      * @param node       expected schema node (never null)
      * @return true if the pushdown should continue, false otherwise
      */
-    protected abstract boolean handlePath(AbstractFunctionCallExpression 
expression, IExpectedSchemaNode node)
+    protected abstract FilterBranch handlePath(AbstractFunctionCallExpression 
expression, IExpectedSchemaNode node)
             throws AlgebricksException;

     protected abstract IExpectedSchemaNode 
getPathNode(AbstractFunctionCallExpression expression)
@@ -285,7 +290,7 @@

         // Prepare for pushdown
         preparePushdown(useDescriptor, scanDefineDescriptor);
-        if (pushdownFilterExpression(inlinedExpr, 0)) {
+        if (pushdownFilterExpression(inlinedExpr, useDescriptor, 0) != 
FilterBranch.NA) {
             putFilterInformation(scanDefineDescriptor, inlinedExpr);
             changed = true;
         }
@@ -293,57 +298,96 @@
         return changed;
     }

-    protected final boolean pushdownFilterExpression(ILogicalExpression 
expression, int depth)
-            throws AlgebricksException {
-        boolean pushdown = false;
+    public enum FilterBranch {
+        CONSTANT,
+        AND,
+        COMPARE,
+        FILTER_PATH,
+        FUNCTION,
+        NA;
+
+        public static FilterBranch andOutput(FilterBranch leftBranch, 
FilterBranch rightBranch,
+                FilterBranch parentBranch) {
+            if (leftBranch == FilterBranch.NA || rightBranch == 
FilterBranch.NA) {
+                return FilterBranch.NA;
+            }
+            return parentBranch;
+        }
+    };
+
+    protected final FilterBranch pushdownFilterExpression(ILogicalExpression 
expression, UseDescriptor useDescriptor,
+            int depth) throws AlgebricksException {
         if (isConstant(expression)) {
             IAObject constantValue = getConstant(expression);
             // Only non-derived types are allowed
-            pushdown = !constantValue.getType().getTypeTag().isDerivedType();
+            if (!constantValue.getType().getTypeTag().isDerivedType()) {
+                return FilterBranch.CONSTANT;
+            }
+            return FilterBranch.NA;
         } else if (isAnd(expression)) {
-            pushdown = handleAnd((AbstractFunctionCallExpression) expression, 
depth);
+            return handleAnd((AbstractFunctionCallExpression) expression, 
depth, useDescriptor);
         } else if (isCompare(expression)) {
-            pushdown = handleCompare((AbstractFunctionCallExpression) 
expression, depth);
+            return handleCompare((AbstractFunctionCallExpression) expression, 
depth, useDescriptor);
         } else if (isFilterPath(expression)) {
-            pushdown = handlePath((AbstractFunctionCallExpression) expression);
+            return handlePath((AbstractFunctionCallExpression) expression);
         } else if (expression.getExpressionTag() == 
LogicalExpressionTag.FUNCTION_CALL) {
             // All functions including OR
-            pushdown = handleFunction((AbstractFunctionCallExpression) 
expression, depth);
+            return handleFunction((AbstractFunctionCallExpression) expression, 
depth, useDescriptor);
         }
         // PK variable should have (pushdown = false) as we should not involve 
the PK (at least currently)
-        return pushdown;
+        return FilterBranch.NA;
     }

-    private boolean handleAnd(AbstractFunctionCallExpression expression, int 
depth) throws AlgebricksException {
+    private FilterBranch handleAnd(AbstractFunctionCallExpression expression, 
int depth, UseDescriptor useDescriptor)
+            throws AlgebricksException {
         List<Mutable<ILogicalExpression>> args = expression.getArguments();
         Iterator<Mutable<ILogicalExpression>> argIter = args.iterator();
         while (argIter.hasNext()) {
             ILogicalExpression arg = argIter.next().getValue();
             // Allow for partial pushdown of AND operands
-            if (!pushdownFilterExpression(arg, depth + 1)) {
+            if (pushdownFilterExpression(arg, useDescriptor, depth + 1) == 
FilterBranch.NA) {
                 if (depth == 0) {
                     // Remove the expression that cannot be pushed down
                     argIter.remove();
                 } else {
-                    return false;
+                    return FilterBranch.NA;
                 }
             }
         }
-        return !args.isEmpty();
+        return !args.isEmpty() ? FilterBranch.AND : FilterBranch.NA;
     }

-    private boolean handleFunction(AbstractFunctionCallExpression expression, 
int depth) throws AlgebricksException {
-        if (!expression.getFunctionInfo().isFunctional() || 
isNotPushable(expression, depth)) {
+    protected boolean isExpressionReturningArray(ILogicalExpression 
expression, ILogicalOperator operator)
+            throws AlgebricksException {
+        IAType expressionType = (IAType) 
context.getExpressionTypeComputer().getType(expression,
+                context.getMetadataProvider(), getTypeEnv(operator, context));
+        // if the expression is not an array, we cannot push it down
+        if (ATypeTag.ARRAY == expressionType.getTypeTag() || ATypeTag.ANY == 
expressionType.getTypeTag()) {
             return false;
         }
+        // if it's a union type, check for the original type
+        if (ATypeTag.UNION == expressionType.getTypeTag()) {
+            AUnionType unionType = (AUnionType) expressionType;
+            IAType actualType = unionType.getActualType();
+            return ATypeTag.ARRAY != actualType.getTypeTag() && ATypeTag.ANY 
!= actualType.getTypeTag();
+        }
+
+        return true;
+    }
+
+    private FilterBranch handleFunction(AbstractFunctionCallExpression 
expression, int depth,
+            UseDescriptor useDescriptor) throws AlgebricksException {
+        if (!expression.getFunctionInfo().isFunctional() || 
isNotPushable(expression)) {
+            return FilterBranch.NA;
+        }

         for (Mutable<ILogicalExpression> argRef : expression.getArguments()) {
             ILogicalExpression arg = argRef.getValue();
             // Either all arguments are pushable or none
-            if (!pushdownFilterExpression(arg, depth + 1)) {
-                return false;
+            if (pushdownFilterExpression(arg, useDescriptor, depth + 1) == 
FilterBranch.NA) {
+                return FilterBranch.NA;
             }
         }
-        return true;
+        return FilterBranch.FUNCTION;
     }
 }
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnFilterPushdownProcessor.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnFilterPushdownProcessor.java
index 7ab13f8..fee3fea 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnFilterPushdownProcessor.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnFilterPushdownProcessor.java
@@ -99,12 +99,13 @@
     }

     @Override
-    protected boolean isNotPushable(AbstractFunctionCallExpression expression, 
int depth) {
-        return isProhibitedFilterFunction(expression, depth);
+    protected boolean isNotPushable(AbstractFunctionCallExpression expression) 
{
+        return isProhibitedFilterFunction(expression);
     }

     @Override
-    protected boolean handleCompare(AbstractFunctionCallExpression expression, 
int depth) throws AlgebricksException {
+    protected FilterBranch handleCompare(AbstractFunctionCallExpression 
expression, int depth,
+            UseDescriptor currentDescriptor) throws AlgebricksException {
         List<Mutable<ILogicalExpression>> args = expression.getArguments();

         Mutable<ILogicalExpression> leftRef = args.get(0);
@@ -113,17 +114,37 @@
         ILogicalExpression left = leftRef.getValue();
         ILogicalExpression right = rightRef.getValue();

-        return pushdownFilterExpression(left, depth + 1) && 
pushdownFilterExpression(right, depth + 1);
+        //If the left or right is handlePath (like getField), then the right 
or left shouldn't be an array
+        FilterBranch leftBranch = pushdownFilterExpression(left, 
currentDescriptor, depth + 1);
+        FilterBranch rightBranch = pushdownFilterExpression(right, 
currentDescriptor, depth + 1);
+
+        FilterBranch result = FilterBranch.andOutput(leftBranch, rightBranch, 
FilterBranch.COMPARE);
+        if (result == FilterBranch.NA) {
+            // If the result is NA, then we cannot push down the filter
+            return FilterBranch.NA;
+        }
+
+        boolean pushdown = true;
+        //If the value is a filterPath, means it is coming from the expression 
tree.
+        if (leftBranch == FilterBranch.FILTER_PATH && rightBranch == 
FilterBranch.FILTER_PATH) {
+            return FilterBranch.COMPARE;
+        } else if (leftBranch == FilterBranch.FILTER_PATH) {
+            pushdown = isExpressionReturningArray(right, 
currentDescriptor.getOperator());
+        } else if (rightBranch == FilterBranch.FILTER_PATH) {
+            pushdown = isExpressionReturningArray(left, 
currentDescriptor.getOperator());
+        }
+
+        return pushdown ? FilterBranch.FILTER_PATH : FilterBranch.NA;
     }

     @Override
-    protected boolean handlePath(AbstractFunctionCallExpression expression, 
IExpectedSchemaNode node)
+    protected FilterBranch handlePath(AbstractFunctionCallExpression 
expression, IExpectedSchemaNode node)
             throws AlgebricksException {
         if (node.getType() != ExpectedSchemaNodeType.ANY) {
-            return false;
+            return FilterBranch.NA;
         }
         paths.put(expression, 
pathBuilderVisitor.buildPath((AnyExpectedSchemaNode) node));
-        return true;
+        return FilterBranch.FILTER_PATH;
     }

     @Override
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java
index 274e165..04a9f6d 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ColumnRangeFilterPushdownProcessor.java
@@ -78,12 +78,13 @@
     }

     @Override
-    protected boolean isNotPushable(AbstractFunctionCallExpression expression, 
int depth) {
+    protected boolean isNotPushable(AbstractFunctionCallExpression expression) 
{
         return 
!RANGE_FILTER_PUSHABLE_FUNCTIONS.contains(expression.getFunctionIdentifier());
     }

     @Override
-    protected boolean handleCompare(AbstractFunctionCallExpression expression, 
int depth) throws AlgebricksException {
+    protected FilterBranch handleCompare(AbstractFunctionCallExpression 
expression, int depth,
+            UseDescriptor currentDescriptor) throws AlgebricksException {
         List<Mutable<ILogicalExpression>> args = expression.getArguments();

         Mutable<ILogicalExpression> leftRef = args.get(0);
@@ -98,15 +99,15 @@
             return pushdownRangeFilter(left, right, expression, false);
         }
         // Either it is a compare that doesn't involve a constant there's a 
function that wraps the value access path
-        return false;
+        return FilterBranch.NA;
     }

     @Override
-    protected boolean handlePath(AbstractFunctionCallExpression expression, 
IExpectedSchemaNode node)
+    protected FilterBranch handlePath(AbstractFunctionCallExpression 
expression, IExpectedSchemaNode node)
             throws AlgebricksException {
         // This means we got something like WHERE $r.getField("isVerified") -- 
where isVerified is a boolean field.
         if (node.getType() != ExpectedSchemaNodeType.ANY) {
-            return false;
+            return FilterBranch.NA;
         }
         IAObject constantValue = ABoolean.TRUE;
         String functionName = expression.getFunctionIdentifier().getName();
@@ -116,7 +117,7 @@
         ARecordType path = 
pathBuilderVisitor.buildPath((AnyExpectedSchemaNode) node, 
constantValue.getType(),
                 sourceInformationMap, functionCallInfo);
         paths.put(expression, path);
-        return true;
+        return FilterBranch.FILTER_PATH;
     }

     @Override
@@ -132,12 +133,12 @@
         scanDefineDescriptor.getPathLocations().putAll(sourceInformationMap);
     }

-    private boolean pushdownRangeFilter(ILogicalExpression pathExpr, 
ILogicalExpression constExpr,
+    private FilterBranch pushdownRangeFilter(ILogicalExpression pathExpr, 
ILogicalExpression constExpr,
             AbstractFunctionCallExpression funcExpr, boolean leftConstant) 
throws AlgebricksException {
         AnyExpectedSchemaNode node = getNode(pathExpr);
         IAObject constantValue = ((AsterixConstantValue) ((ConstantExpression) 
constExpr).getValue()).getObject();
         if (node == null || 
!SUPPORTED_CONSTANT_TYPES.contains(constantValue.getType().getTypeTag())) {
-            return false;
+            return FilterBranch.NA;
         }
         String functionName = funcExpr.getFunctionIdentifier().getName();
         SourceLocation sourceLocation = funcExpr.getSourceLocation();
@@ -146,7 +147,7 @@
         ARecordType path =
                 pathBuilderVisitor.buildPath(node, constantValue.getType(), 
sourceInformationMap, functionCallInfo);
         paths.put(pathExpr, path);
-        return true;
+        return FilterBranch.COMPARE;
     }

     private AnyExpectedSchemaNode getNode(ILogicalExpression expression) 
throws AlgebricksException {
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/DeltaTableFilterPushdownProcessor.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/DeltaTableFilterPushdownProcessor.java
index 71dccd4..a5382c0 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/DeltaTableFilterPushdownProcessor.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/DeltaTableFilterPushdownProcessor.java
@@ -44,21 +44,21 @@
     }

     @Override
-    protected boolean isNotPushable(AbstractFunctionCallExpression expression, 
int depth) {
+    protected boolean isNotPushable(AbstractFunctionCallExpression expression) 
{
         FunctionIdentifier fid = expression.getFunctionIdentifier();
-        return ARRAY_FUNCTIONS.contains(fid) || 
super.isNotPushable(expression, -1);
+        return ARRAY_FUNCTIONS.contains(fid) || 
super.isNotPushable(expression);
     }

     @Override
-    protected boolean handlePath(AbstractFunctionCallExpression expression, 
IExpectedSchemaNode node)
+    protected FilterBranch handlePath(AbstractFunctionCallExpression 
expression, IExpectedSchemaNode node)
             throws AlgebricksException {
         if (node.getType() != ExpectedSchemaNodeType.ANY) {
-            return false;
+            return FilterBranch.NA;
         }

         // The inferred path from the provided expression
         ARecordType expressionPath = 
pathBuilderVisitor.buildPath((AnyExpectedSchemaNode) node);
         paths.put(expression, expressionPath);
-        return true;
+        return FilterBranch.FILTER_PATH;
     }
 }
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ExternalDatasetFilterPushdownProcessor.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ExternalDatasetFilterPushdownProcessor.java
index 91286ad..50180c4 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ExternalDatasetFilterPushdownProcessor.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ExternalDatasetFilterPushdownProcessor.java
@@ -67,16 +67,16 @@
     }

     @Override
-    protected boolean isNotPushable(AbstractFunctionCallExpression expression, 
int depth) {
+    protected boolean isNotPushable(AbstractFunctionCallExpression expression) 
{
         FunctionIdentifier fid = expression.getFunctionIdentifier();
-        return ARRAY_FUNCTIONS.contains(fid) || 
super.isNotPushable(expression, -1);
+        return ARRAY_FUNCTIONS.contains(fid) || 
super.isNotPushable(expression);
     }

     @Override
-    protected boolean handlePath(AbstractFunctionCallExpression expression, 
IExpectedSchemaNode node)
+    protected FilterBranch handlePath(AbstractFunctionCallExpression 
expression, IExpectedSchemaNode node)
             throws AlgebricksException {
         if (node.getType() != ExpectedSchemaNodeType.ANY) {
-            return false;
+            return FilterBranch.NA;
         }

         // The inferred path from the provided expression
@@ -84,8 +84,8 @@
         if (prefix.getPaths().contains(expressionPath)) {
             // The expression refer to a declared computed field. Add it to 
the filter paths
             paths.put(expression, expressionPath);
-            return true;
+            return FilterBranch.FILTER_PATH;
         }
-        return false;
+        return FilterBranch.NA;
     }
 }
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ParquetFilterPushdownProcessor.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ParquetFilterPushdownProcessor.java
index 55a812e..f6c94c6 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ParquetFilterPushdownProcessor.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/ParquetFilterPushdownProcessor.java
@@ -45,21 +45,21 @@
     }

     @Override
-    protected boolean isNotPushable(AbstractFunctionCallExpression expression, 
int depth) {
+    protected boolean isNotPushable(AbstractFunctionCallExpression expression) 
{
         return 
!RANGE_FILTER_PUSHABLE_FUNCTIONS.contains(expression.getFunctionIdentifier());
     }

     @Override
-    protected boolean handlePath(AbstractFunctionCallExpression expression, 
IExpectedSchemaNode node)
+    protected FilterBranch handlePath(AbstractFunctionCallExpression 
expression, IExpectedSchemaNode node)
             throws AlgebricksException {
         if (node.getType() != ExpectedSchemaNodeType.ANY) {
-            return false;
+            return FilterBranch.NA;
         }

         // The inferred path from the provided expression
         ARecordType expressionPath = 
pathBuilderVisitor.buildPath((AnyExpectedSchemaNode) node);
         paths.put(expression, expressionPath);
-        return true;
+        return FilterBranch.FILTER_PATH;
     }

     @Override
diff --git 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java
 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java
index 97ddba9..316b559 100644
--- 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java
+++ 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/PushdownUtil.java
@@ -29,9 +29,6 @@
 import org.apache.asterix.om.base.IAObject;
 import org.apache.asterix.om.constants.AsterixConstantValue;
 import org.apache.asterix.om.functions.BuiltinFunctions;
-import org.apache.asterix.om.typecomputer.impl.ListConstructorTypeComputer;
-import org.apache.asterix.om.typecomputer.impl.OrderedListOfAnyTypeComputer;
-import org.apache.asterix.om.typecomputer.impl.ToArrayTypeComputer;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.AUnionType;
@@ -174,10 +171,9 @@
         return fid.getName().startsWith("is");
     }

-    public static boolean isNestedFunction(FunctionIdentifier fid, 
AbstractFunctionCallExpression expression,
-            int depth) {
-        return isObjectFunction(fid) || isArrayOrAggregateFunction(fid, depth)
-                || BuiltinFunctions.DEEP_EQUAL.equals(fid) || 
isNonScalar(expression);
+    public static boolean isNestedFunction(FunctionIdentifier fid, 
AbstractFunctionCallExpression expression) {
+        return isObjectFunction(fid) || isArrayOrAggregateFunction(fid) || 
BuiltinFunctions.DEEP_EQUAL.equals(fid)
+                || isNonScalar(expression);
     }

     public static boolean isObjectFunction(FunctionIdentifier fid) {
@@ -185,25 +181,11 @@
         return functionName.contains("object") || 
BuiltinFunctions.PAIRS.equals(fid);
     }

-    public static boolean isArrayOrAggregateFunction(FunctionIdentifier fid, 
int depth) {
+    public static boolean isArrayOrAggregateFunction(FunctionIdentifier fid) {
         String functionName = fid.getName();
         return functionName.startsWith("array") || 
functionName.startsWith("strict") || functionName.startsWith("sql")
                 || BuiltinFunctions.GET_ITEM.equals(fid) || 
BuiltinFunctions.isBuiltinScalarAggregateFunction(fid)
-                || BuiltinFunctions.isBuiltinAggregateFunction(fid)
-                //To Reject a function if this is an outer function call, and 
returns an array
-                || hasArrayResultTypeComputerAtTop(fid, depth);
-    }
-
-    private static boolean hasArrayResultTypeComputerAtTop(FunctionIdentifier 
fid, int depth) {
-        if (depth == 0 || depth == 1) {
-            return BuiltinFunctions.getBuiltinFunctionInfo(fid)
-                    .getResultTypeComputer() instanceof 
OrderedListOfAnyTypeComputer
-                    || BuiltinFunctions.getBuiltinFunctionInfo(fid)
-                            .getResultTypeComputer() instanceof 
ListConstructorTypeComputer
-                    || BuiltinFunctions.getBuiltinFunctionInfo(fid)
-                            .getResultTypeComputer() instanceof 
ToArrayTypeComputer && (depth == 0 || depth == 1);
-        }
-        return false;
+                || BuiltinFunctions.isBuiltinAggregateFunction(fid);
     }

     public static boolean isNonScalar(AbstractFunctionCallExpression 
expression) {
@@ -225,11 +207,10 @@
         return fid != null && 
FILTER_PUSHABLE_AGGREGATE_FUNCTIONS.contains(fid);
     }

-    public static boolean 
isProhibitedFilterFunction(AbstractFunctionCallExpression expression, int 
depth) {
+    public static boolean 
isProhibitedFilterFunction(AbstractFunctionCallExpression expression) {
         FunctionIdentifier fid = getFunctionIdentifier(expression);
-        return fid != null && !RANGE_FILTER_PUSHABLE_FUNCTIONS.contains(fid)
-                && (isNestedFunction(fid, expression, depth) || 
isTypeFunction(fid)
-                        || FILTER_PROHIBITED_FUNCTIONS.contains(fid));
+        return fid != null && !RANGE_FILTER_PUSHABLE_FUNCTIONS.contains(fid) 
&& (isNestedFunction(fid, expression)
+                || isTypeFunction(fid) || 
FILTER_PROHIBITED_FUNCTIONS.contains(fid));
     }

     public static IAObject getConstant(ILogicalExpression expr) {

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20030
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: ionic
Gerrit-Change-Id: Ib0525b687bc0e4c41a21b5ff18cca0b891e2c906
Gerrit-Change-Number: 20030
Gerrit-PatchSet: 1
Gerrit-Owner: Ritik Raj <[email protected]>
Gerrit-MessageType: newchange

Reply via email to