public Expr visitRegular_body()

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


  public Expr visitRegular_body(HiveQLParser.Regular_bodyContext ctx) {
    Expr current = null;
    Insert insert = null;

    if (ctx.selectStatement() != null) {
      current = visitSelectStatement(ctx.selectStatement());
    } else {
      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();
        }

      }

      if (ctx.fromClause() != null) {
        Expr from = visitFromClause(ctx.fromClause());
        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;
  }