예제 #1
0
  /**
   * Flatten this FSqry into the outer query block. The steps in flattening are: o Mark all
   * ResultColumns as redundant, so that they are "skipped over" at generate(). o Append the
   * wherePredicates to the outer list. o Return the fromList so that the caller will merge the 2
   * lists RESOLVE - FSqrys with subqueries are currently not flattenable. Some of them can be
   * flattened, however. We need to merge the subquery list when we relax this restriction.
   *
   * <p>NOTE: This method returns NULL when flattening RowResultSetNodes (the node for a VALUES
   * clause). The reason is that no reference is left to the RowResultSetNode after flattening is
   * done - the expressions point directly to the ValueNodes in the RowResultSetNode's
   * ResultColumnList.
   *
   * @param rcl The RCL from the outer query
   * @param outerPList PredicateList to append wherePredicates to.
   * @param sql The SubqueryList from the outer query
   * @param gbl The group by list, if any
   * @param havingClause The HAVING clause, if any
   * @return FromList The fromList from the underlying SelectNode.
   * @exception StandardException Thrown on error
   */
  public FromList flatten(
      ResultColumnList rcl,
      PredicateList outerPList,
      SubqueryList sql,
      GroupByList gbl,
      ValueNode havingClause)
      throws StandardException {
    FromList fromList = null;
    SelectNode selectNode;

    resultColumns.setRedundant();

    subquery.getResultColumns().setRedundant();

    /*
     ** RESOLVE: Each type of result set should know how to remap itself.
     */
    if (subquery instanceof SelectNode) {
      selectNode = (SelectNode) subquery;
      fromList = selectNode.getFromList();

      // selectNode.getResultColumns().setRedundant();

      if (selectNode.getWherePredicates().size() > 0) {
        outerPList.destructiveAppend(selectNode.getWherePredicates());
      }

      if (selectNode.getWhereSubquerys().size() > 0) {
        sql.destructiveAppend(selectNode.getWhereSubquerys());
      }
    } else if (!(subquery instanceof RowResultSetNode)) {
      if (SanityManager.DEBUG) {
        SanityManager.THROWASSERT(
            "subquery expected to be either a SelectNode or a RowResultSetNode, but is a "
                + subquery.getClass().getName());
      }
    }

    /* Remap all ColumnReferences from the outer query to this node.
     * (We replace those ColumnReferences with clones of the matching
     * expression in the SELECT's RCL.
     */
    rcl.remapColumnReferencesToExpressions();
    outerPList.remapColumnReferencesToExpressions();
    if (gbl != null) {
      gbl.remapColumnReferencesToExpressions();
    }

    if (havingClause != null) {
      havingClause.remapColumnReferencesToExpressions();
    }

    return fromList;
  }
예제 #2
0
  /**
   * Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed
   * to work.
   *
   * @param depth The depth of this node in the tree
   */
  public void printSubNodes(int depth) {
    super.printSubNodes(depth);

    if (methodCall != null) {
      printLabel(depth, "methodCall: ");
      methodCall.treePrint(depth + 1);
    }

    if (exposedName != null) {
      printLabel(depth, "exposedName: ");
      exposedName.treePrint(depth + 1);
    }

    if (subqueryList != null) {
      printLabel(depth, "subqueryList: ");
      subqueryList.treePrint(depth + 1);
    }
  }