Пример #1
0
  public static List<Datum[]> execQuery(Map<String, Schema.TableFromFile> tables, PlanNode q)
      throws SqlException {

    switch (q.struct) {
      case LEAF:
        switch (q.type) {
          case SCAN:
            ScanNode node = (ScanNode) q;
            ScanOperator sop = new ScanOperator(node);
            return sop.getTuples(tables);
            // break;
          case NULLSOURCE:
            NullSourceNode nNode = (NullSourceNode) q;
            return new ArrayList<Datum[]>();
            // break;
        }
        break;
      case UNARY:
        switch (q.type) {
          case AGGREGATE:
            AggregateNode aggrNode = (AggregateNode) q;
            List<Datum[]> aggrResult = execQuery(tables, aggrNode.getChild());
            AggregateOperator aop = new AggregateOperator(aggrNode, aggrResult);
            return aop.getTuples();
            // break;
          case SELECT:
            SelectionNode selectNode = (SelectionNode) q;
            List<Datum[]> selectResult = execQuery(tables, selectNode.getChild());
            SelectOperation slop = new SelectOperation(selectNode);
            return slop.getTuples(selectResult, selectNode.getCondition());
            // break;
          case PROJECT:
            ProjectionNode projNode = (ProjectionNode) q;
            List<Datum[]> projResult = execQuery(tables, projNode.getChild());
            ProjectOperation prop = new ProjectOperation(projNode);
            ExprTree e = null;
            return prop.getTuples(projResult, e);
            // break;
        }
        break;
      case BINARY:
        switch (q.type) {
          case JOIN:
            JoinNode joinNode = (JoinNode) q;
            JoinOperator jop = new JoinOperator(joinNode);
            List<Datum[]> lResult = execQuery(tables, joinNode.getLHS());
            List<Datum[]> rResult = execQuery(tables, joinNode.getRHS());
            return jop.getTuples(lResult, rResult);
            // break;
          case UNION:
            UnionNode unionNode = (UnionNode) q;
            UnionOperator uop = new UnionOperator(unionNode);
            List<Datum[]> lUResult = execQuery(tables, unionNode.getLHS());
            List<Datum[]> rUResult = execQuery(tables, unionNode.getRHS());
            return uop.getTuples(lUResult, rUResult);
            // break;
          default:
            break;
        }
    }
    throw new SqlException("execQuery() is unimplemented");
  }