>From Ritik Raj <[email protected]>:

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


Change subject: [ASTERIXDB-3582][COMP] Restricting to one unnest filter 
pushdown for a datasource
......................................................................

[ASTERIXDB-3582][COMP] Restricting to one unnest filter pushdown for a 
datasource

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

Currently, storage filter evaluation produces incorrect results when
multiple unnest filters are pushed down. This leads to inaccurate
query outputs.

To prevent incorrect evaluations, this change restricts the pushdown
to at most one unnest filter. This is a temporary safeguard until we
improve the evaluation algorithm.

Ext-ref: MB-65781
Change-Id: I4f335db4c7c455c1276ea5be9b14ce1e8ee92d74
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/processor/AbstractFilterPushdownProcessor.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.005.plan
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.004.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.002.update.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.003.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.005.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.003.adm
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/visitor/FilterExpressionInlineVisitor.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/descriptor/ScanDefineDescriptor.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.004.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.001.ddl.sqlpp
13 files changed, 655 insertions(+), 0 deletions(-)



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

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/descriptor/ScanDefineDescriptor.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/descriptor/ScanDefineDescriptor.java
index 3f3fa20..95ff920 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/descriptor/ScanDefineDescriptor.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/descriptor/ScanDefineDescriptor.java
@@ -44,6 +44,8 @@
     private RootExpectedSchemaNode metaNode;
     private ILogicalExpression filterExpression;
     private ILogicalExpression rangeFilterExpression;
+    private boolean pushedUnnestFnFilter;
+    private boolean pushedUnnestFnRangeFilter;

     public ScanDefineDescriptor(int scope, Dataset dataset, 
List<LogicalVariable> primaryKeyVariables,
             LogicalVariable recordVariable, LogicalVariable 
metaRecordVariable, ILogicalOperator operator) {
@@ -60,6 +62,22 @@
         }
     }

+    public void markUnnestFnFilterPushed() {
+        pushedUnnestFnFilter = true;
+    }
+
+    public void markUnnestFnRangeFilterPushed() {
+        pushedUnnestFnRangeFilter = true;
+    }
+
+    public boolean isUnnestFnFilterPushed() {
+        return pushedUnnestFnFilter;
+    }
+
+    public boolean isUnnestFnRangeFilterPushed() {
+        return pushedUnnestFnRangeFilter;
+    }
+
     @Override
     public boolean isScanDefinition() {
         return true;
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 6134d63..9a3097b 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
@@ -249,19 +249,41 @@
         boolean changed = false;

         FilterExpressionInlineVisitor inliningVisitor = 
pushdownContext.getInlineVisitor();
+        // Currently we restrict only one unnest to be pushed down, since the 
column storage
+        // filter evaluation does not support multiple unnest conditions to be 
pushed down.
+        inliningVisitor.resetUnnestFnEncounter();
         // Get a clone of the operator's expression and inline it
         ILogicalExpression inlinedExpr = 
inliningVisitor.cloneAndInline(useDescriptor, subplanSelects);

         // Prepare for pushdown
         preparePushdown(useDescriptor, scanDefineDescriptor);
         if (pushdownFilterExpression(inlinedExpr, 0)) {
+            if (canPushCurrentUnnestFn(scanDefineDescriptor, inliningVisitor)) 
{
+                // If the scanDefineDescriptor already pushed down an unnest 
function, then we should not push-down
+                return false;
+            }
             putFilterInformation(scanDefineDescriptor, inlinedExpr);
+            if (inliningVisitor.isEncounteredUnnestFnExpr()) {
+                markUnnestFnFilterPushed(scanDefineDescriptor);
+            }
             changed = true;
         }

         return changed;
     }

+    private boolean canPushCurrentUnnestFn(ScanDefineDescriptor 
scanDefineDescriptor,
+            FilterExpressionInlineVisitor inliningVisitor) {
+        return isUnnestFnFilterPushed(scanDefineDescriptor) && 
inliningVisitor.isEncounteredUnnestFnExpr();
+    }
+
+    protected boolean isUnnestFnFilterPushed(ScanDefineDescriptor 
scanDefineDescriptor) {
+        return false;
+    }
+
+    protected void markUnnestFnFilterPushed(ScanDefineDescriptor 
scanDefineDescriptor) {
+    }
+
     protected final boolean pushdownFilterExpression(ILogicalExpression 
expression, int depth)
             throws AlgebricksException {
         boolean pushdown = false;
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 425a78d..414ce04 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
@@ -100,6 +100,16 @@
     }

     @Override
