001package gudusoft.gsqlparser.ir.logical;
002
003import gudusoft.gsqlparser.ir.common.SourceAnchor;
004
005import java.util.ArrayList;
006import java.util.Collections;
007import java.util.List;
008
009/**
010 * Aggregation root for the Logical IR phase output.
011 * <p>
012 * Contains normalized relational plans (RelNode trees) extracted from
013 * DML statements in BoundProgram routines.
014 */
015public class LogicalProgram {
016
017    private final List<StatementPlan> plans;
018
019    public LogicalProgram() {
020        this.plans = new ArrayList<StatementPlan>();
021    }
022
023    public List<StatementPlan> getPlans() {
024        return Collections.unmodifiableList(plans);
025    }
026
027    public void addPlan(StatementPlan plan) {
028        plans.add(plan);
029    }
030
031    @Override
032    public String toString() {
033        return "LogicalProgram{plans=" + plans.size() + "}";
034    }
035
036    /**
037     * A single DML statement translated to a relational plan.
038     */
039    public static final class StatementPlan {
040        private final String owningRoutineId;
041        private final int statementIndex;
042        private final RelNode root;
043        private final SourceAnchor anchor;
044
045        public StatementPlan(String owningRoutineId, int statementIndex,
046                             RelNode root, SourceAnchor anchor) {
047            this.owningRoutineId = owningRoutineId;
048            this.statementIndex = statementIndex;
049            this.root = root;
050            this.anchor = anchor;
051        }
052
053        public String getOwningRoutineId() { return owningRoutineId; }
054        public int getStatementIndex() { return statementIndex; }
055        public RelNode getRoot() { return root; }
056        public SourceAnchor getAnchor() { return anchor; }
057    }
058}