public Expr visitBody()

in tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java [76:170]


  public Expr visitBody(HiveQLParser.BodyContext ctx) {

    Expr current = null;
    Insert insert = null;

    Projection select = null;

    if (ctx.insertClause() != null) {
      insert = visitInsertClause(ctx.insertClause());
    }

    if (ctx.selectClause() != null) {
      select = (Projection) visitSelectClause(ctx.selectClause());
      if (ctx.selectClause().KW_DISTINCT() != null) {
        select.setDistinct();
      }

    }

    for (int i = 0; i < ctx.getParent().getChildCount(); i++) {
      if (ctx.getParent().getChild(i) instanceof HiveQLParser.FromClauseContext) {
        HiveQLParser.FromClauseContext fromClauseContext = (HiveQLParser.FromClauseContext) ctx.getParent().getChild(i);
        Expr from = visitFromClause(fromClauseContext);
        current = from;
      }
    }

    if (ctx.whereClause() != null) {
      Selection where = new Selection(visitWhereClause(ctx.whereClause()));
      where.setChild(current);
      current = where;
    }

    if (ctx.groupByClause() != null) {
      Aggregation aggregation = visitGroupByClause(ctx.groupByClause());
      aggregation.setChild(current);
      current = aggregation;

      if (ctx.havingClause() != null) {
        Expr havingCondition = visitHavingClause(ctx.havingClause());
        Having having = new Having(havingCondition);
        having.setChild(current);
        current = having;
      }
    }

    if (ctx.orderByClause() != null) {
      Sort sort = visitOrderByClause(ctx.orderByClause());
      sort.setChild(current);
      current = sort;
    }

    if (ctx.clusterByClause() != null) {
      visitClusterByClause(ctx.clusterByClause());
    }

    if (ctx.distributeByClause() != null) {
      visitDistributeByClause(ctx.distributeByClause());
    }

    if (ctx.sortByClause() != null) {
      Sort sort = visitSortByClause(ctx.sortByClause());
      sort.setChild(current);
      current = sort;
    }

    if (ctx.window_clause() != null) {
      Expr window = visitWindow_clause(ctx.window_clause());
    }

    if (ctx.limitClause() != null) {
      Limit limit = visitLimitClause(ctx.limitClause());
      limit.setChild(current);
      current = limit;
    }

    Projection projection = new Projection();
    projection.setNamedExprs(select.getNamedExprs());

    if (current != null)
      projection.setChild(current);

    if (select.isDistinct())
      projection.setDistinct();


    if (insert != null) {
      insert.setSubQuery(projection);
      current = insert;
    } else {
      current = projection;
    }

    return current;
  }