+    protected boolean isUnnestFnFilterPushed(ScanDefineDescriptor 
scanDefineDescriptor) {
+        return scanDefineDescriptor.isUnnestFnFilterPushed();
+    }
+
+    @Override
+    protected void markUnnestFnFilterPushed(ScanDefineDescriptor 
scanDefineDescriptor) {
+        scanDefineDescriptor.markUnnestFnFilterPushed();
+    }
+
+    @Override
     protected boolean isNotPushable(AbstractFunctionCallExpression expression) 
{
         return isProhibitedFilterFunction(expression);
     }
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 75a7608..9028317 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,6 +78,16 @@
     }

     @Override
+    protected boolean isUnnestFnFilterPushed(ScanDefineDescriptor 
scanDefineDescriptor) {
+        return scanDefineDescriptor.isUnnestFnRangeFilterPushed();
+    }
+
+    @Override
+    protected void markUnnestFnFilterPushed(ScanDefineDescriptor 
scanDefineDescriptor) {
+        scanDefineDescriptor.markUnnestFnRangeFilterPushed();
+    }
+
+    @Override
     protected boolean isNotPushable(AbstractFunctionCallExpression expression) 
{
         return 
!RANGE_FILTER_PUSHABLE_FUNCTIONS.contains(expression.getFunctionIdentifier());
     }
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/visitor/FilterExpressionInlineVisitor.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/visitor/FilterExpressionInlineVisitor.java
index 56ab226..5f7b163 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/visitor/FilterExpressionInlineVisitor.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/pushdown/visitor/FilterExpressionInlineVisitor.java
@@ -23,8 +23,10 @@

 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;

 import 
org.apache.asterix.common.annotations.ExistsComparisonExpressionAnnotation;
 import org.apache.asterix.om.base.AOrderedList;
@@ -61,11 +63,22 @@
     private final PushdownContext pushdownContext;
     private final IOptimizationContext context;
     private final Map<ILogicalOperator, ILogicalExpression> inlinedCache;
+    private final Set<ILogicalOperator> containsUnnestFilterPushdown;
+    private boolean encounteredUnnestFnExpr;

     public FilterExpressionInlineVisitor(PushdownContext pushdownContext, 
IOptimizationContext context) {
         this.pushdownContext = pushdownContext;
         this.context = context;
         inlinedCache = new HashMap<>();
+        containsUnnestFilterPushdown = new HashSet<>();
+    }
+
+    public void resetUnnestFnEncounter() {
+        encounteredUnnestFnExpr = false;
+    }
+
+    public boolean isEncounteredUnnestFnExpr() {
+        return encounteredUnnestFnExpr;
     }

     public ILogicalExpression cloneAndInline(UseDescriptor useDescriptor,
@@ -75,8 +88,14 @@
         if (inlinedExpr == null) {
             inlinedExpr = useDescriptor.getExpression().accept(this, 
subplanSelects);
             inlinedCache.put(op, inlinedExpr);
+            if (encounteredUnnestFnExpr) {
+                containsUnnestFilterPushdown.add(op);
+            }
         }

+        if (containsUnnestFilterPushdown.contains(op)) {
+            encounteredUnnestFnExpr = true;
+        }
         // Clone the cached expression as a processor may change it
         return inlinedExpr.cloneExpression();
     }
@@ -133,6 +152,7 @@
     @Override
     public ILogicalExpression 
visitUnnestingFunctionCallExpression(UnnestingFunctionCallExpression expr,
             Map<ILogicalOperator, List<UseDescriptor>> subplanSelects) throws 
AlgebricksException {
+        encounteredUnnestFnExpr = true;
         return cloneAndInlineFunction(expr, subplanSelects);
     }

diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.001.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.001.ddl.sqlpp
new file mode 100644
index 0000000..ba0b695
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.001.ddl.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+CREATE DATAVERSE websales;
+CREATE DATAVERSE inventory;
+CREATE DATAVERSE marketing;
+
+CREATE DATASET websales.customers
+   PRIMARY KEY (custid: string) WITH { "storage-format": { "format": "column" 
}};
+
+CREATE DATASET websales.orders
+   PRIMARY KEY (orderno: int) WITH { "storage-format": { "format": "column" }};
+
+CREATE DATASET inventory.products
+   PRIMARY KEY (itemno: int) WITH { "storage-format": { "format": "column" }};
+
+CREATE DATASET marketing.reviews
+   PRIMARY KEY (itemno: int, custid: string) WITH { "storage-format": { 
"format": "column" }};
+
+CREATE DATASET marketing.inventory
+   PRIMARY KEY (id: string) WITH { "storage-format": { "format": "column" }};
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.002.update.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.002.update.sqlpp
new file mode 100644
index 0000000..39a7673
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.002.update.sqlpp
@@ -0,0 +1,413 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+INSERT INTO websales.customers
+([
+    {
+        "custid": "C13",
+        "name": "T. Cody",
+        "address": {
+            "street": "201 Main St.",
+            "city": "St. Louis, MO",
+            "zipcode": "63101"
+        },
+        "rating": 750
+    },
+    {
+        "custid": "C25",
+        "name": "M. Sinclair",
+        "address": {
+            "street": "690 River St.",
+            "city": "Hanover, MA",
+            "zipcode": "02340"
+        },
+        "rating": 690
+    },
+    {
+        "custid": "C31",
+        "name": "B. Pruitt",
+        "address": {
+            "street": "360 Mountain Ave.",
+            "city": "St. Louis, MO",
+            "zipcode": "63101"
+        }
+    },
+    {
+        "custid": "C35",
+        "name": "J. Roberts",
+        "address": {
+            "street": "420 Green St.",
+            "city": "Boston, MA",
+            "zipcode": "02115"
+        },
+        "rating": 565
+    },
+    {
+        "custid": "C37",
+        "name": "T. Henry",
+        "address": {
+            "street": "120 Harbor Blvd.",
+            "city": "Boston, MA",
+            "zipcode": "02115"
+        },
+        "rating": 750
+    },
+    {
+        "custid": "C41",
+        "name": "R. Dodge",
+        "address": {
+            "street": "150 Market St.",
+            "city": "St. Louis, MO",
+            "zipcode": "63101"
+        },
+        "rating": 640
+    },
+    {
+        "custid": "C47",
+        "name": "S. Logan",
+        "address": {
+            "street": "Via del Corso",
+            "city": "Rome, Italy"
+        },
+        "rating": 625
+    }
+]);
+INSERT INTO websales.orders
+([
+    {
+        "orderno": 1001,
+        "custid": "C41",
+        "order_date": "2020-04-29",
+        "ship_date": "2020-05-03",
+        "items": [
+            {
+                "itemno": 347,
+                "qty": 5,
+                "price": 19.99
+            },
+            {
+                "itemno": 193,
+                "qty": 2,
+                "price": 28.89
+            }
+        ]
+    },
+    {
+        "orderno": 1002,
+        "custid": "C13",
+        "order_date": "2020-05-01",
+        "ship_date": "2020-05-03",
+        "items": [
+            {
+                "itemno": 460,
+                "qty": 95,
+                "price": 29.99
+            },
+            {
+                "itemno": 680,
+                "qty": 150,
+                "price": 22.99
+            }
+        ]
+    },
+    {
+        "orderno": 1003,
+        "custid": "C31",
+        "order_date": "2020-06-15",
+        "ship_date": "2020-06-16",
+        "items": [
+            {
+                "itemno": 120,
+                "qty": 2,
+                "price": 88.99
+            },
+            {
+                "itemno": 460,
+                "qty": 3,
+                "price": 29.99
+            }
+        ]
+    },
+    {
+        "orderno": 1004,
+        "custid": "C35",
+        "order_date": "2020-07-10",
+        "ship_date": "2020-07-15",
+        "items": [
+            {
+                "itemno": 680,
+                "qty": 6,
+                "price": 29.99
+            },
+            {
+                "itemno": 195,
+                "qty": 4,
+                "price": 35.00
+            }
+        ]
+    },
+    {
+        "orderno": 1005,
+        "custid": "C37",
+        "order_date": "2020-08-30",
+        "items": [
+            {
+                "itemno": 460,
+                "qty": 2,
+                "price": 29.99
+            },
+            {
+                "itemno": 347,
+                "qty": 120,
+                "price": 22.00
+            },
+            {
+                "itemno": 780,
+                "qty": 1,
+                "price": 1500.00
+            },
+            {
+                "itemno": 375,
+                "qty": 2,
+                "price": 149.98
+            }
+        ]
+    },
+    {
+        "orderno": 1006,
+        "custid": "C41",
+        "order_date": "2020-09-02",
+        "ship_date": "2020-09-04",
+        "items": [
+            {
+                "itemno": 680,
+                "qty": 51,
+                "price": 25.98
+            },
+            {
+                "itemno": 120,
+                "qty": 65,
+                "price": 85.00
+            },
+            {
+                "itemno": 460,
+                "qty": 120,
+                "price": 29.98
+            }
+        ]
+    },
+    {
+        "orderno": 1007,
+        "custid": "C13",
+        "order_date": "2020-09-13",
+        "ship_date": "2020-09-20",
+        "items": [
+            {
+                "itemno": 185,
+                "qty": 5,
+                "price": 21.99
+            },
+            {
+                "itemno": 680,
+                "qty": 1,
+                "price": 20.50
+            }
+        ]
+    },
+    {
+        "orderno": 1008,
+        "custid": "C13",
+        "order_date": "2020-10-13",
+        "items": [
+            {
+                "itemno": 460,
+                "qty": 20,
+                "price": 29.99
+            }
+        ]
+    },
+    {
+        "orderno": 1009,
+        "custid": "C13",
+        "order_date": "2020-10-13",
+        "items": []
+    }
+]);
+
+INSERT INTO inventory.products
+([
+  {
+    "itemno": 120,
+    "category": ["computer"],
+    "name": "16TB External SDD",
+    "descrip": "16TB storage add-on for Pacbook laptops",
+    "manuf": "El Cheapo",
+    "listprice": 99.00,
+    "kind": "electric",
+    "power": "USB"
+  },
+  {
+    "itemno": 185,
+    "category": ["office", "essentials"],
+    "name": "Stapler",
+    "descrip": "Manual stapler for up to 25 sheets of paper",
+    "manuf": "Office Min",
+    "listprice": 21.99
+  },
+  {
+    "itemno": 193,
+    "category": ["office"],
+    "name": "Super Stapler",
+    "descrip": "Electric stapler for up to 250 sheets of paper",
+    "manuf": "Office Min",
+    "listprice": 28.89,
+    "kind": "electric",
+    "power": "115V"
+  },
+  {
+    "itemno": 195,
+    "category": ["computer", "office"],
+    "name": "Computer Stand",
+    "manuf": "ISeeYa",
+    "listprice": 49.00
+  },
+  {
+    "itemno": 347,
+    "category": ["essentials"],
+    "name": "Beer Cooler Backpack",
+    "manuf": "Robo Brew",
+    "listprice": 25.95,
+    "kind": "electric",
+    "power": "D batteries"
+  },
+  {
+    "itemno": 375,
+    "category": ["music"],
+    "name": "Stratuscaster Guitar",
+    "manuf": "Fender Bender",
+    "listprice": 149.99
+  },
+  {
+    "itemno": 460,
+    "category": ["music", "clothing"],
+    "name": "Fender Bender T-Shirt",
+    "descrip": "Extra Large T-Shirt for Fender Bender fans",
+    "manuf": "Fender Bender",
+    "listprice": 34.99,
+    "kind": "clothing",
+    "size": "XL"
+  },
+  {
+    "itemno": 680,
+    "category": ["music", "clothing"],
+    "name": "Fender Bender Tank Top",
+    "descrip": "Medium Tank Top for Fender Bender fans",
+    "manuf": "Fender Bender",
+    "listprice": 29.99,
+    "kind": "clothing",
+    "size": "M"
+  },
+  {
+    "itemno": 780,
+    "category": ["essentials", "kitchen"],
+    "name": "Automatic Beer Opener",
+    "descrip": "Robotic beer bottle opener",
+    "manuf": "Robo Brew",
+    "listprice": 29.95,
+    "kind": "electric",
+    "power": "AA batteries"
+  }
+]);
+
+INSERT INTO marketing.reviews
+([
+  {
+    "itemno": 193,
+    "name": "Super Stapler",
+    "rating": 5,
+    "comment": "This electric stapler is the bomb",
+    "custid": "C41",
+    "rev_date": "2020-05-13"
+  },
+  {
+    "itemno": 347,
+    "name": "Beer Cooler Backpack",
+    "rating": 5,
+    "comment": "Every camper needs one of these for sure",
+    "custid": "C41",
+    "rev_date": "2020-05-13"
+  },
+  {
+    "itemno": 375,
+    "name": "Stratuscaster Guitar",
+    "rating": 4,
+    "comment": "Anxiously awaiting its arrival!",
+    "custid": "C37",
+    "rev_date": "2020-09-07"
+  },
+  {
+    "itemno": 460,
+    "name": "Fender Bender T-Shirt",
+    "rating": 2,
+    "comment": "Had to return it 'cause it shrunk when washed",
+    "custid": "C13",
+    "rev_date": "2020-10-20"
+  },
+  {
+    "itemno": 460,
+    "name": "Fender Bender T-Shirt",
+    "rating": 2,
+    "comment": "Order one size up, it shrinks when you wash it",
+    "custid": "C41",
+    "rev_date": "2020-09-11"
+  },
+  {
+    "itemno": 680,
+    "name": "Fender Bender Tank Top",
+    "rating": 3,
+    "comment": "Like it, but had to reorder in a bigger size",
+    "custid": "C35",
+    "rev_date": "2020-07-25"
+  },
+  {
+    "itemno": 680,
+    "name": "Fender Bender Tank Top",
+    "rating": 2,
+    "comment": "Size seems to be smaller than expected",
+    "custid": "C13",
+    "rev_date": "2020-05-04"
+  },
+  {
+    "itemno": 780,
+    "name": "Automatic Beer Opener",
+    "rating": 1,
+    "comment": "Still waiting for mine to actually arrive...",
+    "custid": "C37",
+    "rev_date": "2020-09-30"
+  }
+]);
+
+INSERT INTO marketing.inventory(
+{
+ "id": "1",
+ "bought": [{ "qty": 2 }, { "qty": 100 }],
+ "sold": [{"lqty": 10}, {"lqty": 40}]
+}
+);
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.003.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.003.query.sqlpp
new file mode 100644
index 0000000..1056e64
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.003.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+SELECT o.orderno, o.order_date, i.itemno AS item_number, i.qty AS quantity
+FROM websales.orders AS o, o.items AS i
+WHERE
+(SOME li IN o.items SATISFIES li.qty < 3)
+  AND i.qty >= 100
+ORDER BY o.orderno, item_number;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.004.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.004.query.sqlpp
new file mode 100644
index 0000000..40219e6
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.004.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+SELECT o.id, o.sold, i.qty
+FROM marketing.inventory AS o, o.bought AS i, o.sold AS s
+WHERE
+i.qty < 3
+AND s.lqty > 19;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.005.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.005.query.sqlpp
new file mode 100644
index 0000000..a574d2d
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582-2.005.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+EXPLAIN
+SELECT o.id, o.sold, i.qty
+FROM marketing.inventory AS o, o.bought AS i, o.sold AS s
+WHERE
+i.qty < 3
+AND s.lqty > 19;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.003.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.003.adm
new file mode 100644
index 0000000..9fd5328
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.003.adm
@@ -0,0 +1 @@
+{ "orderno": 1005, "order_date": "2020-08-30", "item_number": 347, "quantity": 
120 }
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.004.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.004.adm
new file mode 100644
index 0000000..1fb4f83
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.004.adm
@@ -0,0 +1 @@
+{ "id": "1", "sold": [ { "lqty": 10 }, { "lqty": 40 } ], "qty": 2 }
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.005.plan
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.005.plan
new file mode 100644
index 0000000..679132b
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/ASTERIXDB-3582-2/ASTERIXDB-3582.005.plan
@@ -0,0 +1,26 @@
+distribute result [$$46] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    assign [$$46] <- [{"id": $$48, "sold": $$50, "qty": $$47}] project: [$$46] 
[cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+    -- ASSIGN  |PARTITIONED|
+      select (gt($$s.getField("lqty"), 19)) project: [$$48, $$50, $$47] 
[cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+      -- STREAM_SELECT  |PARTITIONED|
+        unnest $$s <- scan-collection($$50) [cardinality: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+        -- UNNEST  |PARTITIONED|
+          select (lt($$47, 3)) [cardinality: 0.0, op-cost: 0.0, total-cost: 
0.0]
+          -- STREAM_SELECT  |PARTITIONED|
+            assign [$$47] <- [$$i.getField("qty")] project: [$$48, $$50, $$47] 
[cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+            -- ASSIGN  |PARTITIONED|
+              unnest $$i <- scan-collection($$49) project: [$$48, $$50, $$i] 
[cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+              -- UNNEST  |PARTITIONED|
+                assign [$$50, $$49] <- [$$o.getField("sold"), 
$$o.getField("bought")] project: [$$48, $$50, $$49] [cardinality: 0.0, op-cost: 
0.0, total-cost: 0.0]
+                -- ASSIGN  |PARTITIONED|
+                  exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    data-scan []<-[$$48, $$o] <- marketing.inventory project 
({sold:any,bought:[{qty:any}]}) filter on: 
gt(scan-collection($$o.getField("sold")).getField("lqty"), 19) range-filter on: 
gt(scan-collection($$o.getField("sold")).getField("lqty"), 19) [cardinality: 
0.0, op-cost: 0.0, total-cost: 0.0]
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 
0.0]
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source [cardinality: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19529
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: I4f335db4c7c455c1276ea5be9b14ce1e8ee92d74
Gerrit-Change-Number: 19529
Gerrit-PatchSet: 1
Gerrit-Owner: Ritik Raj <[email protected]>
Gerrit-MessageType: newchange

Reply via email to