net.sf.farrago.query
Class ScalarSubqueryConverter

java.lang.Object
  extended by net.sf.farrago.query.ScalarSubqueryConverter
All Implemented Interfaces:
SubqueryConverter

public class ScalarSubqueryConverter
extends Object
implements SubqueryConverter

ScalarSubqueryConverter converts subqueries to scalar constants by evaulating them and passing back the resulting constant expression. By doing so, this means that the statement containing the subquery can no longer be cached.

This class can also be used to convert EXISTS subqueries by replacing the EXISTS with a boolean value indicating whether the subquery returns zero (FALSE) or at least one (TRUE) row.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/query/ScalarSubqueryConverter.java#4 $
Author:
Zelaine Fong

Field Summary
private  FarragoSessionPreparingStmt stmt
           
 
Constructor Summary
ScalarSubqueryConverter(FarragoSessionPreparingStmt stmt)
           
 
Method Summary
 boolean canConvertSubquery()
           
 RexNode convertSubquery(SqlCall subquery, SqlToRelConverter parentConverter, boolean isExists, boolean isExplain)
          Converts the subquery to an equivalent expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stmt

private final FarragoSessionPreparingStmt stmt
Constructor Detail

ScalarSubqueryConverter

public ScalarSubqueryConverter(FarragoSessionPreparingStmt stmt)
Method Detail

canConvertSubquery

public boolean canConvertSubquery()
Specified by:
canConvertSubquery in interface SubqueryConverter
Returns:
true if the subquery can be converted

convertSubquery

public RexNode convertSubquery(SqlCall subquery,
                               SqlToRelConverter parentConverter,
                               boolean isExists,
                               boolean isExplain)
Description copied from interface: SubqueryConverter
Converts the subquery to an equivalent expression.

Specified by:
convertSubquery in interface SubqueryConverter
Parameters:
subquery - the SqlNode tree corresponding to a subquery
parentConverter - sqlToRelConverter of the parent query
isExists - whether the subquery is part of an EXISTS expression
isExplain - whether the subquery is part of an EXPLAIN PLAN statement
Returns:
the equivalent expression or null if the subquery couldn't be converted