stagesupport/src/main/java/com/streamsets/pipeline/lib/util/FieldPathExpressionUtil.java
private static boolean pathMatches(
      Record record,
      String fieldPath,
      String fieldExpression,
      ELEval elEval,
      ELVars elVars
  ) throws ELEvalException {
    List<PathElement> actualPathElements = PathElement.parse(fieldPath, true);
    List<PathElement> matcherPathElements = PathElement.parse(fieldExpression, false, true);

    Iterator<PathElement> currentPathIter = actualPathElements.iterator();
    Iterator<PathElement> matcherPathIter = matcherPathElements.iterator();

    PathElement currentMatcher = null;
    PathElement currentPath = null;
    Field currentField = null;
    StringBuilder currentFieldPath = new StringBuilder();

    while (matcherPathIter.hasNext()) {
      currentMatcher = matcherPathIter.next();
      switch (currentMatcher.getType()) {
        case MAP:
          if (!currentPathIter.hasNext()) {
            // we are expecting to match a MAP, but there are no more elements in the path
            return false;
          }
          currentPath = currentPathIter.next();

          // see if the name matches the pattern
          String childName = currentPath.getName();

          String patternName = currentMatcher.getName();
          if (FieldRegexUtil.hasWildCards(patternName)) {
            patternName = FieldRegexUtil.transformFieldPathRegex(patternName);
          }
          if (childName.matches(patternName)) {
            currentField = currentField.getValueAsMap().get(childName);
            currentFieldPath.append("/");
            currentFieldPath.append(childName);
          } else {
            return false;
          }

          break;
        case LIST:
          // see if the index matches the pattern

          if (!currentPathIter.hasNext()) {
            // we are expecting to match a LIST, but there are no more elements in the path
            return false;
          }
          currentPath = currentPathIter.next();

          int childIndex = currentPath.getIndex();
          final int matchInd = currentMatcher.getIndex();
          if (matchInd == PathElement.WILDCARD_INDEX_ANY_LENGTH
              || (matchInd == PathElement.WILDCARD_INDEX_SINGLE_CHAR && childIndex < 10)
              || matchInd == childIndex) {
            currentField = currentField.getValueAsList().get(childIndex);
            currentFieldPath.append("[");
            currentFieldPath.append(childIndex);
            currentFieldPath.append("]");
          } else {
            return false;
          }
          break;
        case ROOT:
          if (!currentPathIter.hasNext()) {
            // we are expecting to match the ROOT, but there are no more elements in the path
            return false;
          }
          currentPath = currentPathIter.next();
          if (currentPath.getType() != PathElement.Type.ROOT) {
            // we are expecting to match the ROOT, the root element wasn't for some reason
            return false;
          }
          currentField = record.get();
          break;
        case FIELD_EXPRESSION:
          // see if the current field matches the given expression
          FieldEL.setFieldInContext(elVars, currentFieldPath.toString(), currentPath.getName(), currentField);
          String expression = currentMatcher.getName();
          final boolean result = elEval.eval(elVars, expression, Boolean.class);
          if (LOG.isDebugEnabled()) {
            LOG.debug(
                "Result of evaluating expression {} on field {} with path {} was {}",
                expression,
                currentField,
                currentFieldPath,
                result
            );
          }
          if (!result) {
            return false;
          }
          break;
      }
    }

    return !currentPathIter.hasNext();
  }
private static boolean pathMatches(
      Record record,
      String fieldPath,
      String fieldExpression,
      ELEval elEval,
      ELVars elVars
  ) throws ELEvalException {
    List<PathElement> actualPathElements = PathElement.parse(fieldPath, true);
    List<PathElement> matcherPathElements = PathElement.parse(fieldExpression, false, true);

    Iterator<PathElement> currentPathIter = actualPathElements.iterator();
    Iterator<PathElement> matcherPathIter = matcherPathElements.iterator();

    PathElement currentMatcher = null;
    PathElement currentPath = null;
    Field currentField = null;
    StringBuilder currentFieldPath = new StringBuilder();

    while (matcherPathIter.hasNext()) {
      currentMatcher = matcherPathIter.next();
      switch (currentMatcher.getType()) {
        case MAP:
          if (!currentPathIter.hasNext()) {
            // we are expecting to match a MAP, but there are no more elements in the path
            return false;
          }
          currentPath = currentPathIter.next();

          // see if the name matches the pattern
          String childName = currentPath.getName();

          String patternName = currentMatcher.getName();
          if (FieldRegexUtil.hasWildCards(patternName)) {
            patternName = FieldRegexUtil.transformFieldPathRegex(patternName);
          }
          if (childName.matches(patternName)) {
            currentField = currentField.getValueAsMap().get(childName);
            currentFieldPath.append("/");
            currentFieldPath.append(childName);
          } else {
            return false;
          }

          break;
        case LIST:
          // see if the index matches the pattern

          if (!currentPathIter.hasNext()) {
            // we are expecting to match a LIST, but there are no more elements in the path
            return false;
          }
          currentPath = currentPathIter.next();

          int childIndex = currentPath.getIndex();
          final int matchInd = currentMatcher.getIndex();
          if (matchInd == PathElement.WILDCARD_INDEX_ANY_LENGTH
              || (matchInd == PathElement.WILDCARD_INDEX_SINGLE_CHAR && childIndex < 10)
              || matchInd == childIndex) {
            currentField = currentField.getValueAsList().get(childIndex);
            currentFieldPath.append("[");
            currentFieldPath.append(childIndex);
            currentFieldPath.append("]");
          } else {
            return false;
          }
          break;
        case ROOT:
          if (!currentPathIter.hasNext()) {
            // we are expecting to match the ROOT, but there are no more elements in the path
            return false;
          }
          currentPath = currentPathIter.next();
          if (currentPath.getType() != PathElement.Type.ROOT) {
            // we are expecting to match the ROOT, the root element wasn't for some reason
            return false;
          }
          currentField = record.get();
          break;
        case FIELD_EXPRESSION:
          // see if the current field matches the given expression
          FieldEL.setFieldInContext(elVars, currentFieldPath.toString(), currentPath.getName(), currentField);
          String expression = currentMatcher.getName();
          final boolean result = elEval.eval(elVars, expression, Boolean.class);
          if (LOG.isDebugEnabled()) {
            LOG.debug(
                "Result of evaluating expression {} on field {} with path {} was {}",
                expression,
                currentField,
                currentFieldPath,
                result
            );
          }
          if (!result) {
            return false;
          }
          break;
      }
    }

    return !currentPathIter.hasNext();
  }
Evaluates a field expression against a specific field in a record to see if it matches

@param record the record which contains the specified field
@param fieldPath the path to the specified field
@param fieldExpression the field expression to evaluate against the specified record/field
@param elEval the {@link ELEval} instance in which to evaluate the expression
@param elVars the {@link ELVars} instance to use when evaluating the expression
@return true if the expression matches the field, false otherwise
@throws ELEvalException if an error occurs during EL evaluation