@Override
  public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
      throws AlgebricksException {

    ILogicalOperator lo = opRef.getValue();
    if (!(lo.getOperatorTag().equals(LogicalOperatorTag.UNNEST))) {
      return false;
    }
    AbstractUnnestOperator auo = (AbstractUnnestOperator) lo;
    Mutable<ILogicalExpression> childExpression =
        ExpressionToolbox.findFirstFunctionExpression(
            auo.getExpressionRef(), BuiltinOperators.CHILD.getFunctionIdentifier());
    if (childExpression == null) {
      return false;
    }
    AbstractFunctionCallExpression childFnCall =
        (AbstractFunctionCallExpression) childExpression.getValue();
    List<Mutable<ILogicalExpression>> list =
        (List<Mutable<ILogicalExpression>>) childFnCall.getArguments();
    Mutable<ILogicalExpression> mle = (Mutable<ILogicalExpression>) (list).get(0);
    ILogicalExpression le = mle.getValue();
    if (!(le.getExpressionTag().equals(LogicalExpressionTag.VARIABLE))) {
      return false;
    }
    VariableReferenceExpression varLogicalExpression = (VariableReferenceExpression) le;
    Mutable<ILogicalOperator> lop =
        OperatorToolbox.findProducerOf(opRef, varLogicalExpression.getVariableReference());
    ILogicalOperator lop1 = lop.getValue();
    if (!(lop1.getOperatorTag().equals(LogicalOperatorTag.UNNEST))) {
      return false;
    }
    if (OperatorToolbox.getExpressionOf(lop, varLogicalExpression.getVariableReference()) == null) {
      return false;
    }
    ILogicalExpression variableLogicalExpression =
        (ILogicalExpression)
            OperatorToolbox.getExpressionOf(lop, varLogicalExpression.getVariableReference())
                .getValue();
    if (!(variableLogicalExpression
        .getExpressionTag()
        .equals(LogicalExpressionTag.FUNCTION_CALL))) {
      return false;
    }
    AbstractFunctionCallExpression afce =
        (AbstractFunctionCallExpression) variableLogicalExpression;
    if (!(afce.getFunctionIdentifier()
        .equals(BuiltinOperators.DESCENDANT_OR_SELF.getFunctionIdentifier()))) {
      return false;
    }
    // All conditions have been met.
    childFnCall.setFunctionInfo(BuiltinOperators.DESCENDANT_OR_SELF);
    childFnCall.getArguments().get(0).setValue(afce.getArguments().get(0).getValue());
    ILogicalOperator lo1 = opRef.getValue();
    Mutable<ILogicalOperator> mlistOfLo = lo1.getInputs().get(0).getValue().getInputs().get(0);
    ILogicalOperator ilo = (ILogicalOperator) mlistOfLo.getValue();
    lo.getInputs().get(0).setValue((ILogicalOperator) ilo);
    return true;
  }
 @Override
 public String visitVariableReferenceExpression(VariableReferenceExpression expr, Integer indent)
     throws AlgebricksException {
   return expr.toString();
 }