@Override
  public RexNode visitCall(RexCall call) {
    // Record if we see not flag before seeing the subquery.
    // Can handle NOT(NOT(...)) if  it exists
    if (call.getOperator().getKind() == SqlKind.NOT) {
      notFlag = !notFlag;
    }
    RexNode returnNode = super.visitCall(call);
    // reset flag after visit.
    if (call.getOperator().getKind() == SqlKind.NOT) {
      notFlag = !notFlag;
    }
    return returnNode;
  }
CorrelationIdVisitor digs out information from a given RexNode about all the RexSubQuery
RexNodes in the top layer. It does not go into RexSubQuery nodes within a RexSubQuery node.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/correlation/CorrelationInfoVisitor.java