/* // $Id: //guest/julian_hyde/saffron/src/main/saffron/rel/java/JavaNestedLoopJoin.java#1 $ // 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.java; import openjava.mop.OJClass; import openjava.ptree.*; import saffron.Planner; import saffron.opt.CallingConvention; import saffron.opt.Cluster; import saffron.opt.Cost; import saffron.opt.Implementor; import saffron.rel.Join; import saffron.rel.Rel; import saffron.util.Util; /** * <code>JavaNestedLoopJoin</code> implements {@link Join} using the * nested-loop algorithm, with output as code. **/ public class JavaNestedLoopJoin extends Join { public JavaNestedLoopJoin( Cluster cluster, Rel left, Rel right, Expression condition, int joinType) { super(cluster, left, right, condition, joinType); } // implement Rel public Object clone() { return new JavaNestedLoopJoin( cluster, Util.clone(left), Util.clone(right), Util.clone(condition), joinType); } // implement Plan public Cost computeSelfCost(Planner planner) { double dRows = left.getRows() * right.getRows() * Util.getSelectivity(condition), dCpu = left.getRows() * right.getRows(), dIo = 0; return planner.makeCost(dRows, dCpu, dIo); } public int getConvention() { return CallingConvention.JAVA; } public Object implement(Implementor implementor, int ordinal) { switch (ordinal) { case -1: // called from parent Object o = implementor.implementChild(this, 0, left); Util.assert(o == null); return null; case 0: // called from left { // Which variables are set by left and used by right StatementList stmtList = implementor.getStatementList(); String[] variables = Util.getVariablesSetAndUsed(left, right); for (int i = 0; i < variables.length; i++) { String variable = variables[i]; // e.g. "$corel2" Variable variableCorel = implementor.newVariable(); Rel rel = getQuery().lookupCorel(variable); OJClass clazz = rel.getRowType(); Expression exp = implementor.makeReference(variable, this); stmtList.add( new VariableDeclaration( TypeName.forOJClass(clazz), variableCorel.toString(), exp)); implementor.bindCorel(variable, variableCorel); } Object o2 = implementor.implementChild(this, 1, right); Util.assert(o2 == null); return null; } case 1: // called from right // Generate // Emp[] emps = f(); // for (int i = 0; i < emps.length; i++) { // Emp emp = emps[i]; // Dept[] depts = g(); // for (int j = 0; j < depts.length; j++) { // Dept dept = depts[j]; // if (emp.deptno == dept.deptno) { // h(); // } // } // } // which is // <<left child // <<right child // if (<<condition>>) { // <<parent>> // >> // >> StatementList stmtList = implementor.getStatementList(); if (condition != Literal.constantTrue()) { StatementList ifBody = new StatementList(); Expression condition2 = implementor.translate( this, condition); stmtList.add( new IfStatement(condition2, ifBody)); stmtList = ifBody; } implementor.generateParentBody(this, stmtList); return null; default: throw Util.newInternal( "implement: ordinal=" + ordinal); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 1853 | Julian Hyde |
saffron: Further improve binding of rows to variables. |
||
#1 | 1467 | Julian Hyde |
saffron: First saffron check-in; incorporate my changes to openjava. |