Fix for issue832
The rewrite rule was previously assuming that the first argument to the function is the one that we are searching the index on. This is not nessassarily the case
I changed it to search for the appropriate argument
Change-Id: I68ab853cc74e930605a9a7037be1036f052236b8
Reviewed-on: http://fulliautomatix.ics.uci.edu:8443/195
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Young-Seok Kim <kisskys@gmail.com>
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/OptimizableFuncExpr.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/OptimizableFuncExpr.java
index 179ab83..0d8351c 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/OptimizableFuncExpr.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/OptimizableFuncExpr.java
@@ -95,6 +95,10 @@
return fieldNames[index];
}
+ public String[] getFieldNames() {
+ return fieldNames;
+ }
+
@Override
public IAlgebricksConstantValue getConstantVal(int index) {
return constantVals[index];
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeAccessMethod.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeAccessMethod.java
index 66d06f6..1eb1f2f 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeAccessMethod.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeAccessMethod.java
@@ -14,6 +14,7 @@
*/
package edu.uci.ics.asterix.optimizer.rules.am;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -167,8 +168,23 @@
Dataset dataset = indexSubTree.dataset;
ARecordType recordType = indexSubTree.recordType;
+ Pair<IAType, Boolean> keyPairType = null;
+ //Get the type of the field from the optFuncExpr
+ for (String fieldName : ((OptimizableFuncExpr) optFuncExpr).getFieldNames()) {
+ try {
+ if (fieldName != null && recordType.getFieldType(fieldName) != null) {
+ keyPairType = Index.getNonNullableKeyFieldType(fieldName, recordType);
+ break;
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ if (keyPairType == null) {
+ return null;
+ }
+
// Get the number of dimensions corresponding to the field indexed by chosenIndex.
- Pair<IAType, Boolean> keyPairType = Index.getNonNullableKeyFieldType(optFuncExpr.getFieldName(0), recordType);
IAType spatialType = keyPairType.first;
int numDimensions = NonTaggedFormatUtil.getNumDimensions(spatialType.getTypeTag());
int numSecondaryKeys = numDimensions * 2;