addressed code review comments
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
index 1023c6d..3efbcc8 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
@@ -286,6 +286,10 @@
                         if (funcVarIndex == -1) {
                             continue;
                         }
+                        // We only look for index on the first variable of the function, because edit-distance-contains() arguments are asymmetric
+                        if (funcVarIndex > 0 && optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS) {
+                            continue;
+                        }
                         // At this point we have matched the optimizable func expr at optFuncExprIndex to an assigned variable.
                         // Remember matching subtree.
                         optFuncExpr.setOptimizableSubTree(funcVarIndex, subTree);
@@ -306,6 +310,10 @@
                     if (funcVarIndex == -1) {
                         continue;
                     }
+                    // We only look for index on the first variable of the function, because edit-distance-contains() arguments are asymmetric
+                    if (funcVarIndex > 0 && optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS) {
+                        continue;
+                    }
                     // At this point we have matched the optimizable func expr at optFuncExprIndex to an unnest variable.
                     // Remember matching subtree.
                     optFuncExpr.setOptimizableSubTree(funcVarIndex, subTree);
@@ -328,6 +336,10 @@
                 if (funcVarIndex == -1) {
                     continue;
                 }
+                // We only look for index on the first variable of the function, because edit-distance-contains() arguments are asymmetric
+                if (funcVarIndex > 0 && optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS) {
+                    continue;
+                }
                 // The variable value is one of the partitioning fields.
                 String fieldName = DatasetUtils.getPartitioningKeys(subTree.dataset).get(varIndex);
                 // Set the fieldName in the corresponding matched function expression, and remember matching subtree.
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
index fce97f4..640e0b6 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
@@ -415,14 +415,10 @@
         // Determine probe and index subtrees based on chosen index.
         OptimizableOperatorSubTree indexSubTree = null;
         OptimizableOperatorSubTree probeSubTree = null;
-        if (dataset.getDatasetName().equals(leftSubTree.dataset.getDatasetName())) {
+        if (leftSubTree.dataset != null && dataset.getDatasetName().equals(leftSubTree.dataset.getDatasetName())) {
             indexSubTree = leftSubTree;
             probeSubTree = rightSubTree;
-        } else if (dataset.getDatasetName().equals(rightSubTree.dataset.getDatasetName())) {
-            // The arguments of edit-distance-contains() function are asymmetrical, we can only use index if it is on the left side
-            if (optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS) {
-                return false;
-            }
+        } else if (rightSubTree.dataset != null && dataset.getDatasetName().equals(rightSubTree.dataset.getDatasetName())) {
             indexSubTree = rightSubTree;
             probeSubTree = leftSubTree;
         }