/* // $Id: //guest/julian_hyde/saffron/src/main/saffron/rel/Project.java#2 $ // Saffron preprocessor and data engine // Copyright (C) 2002 Julian Hyde <julian.hyde@mail.com> // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library 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 // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public // License along with this library; if not, write to the // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // See the COPYING file located in the top-level-directory of // the archive of this library for complete text of license. */ package saffron.rel; import openjava.mop.OJClass; import openjava.mop.Toolbox; import openjava.ptree.Expression; import openjava.ptree.util.SyntheticClass; import saffron.PlanWriter; import saffron.Planner; import saffron.opt.CallingConvention; import saffron.opt.Cluster; import saffron.opt.Cost; import saffron.rel.java.JavaProject; import saffron.rel.plan.PlanProject; import saffron.util.Util; /** * todo: **/ public class Project extends Rel { protected Rel child; protected Expression[] exps; protected String[] fieldNames; protected int flags; public static final int flagNone = 0; public static final int flagBoxed = 1; public static final int flagAnonFields = 2; /** * Creates a Project. * * @param cluster {@link Cluster} this relational expression belongs to * @param child input relational expression * @param exps set of expressions for the input columns * @param fieldNames aliases of the expressions * @param boxed whether the resulting row is to be a synthetic class * whose fields are the aliases of the * fields. <code>boxed</code> must be true unless there is * only one field: <code>select {dept.deptno} from * dept</code> is boxed, <code>select dept.deptno from * dept</code> is not. **/ public Project( Cluster cluster, Rel child, Expression[] exps, String[] fieldNames, int flags) { super(cluster); this.child = child; this.exps = exps; if (fieldNames == null) { fieldNames = new String[exps.length]; } Toolbox.assert(exps.length == fieldNames.length); this.fieldNames = fieldNames; this.flags = flags; if ((flags & flagBoxed) != flagBoxed) { Toolbox.assert(exps.length == 1); } } // Project(Cluster cluster, Rel child, Expression[] exps) // { // this(cluster, child, exps, new String[exps.length]); // for (int i = 0; i < exps.length; i++) { // fieldNames[i] = Util.getAlias(exps[i]); // } // } public Object clone() { return new Project( cluster, Util.clone(child), Util.clone(exps), Util.clone(fieldNames), getFlags()); } public int getFlags() { return flags; } // implement Rel protected OJClass deriveRowType() { if ((flags & flagBoxed) != flagBoxed) { return Toolbox.getType(getEnvironment(), exps[0]); } OJClass[] classes = Util.getTypes(getEnvironment(), exps); if ((flags & flagAnonFields) == flagAnonFields) { return SyntheticClass.createJoin(getTempClass(), classes); } return SyntheticClass.createProject( getTempClass(), classes, fieldNames); } // implement Rel public Rel[] getInputs() { return new Rel[] {child}; } // implement Rel public Expression[] getChildExps() { return exps; } // override Rel public void replaceInput(int ordinalInParent, Rel rel) { Util.assert(ordinalInParent == 0); this.child = rel; } public void explain(PlanWriter pw) { pw.explain(this, new String[] {"child", "expressions"}); } // override Rel public Rel changeConvention(Planner planner, int convention) { switch (convention) { case CallingConvention.JAVA: Rel convertedChild = planner.convert(child, convention); if (convertedChild == null) { return null; } return new JavaProject( cluster, convertedChild, exps, fieldNames, getFlags()); case CallingConvention.PLAN: convertedChild = planner.convert(child, convention); if (convertedChild == null) { return null; } return new PlanProject( cluster, convertedChild, exps, fieldNames, getFlags()); default: return null; } } public Cost computeSelfCost(Planner planner) { double dRows = child.getRows(), dCpu = child.getRows() * exps.length, dIo = 0; return planner.makeCost(dRows, dCpu, dIo); } } // End Project.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 1853 | Julian Hyde |
saffron: Further improve binding of rows to variables. |
||
#2 | 1801 | Julian Hyde |
saffron: add ObjectSchema; rules can now be matched more than once; started to implement correlations in queries in from list. |
||
#1 | 1467 | Julian Hyde |
saffron: First saffron check-in; incorporate my changes to openjava. |