/**
 * Copyright (C) 2011 Akiban Technologies Inc.
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses.
 */

package com.akiban.sql.optimizer.plan;

import com.akiban.qp.operator.API.JoinType;

import java.util.ArrayList;
import java.util.List;

/** Take nested rows and join into single rowset. */
public class Flatten extends BasePlanWithInput
{
    private List<TableNode> tableNodes;
    private List<TableSource> tableSources;
    private List<JoinType> joinTypes;

    public Flatten(PlanNode input, 
                   List<TableNode> tableNodes, 
                   List<TableSource> tableSources, 
                   List<JoinType> joinTypes) {
        super(input);
        this.tableNodes = tableNodes;
        this.tableSources = tableSources;
        this.joinTypes = joinTypes;
    }

    public List<TableNode> getTableNodes() {
        return tableNodes;
    }

    public List<TableSource> getTableSources() {
        return tableSources;
    }

    public List<JoinType> getJoinTypes() {
        return joinTypes;
    }

    @Override
    public String summaryString() {
        StringBuilder str = new StringBuilder(super.summaryString());
        str.append("(");
        for (int i = 0; i < tableNodes.size(); i++) {
            if (i > 0) {
                str.append(" ");
                str.append(joinTypes.get(i-1));
                str.append(" ");
            }
            str.append(tableNodes.get(i).getTable());
        }
        str.append(")");
        return str.toString();
    }

    @Override
    protected void deepCopy(DuplicateMap map) {
        super.deepCopy(map);
        tableNodes = new ArrayList<TableNode>(tableNodes);
        tableSources = duplicateList(tableSources, map);
        joinTypes = new ArrayList<JoinType>(joinTypes);
    }

}

@@ -897,87 +897,366 @@
     
-private List%3CTableNode%3E tableNodes;%0A    private List%3CTableSource%3E tableSources;
+// Must sometimes flatten in tables that aren't known to the%0A    // query, but are used as branchpoints for products.%0A    // This is the complete list.%0A    private List%3CTableNode%3E tableNodes;%0A    // This parallel list has nulls for those unknown tables.%0A    private List%3CTableSource%3E tableSources;%0A    // This list is one shorter and joins between each pair.
 %0A   

Add a comment.