private CompiledValue getReconstructedExpression(String projAttribStr, ExecutionContext context)
      throws TypeMismatchException, NameResolutionException {
    List<CompiledValue> expressions = PathUtils.collectCompiledValuesInThePath(expr, context);
    StringBuilder tempBuff = new StringBuilder();
    ListIterator<CompiledValue> listIter = expressions.listIterator(expressions.size());
    while (listIter.hasPrevious()) {
      listIter.previous().generateCanonicalizedExpression(tempBuff, context);
      if (tempBuff.toString().equals(projAttribStr)) {
        // we have found our match from where we have to replace the expression
        break;
      } else {
        tempBuff.delete(0, tempBuff.length());
      }
    }

    // Now we need to create a new CompiledValue which terminates with
    // ProjectionField
    CompiledValue cvToRetainTill = listIter.previous();

    CompiledValue prevCV = null;
    List<Object> reconstruct = new ArrayList<>();
    CompiledValue cv = expressions.get(0);
    int index = 0;
    do {
      prevCV = cv;

      switch (cv.getType()) {
        case OQLLexerTokenTypes.METHOD_INV:
          reconstruct.add(0, ((CompiledOperation) cv).getArguments());
          reconstruct.add(0, ((CompiledOperation) cv).getMethodName());
          break;
        case CompiledValue.PATH:
          reconstruct.add(0, ((CompiledPath) cv).getTailID());
          break;
        case OQLLexerTokenTypes.TOK_LBRACK:
          reconstruct.add(0, ((CompiledIndexOperation) cv).getExpression());
          break;
        default:
          throw new IllegalStateException("Unexpected CompiledValue in order by clause");
      }
      reconstruct.add(0, prevCV.getType());
      cv = expressions.get(++index);
    } while (prevCV != cvToRetainTill);

    // Now reconstruct back
    Iterator<Object> iter = reconstruct.iterator();
    CompiledValue currentValue = ProjectionField.getProjectionField();
    while (iter.hasNext()) {
      int type = (Integer) iter.next();
      switch (type) {
        case CompiledValue.PATH:
          currentValue = new CompiledPath(currentValue, (String) iter.next());
          break;
        case OQLLexerTokenTypes.METHOD_INV:
          currentValue =
              new CompiledOperation(currentValue, (String) iter.next(), (List) iter.next());
          break;
        case OQLLexerTokenTypes.TOK_LBRACK:
          currentValue = new CompiledIndexOperation(currentValue, (CompiledValue) iter.next());
          break;
      }

    }

    return currentValue;
  }
evaluates sort criteria in order by clause
geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledSortCriterion.java