public SqlNode visit(SqlNodeList list) {
   SqlNodeList copy = new SqlNodeList(list.getParserPosition());
   for (SqlNode node : list) {
     copy.add(node.accept(this));
   }
   return copy;
 }
Exemple #2
0
 public boolean equalsDeep(SqlNode node, boolean fail) {
   if (!(node instanceof SqlNodeList)) {
     assert !fail : this + "!=" + node;
     return false;
   }
   SqlNodeList that = (SqlNodeList) node;
   if (this.size() != that.size()) {
     assert !fail : this + "!=" + node;
     return false;
   }
   for (int i = 0; i < list.size(); i++) {
     SqlNode thisChild = list.get(i);
     final SqlNode thatChild = that.list.get(i);
     if (!thisChild.equalsDeep(thatChild, fail)) {
       return false;
     }
   }
   return true;
 }
Exemple #3
0
 /**
  * Once you have a Result of implementing a child relational expression, call this method to
  * create a Builder to implement the current relational expression by adding additional clauses
  * to the SQL query.
  *
  * <p>You need to declare which clauses you intend to add. If the clauses are "later", you can
  * add to the same query. For example, "GROUP BY" comes after "WHERE". But if they are the same
  * or earlier, this method will start a new SELECT that wraps the previous result.
  *
  * <p>When you have called {@link Builder#setSelect(org.eigenbase.sql.SqlNodeList)}, {@link
  * Builder#setWhere(org.eigenbase.sql.SqlNode)} etc. call {@link
  * Builder#result(org.eigenbase.sql.SqlNode, java.util.Collection, org.eigenbase.rel.RelNode)}
  * to fix the new query.
  *
  * @param rel Relational expression being implemented
  * @param clauses Clauses that will be generated to implement current relational expression
  * @return A builder
  */
 public Builder builder(JdbcRel rel, Clause... clauses) {
   final Clause maxClause = maxClause();
   boolean needNew = false;
   for (Clause clause : clauses) {
     if (maxClause.ordinal() >= clause.ordinal()) {
       needNew = true;
     }
   }
   SqlSelect select;
   Expressions.FluentList<Clause> clauseList = Expressions.list();
   if (needNew) {
     select = subSelect();
   } else {
     select = asSelect();
     clauseList.addAll(this.clauses);
   }
   clauseList.addAll(Arrays.asList(clauses));
   Context newContext;
   final SqlNodeList selectList = select.getSelectList();
   if (selectList != null) {
     newContext =
         new Context(selectList.size()) {
           @Override
           public SqlNode field(int ordinal) {
             final SqlNode selectItem = selectList.get(ordinal);
             switch (selectItem.getKind()) {
               case AS:
                 return ((SqlCall) selectItem).operand(0);
             }
             return selectItem;
           }
         };
   } else {
     newContext = new AliasContext(aliases, aliases.size() > 1);
   }
   return new Builder(rel, clauseList, select, newContext);
 }