>From Shahrzad Shirazi <[email protected]>:

Shahrzad Shirazi has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20411?usp=email )


Change subject: [NO ISSUE][COMP] Correct delivered properties of secondary 
index search operator Ext-ref: MB-55766
......................................................................

[NO ISSUE][COMP] Correct delivered properties of secondary index search operator
Ext-ref: MB-55766

Change-Id: I2812c034a6d002bf906a0dff7a26aa7402707a3f
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/IndexSearchPOperator.java
1 file changed, 35 insertions(+), 6 deletions(-)



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

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/IndexSearchPOperator.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/IndexSearchPOperator.java
index f522d93..9f622ae 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/IndexSearchPOperator.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/IndexSearchPOperator.java
@@ -18,14 +18,20 @@
  */
 package org.apache.asterix.algebra.operators.physical;

+import java.util.ArrayList;
 import java.util.List;

 import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.metadata.declared.DataSourceId;
+import org.apache.asterix.metadata.declared.DataSourceIndex;
+import org.apache.asterix.metadata.declared.DatasetDataSource;
+import org.apache.asterix.metadata.entities.Dataset;
+import org.apache.asterix.metadata.entities.Index;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
 import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
 import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
 import 
org.apache.hyracks.algebricks.core.algebra.expressions.IAlgebricksConstantValue;
 import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
@@ -33,6 +39,7 @@
 import 
org.apache.hyracks.algebricks.core.algebra.metadata.IDataSourcePropertiesProvider;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractScanOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.IOperatorSchema;
+import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.physical.AbstractScanPOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.properties.BroadcastPartitioningProperty;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;
@@ -54,7 +61,7 @@
     protected final INodeDomain domain;

     public IndexSearchPOperator(IDataSourceIndex<String, DataSourceId> idx, 
INodeDomain domain,
-            boolean requiresBroadcast) {
+                                boolean requiresBroadcast) {
         this.idx = idx;
         this.requiresBroadcast = requiresBroadcast;
         this.domain = domain;
@@ -69,9 +76,31 @@
     public void computeDeliveredProperties(ILogicalOperator op, 
IOptimizationContext context)
             throws AlgebricksException {
         IDataSource<?> ds = idx.getDataSource();
+        List<LogicalVariable> scanVariables = new ArrayList<>();
+        if (idx instanceof DataSourceIndex) {
+            Index index = ((DataSourceIndex) idx).getIndex();
+            if (index.isSecondaryIndex() && ds instanceof DatasetDataSource) {
+                Dataset dataset = ((DatasetDataSource) ds).getDataset();
+                int numOfPrimaryKeys = dataset.getPrimaryKeys().size();
+                if (op.getOperatorTag() == LogicalOperatorTag.UNNEST_MAP) {
+                    // Getting the primary keys vars from the Unnest Map,
+                    // Primary key Vars are always located at the end of the 
unnest variables list.
+                    // This check is unnecessary as the operator will always 
be an
+                    // UnnestMapOperator in secondary index search cases.
+                    List<LogicalVariable> opVars = ((UnnestMapOperator) 
op).getVariables();
+                    int varsSize = opVars.size();
+                    scanVariables.addAll(opVars.subList(varsSize - 
numOfPrimaryKeys, varsSize));
+                    scanVariables.add(new LogicalVariable(-1));
+                }
+            }
+        }
+        if (scanVariables.isEmpty()) {
+            AbstractScanOperator as = (AbstractScanOperator) op;
+            scanVariables.addAll(as.getScanVariables());
+        }
+
         IDataSourcePropertiesProvider dspp = ds.getPropertiesProvider();
-        AbstractScanOperator as = (AbstractScanOperator) op;
-        deliveredProperties = 
dspp.computeDeliveredProperties(as.getScanVariables(), context);
+        deliveredProperties = dspp.computeDeliveredProperties(scanVariables, 
context);
     }

     protected int[] getKeyIndexes(List<LogicalVariable> keyVarList, 
IOperatorSchema[] inputSchemas) {
@@ -87,7 +116,7 @@

     @Override
     public PhysicalRequirements 
getRequiredPropertiesForChildren(ILogicalOperator op,
-            IPhysicalPropertiesVector reqdByParent, IOptimizationContext 
context) throws AlgebricksException {
+                                                                 
IPhysicalPropertiesVector reqdByParent, IOptimizationContext context) throws 
AlgebricksException {
         if (requiresBroadcast) {
             StructuralPropertiesVector[] pv = new 
StructuralPropertiesVector[1];
             pv[0] = new StructuralPropertiesVector(new 
BroadcastPartitioningProperty(domain), null);
@@ -112,7 +141,7 @@
     }

     protected static IMissingWriterFactory 
getNonMatchWriterFactory(IAlgebricksConstantValue missingValue,
-            JobGenContext context, SourceLocation sourceLoc) throws 
CompilationException {
+                                                                    
JobGenContext context, SourceLocation sourceLoc) throws CompilationException {
         IMissingWriterFactory nonMatchWriterFactory;
         if (missingValue.isMissing()) {
             nonMatchWriterFactory = context.getMissingWriterFactory();
@@ -127,4 +156,4 @@
     protected static IMissingWriterFactory getNonFilterWriterFactory(boolean 
propagateFilter, JobGenContext context) {
         return propagateFilter ? context.getMissingWriterFactory() : null;
     }
-}
+}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I2812c034a6d002bf906a0dff7a26aa7402707a3f
Gerrit-Change-Number: 20411
Gerrit-PatchSet: 1
Gerrit-Owner: Shahrzad Shirazi <[email protected]>

Reply via email to