org.eigenbase.rel.jdbc
Class JdbcQuery

java.lang.Object
  extended by org.eigenbase.rel.AbstractRelNode
      extended by org.eigenbase.rel.jdbc.JdbcQuery
All Implemented Interfaces:
Cloneable, JavaRel, ResultSetRel, RelNode
Direct Known Subclasses:
MedJdbcQueryRel

public class JdbcQuery
extends AbstractRelNode
implements ResultSetRel

A JdbcQuery is a relational expression whose source is a SQL statement executed against a JDBC data source. It has result set calling convention.

Since:
2 August, 2002
Version:
$Id: //open/dev/farrago/src/org/eigenbase/rel/jdbc/JdbcQuery.java#21 $
Author:
jhyde

Field Summary
protected  RelOptConnection connection
          The expression which yields the connection object.
private  DataSource dataSource
           
(package private)  SqlDialect dialect
           
protected  String queryString
          For debug.
(package private)  SqlSelect sql
           
 
Fields inherited from class org.eigenbase.rel.AbstractRelNode
digest, id, rowType, traits
 
Fields inherited from interface org.eigenbase.rel.RelNode
emptyArray
 
Constructor Summary
JdbcQuery(RelOptCluster cluster, RelDataType rowType, RelOptConnection connection, SqlDialect dialect, SqlSelect sql, DataSource dataSource)
          Creates a JdbcQuery.
 
Method Summary
 JdbcQuery clone()
          Clones this RelNode.
 RelOptCost computeSelfCost(RelOptPlanner planner)
          Returns the cost of this plan (not including children).
 void explain(RelOptPlanWriter pw)
           
 RelOptConnection getConnection()
          Returns the connection
 DataSource getDataSource()
          Returns the JDBC data source
 String getForeignSql()
          Returns the SQL that this query will execute against the foreign database, in the SQL dialect of that database.
 SqlSelect getSql()
          Returns the parse tree of the SQL statement which populates this query.
 ParseTree implement(JavaRelImplementor implementor)
          Creates a plan for this expression according to a calling convention.
 void onRegister(RelOptPlanner planner)
          Receives notification that this expression is about to be registered.
static void register(RelOptPlanner planner)
          Registers any planner rules needed to implement queries using JdbcQuery objects.
 
Methods inherited from class org.eigenbase.rel.AbstractRelNode
childrenAccept, cloneTraits, collectVariablesSet, collectVariablesUsed, computeDigest, deriveRowType, getChildExps, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getInputs, getOrCreateCorrelVariable, getQuery, getRelTypeName, getRows, getRowType, getTable, getTraits, getVariablesStopped, inheritTraitsFrom, isAccessTo, isDistinct, isValid, recomputeDigest, registerCorrelVariable, replaceInput, setCorrelVariable, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eigenbase.rel.RelNode
childrenAccept, collectVariablesSet, collectVariablesUsed, getChildExps, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getInputs, getOrCreateCorrelVariable, getQuery, getRelTypeName, getRows, getRowType, getTable, getTraits, getVariablesStopped, isAccessTo, isDistinct, isValid, recomputeDigest, registerCorrelVariable, replaceInput, setCorrelVariable
 

Field Detail

dataSource

private final DataSource dataSource

connection

protected RelOptConnection connection
The expression which yields the connection object.


dialect

SqlDialect dialect

sql

SqlSelect sql

queryString

protected String queryString
For debug. Set on register.

Constructor Detail

JdbcQuery

public JdbcQuery(RelOptCluster cluster,
                 RelDataType rowType,
                 RelOptConnection connection,
                 SqlDialect dialect,
                 SqlSelect sql,
                 DataSource dataSource)
Creates a JdbcQuery.

Parameters:
cluster - RelOptCluster this relational expression belongs to
connection - a RelOptConnection; must also implement DataSource, because that's how we will acquire the JDBC connection
sql - SQL parse tree, may be null, otherwise must be a SELECT statement
dataSource - Provides a JDBC connection to run this query against.

In saffron, if the query is implementing a JDBC table, then the connection's schema will implement net.sf.saffron.ext.JdbcSchema, and data source will typically be the same as calling the getDataSource() method on that schema. But non-JDBC schemas are also acceptable.

"Precondition:"
connection != null, sql == null || sql.isA(SqlNode.Kind.Select), dataSource != null
Method Detail

getConnection

public RelOptConnection getConnection()
Returns the connection

Returns:
connection

getDataSource

public DataSource getDataSource()
Returns the JDBC data source

Returns:
data source

explain

public void explain(RelOptPlanWriter pw)
Specified by:
explain in interface RelNode
Overrides:
explain in class AbstractRelNode

getForeignSql

public String getForeignSql()
Returns the SQL that this query will execute against the foreign database, in the SQL dialect of that database.

Returns:
foreign SQL
See Also:
getSql()

clone

public JdbcQuery clone()
Description copied from interface: RelNode
Clones this RelNode.

Traits of the RelNode must be explicitly cloned, using AbstractRelNode.inheritTraitsFrom(AbstractRelNode), as the RelNode may have traits of which it has no knowledge. Example implementation:

     public MyRelNode clone()
     {
         MyRelNode clone = new MyRelNode(...);
         clone.inheritTraitsFrom(this);
         return clone;
     }
 
N.B.: This method must be overridden whenever an existing, concrete RelNode is extended. Otherwise, calling clone() will produce a differently typed RelNode, resulting in invalid or incorrect query plans.

Specified by:
clone in interface RelNode
Specified by:
clone in class AbstractRelNode
Returns:
a clone of this RelNode

computeSelfCost

public RelOptCost computeSelfCost(RelOptPlanner planner)
Description copied from interface: RelNode
Returns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.

NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getNonCumulativeCost(org.eigenbase.rel.RelNode), which gives plugins a chance to override the rel's default ideas about cost.

Specified by:
computeSelfCost in interface RelNode
Overrides:
computeSelfCost in class AbstractRelNode

onRegister

public void onRegister(RelOptPlanner planner)
Description copied from interface: RelNode
Receives notification that this expression is about to be registered. The implementation of this method must at least register all child expressions.

Specified by:
onRegister in interface RelNode
Overrides:
onRegister in class AbstractRelNode

register

public static void register(RelOptPlanner planner)
Registers any planner rules needed to implement queries using JdbcQuery objects.

Parameters:
planner - Planner

implement

public ParseTree implement(JavaRelImplementor implementor)
Description copied from interface: JavaRel
Creates a plan for this expression according to a calling convention.

Specified by:
implement in interface JavaRel
Parameters:
implementor - implementor

getSql

public SqlSelect getSql()
Returns the parse tree of the SQL statement which populates this query.

Returns:
SQL query