org.eigenbase.oj.stmt
Class OJPreparingStmt

java.lang.Object
  extended by org.eigenbase.oj.stmt.OJPreparingStmt
Direct Known Subclasses:
FarragoPreparingStmt

public abstract class OJPreparingStmt
extends Object

OJPreparingStmt is an abstract base for classes which implement the process of preparing and executing SQL expressions by generating OpenJava code.


Nested Class Summary
static class OJPreparingStmt.Argument
          An Argument supplies a name/value pair to a statement.
static class OJPreparingStmt.JavaRelFinder
          Walks a RelNode tree and determines if it contains any JavaRels.
 
Field Summary
protected  RelOptConnection connection
           
static String connectionVariable
           
protected  boolean containsJava
          True if the statement contains java RelNodes
protected  Environment env
           
protected  JavaCompiler javaCompiler
           
private  String queryString
           
private  CallingConvention resultCallingConvention
          CallingConvention via which results should be returned by execution.
protected  EigenbaseTimingTracer timingTracer
           
private static Logger tracer
           
 
Constructor Summary
OJPreparingStmt(RelOptConnection connection)
          Creates a statement.
 
Method Summary
protected  void addDecl(Statement statement, ExpressionList exprList)
           
protected  void bindArgument(OJPreparingStmt.Argument arg)
           
private  BoundMethod compile(ClassDeclaration decl, Environment env, ParseTree parseTree, OJPreparingStmt.Argument[] arguments)
           
private  BoundMethod compile(String packageName, String className, String s, Class[] parameterTypes, String[] parameterNames)
           
protected  BoundMethod compileAndBind(ClassDeclaration decl, ParseTree parseTree, OJPreparingStmt.Argument[] arguments)
           
protected  Class compileClass(String packageName, String className, String source)
          Compile a single class with the given source in the given package.
protected  JavaCompiler createCompiler()
           
protected abstract  RelNode decorrelate(SqlNode query, RelNode rootRel)
           
protected abstract  RelNode flattenTypes(RelNode rootRel, boolean restructure)
           
protected abstract  String getClassRoot()
           
protected abstract  String getCompilerClassName()
           
protected  RelTraitSet getDesiredRootTraitSet(RelNode rootRel)
           
 Environment getEnvironment()
           
protected abstract  String getJavaRoot()
           
protected abstract  JavaRelImplementor getRelImplementor(RexBuilder rexBuilder)
          Protected method to allow subclasses to override construction of JavaRelImplementor.
 RelOptSchema getRelOptSchema()
           
protected abstract  SqlToRelConverter getSqlToRelConverter(SqlValidator validator, RelOptConnection connection)
          Protected method to allow subclasses to override construction of SqlToRelConverter.
protected abstract  String getTempClassName()
           
protected abstract  String getTempMethodName()
           
protected abstract  String getTempPackageName()
           
private  PreparedExecution implement(RelDataType rowType, RelNode rootRel, SqlKind sqlKind, ClassDeclaration decl, OJPreparingStmt.Argument[] args)
          Implements a physical query plan.
 ClassDeclaration init(OJPreparingStmt.Argument[] arguments)
           
protected  void initSub()
           
private  TableModificationRelBase.Operation mapTableModOp(boolean isDml, SqlKind sqlKind)
           
protected  RelNode optimize(RelDataType logicalRowType, RelNode rootRel)
          Optimizes a query plan.
 PreparedResult prepareSql(RelDataType rowType, RelNode rootRel, SqlKind sqlKind, boolean needOpt, ClassDeclaration decl, OJPreparingStmt.Argument[] args)
          Prepares a statement for execution, starting from a relational expression (ie a logical or a physical query plan).
 PreparedResult prepareSql(SqlNode sqlQuery, Class runtimeContextClass, SqlValidator validator, boolean needsValidation)
           
 PreparedResult prepareSql(SqlNode sqlQuery, SqlNode sqlNodeOriginal, Class runtimeContextClass, SqlValidator validator, boolean needsValidation)
          Prepares a statement for execution, starting from a parse tree and using a user-supplied validator.
 void setResultCallingConvention(CallingConvention resultCallingConvention)
           
protected abstract  boolean shouldAlwaysWriteJavaFile()
           
protected abstract  boolean shouldSetConnectionInfo()
           
protected  boolean treeContainsJava(RelNode rootRel)
          Determines if the RelNode tree contains Java RelNodes.
private static Class visibleBaseClass(Class clazz, String fromPackageName)
          Returns the lowest ancestor of clazz which is visible from fromPackage.fromClazz.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionVariable

public static final String connectionVariable
See Also:
Constant Field Values

tracer

private static final Logger tracer

queryString

private String queryString

env

protected Environment env

resultCallingConvention

private CallingConvention resultCallingConvention
CallingConvention via which results should be returned by execution.


javaCompiler

protected JavaCompiler javaCompiler

connection

protected final RelOptConnection connection

timingTracer

protected EigenbaseTimingTracer timingTracer

containsJava

protected boolean containsJava
True if the statement contains java RelNodes

Constructor Detail

OJPreparingStmt

public OJPreparingStmt(RelOptConnection connection)
Creates a statement.

Parameters:
connection - Connection statement belongs to; may be null, but only if this statement implements RelOptConnection
"Precondition:"
connection != null || this instanceof RelOptConnection
Method Detail

getRelOptSchema

public RelOptSchema getRelOptSchema()

getEnvironment

public Environment getEnvironment()

setResultCallingConvention

public void setResultCallingConvention(CallingConvention resultCallingConvention)

compileAndBind

protected BoundMethod compileAndBind(ClassDeclaration decl,
                                     ParseTree parseTree,
                                     OJPreparingStmt.Argument[] arguments)

initSub

protected void initSub()

init

public ClassDeclaration init(OJPreparingStmt.Argument[] arguments)

bindArgument

protected void bindArgument(OJPreparingStmt.Argument arg)

prepareSql

public PreparedResult prepareSql(SqlNode sqlQuery,
                                 Class runtimeContextClass,
                                 SqlValidator validator,
                                 boolean needsValidation)

prepareSql

public PreparedResult prepareSql(SqlNode sqlQuery,
                                 SqlNode sqlNodeOriginal,
                                 Class runtimeContextClass,
                                 SqlValidator validator,
                                 boolean needsValidation)
Prepares a statement for execution, starting from a parse tree and using a user-supplied validator.


optimize

protected RelNode optimize(RelDataType logicalRowType,
                           RelNode rootRel)
Optimizes a query plan.

Parameters:
logicalRowType - logical row type of relational expression (before struct fields are flattened, or field names are renamed for uniqueness)
rootRel - root of a relational expression
Returns:
an equivalent optimized relational expression

getDesiredRootTraitSet

protected RelTraitSet getDesiredRootTraitSet(RelNode rootRel)

treeContainsJava

protected boolean treeContainsJava(RelNode rootRel)
Determines if the RelNode tree contains Java RelNodes. Also, if the row contains an interval type, then effectively, the tree is treated as containing Java, since we currently cannot read raw interval columns.

Parameters:
rootRel - root of the RelNode tree
Returns:
true if the tree contains Java RelNodes or returns an interval type

implement

private PreparedExecution implement(RelDataType rowType,
                                    RelNode rootRel,
                                    SqlKind sqlKind,
                                    ClassDeclaration decl,
                                    OJPreparingStmt.Argument[] args)
Implements a physical query plan.

Parameters:
rowType - original rowtype returned by query validator
rootRel - root of the relational expression.
sqlKind - SqlKind of the original statement.
decl - ClassDeclaration of the generated result.
args - argument list of the generated result.
Returns:
an executable plan, a PreparedExecution.

mapTableModOp

private TableModificationRelBase.Operation mapTableModOp(boolean isDml,
                                                         SqlKind sqlKind)

prepareSql

public PreparedResult prepareSql(RelDataType rowType,
                                 RelNode rootRel,
                                 SqlKind sqlKind,
                                 boolean needOpt,
                                 ClassDeclaration decl,
                                 OJPreparingStmt.Argument[] args)
Prepares a statement for execution, starting from a relational expression (ie a logical or a physical query plan).

Parameters:
rowType -
rootRel - root of the relational expression.
sqlKind - SqlKind for the relational expression: only SqlKind.Explain and SqlKind.Dml are special cases.
needOpt - true for a logical query plan (still needs to be optimized), false for a physical plan.
decl - openjava ClassDeclaration for the code generated to implement the statement.
args - openjava argument list for the generated code.

getSqlToRelConverter

protected abstract SqlToRelConverter getSqlToRelConverter(SqlValidator validator,
                                                          RelOptConnection connection)
Protected method to allow subclasses to override construction of SqlToRelConverter.


getRelImplementor

protected abstract JavaRelImplementor getRelImplementor(RexBuilder rexBuilder)
Protected method to allow subclasses to override construction of JavaRelImplementor.


getClassRoot

protected abstract String getClassRoot()

getCompilerClassName

protected abstract String getCompilerClassName()

getJavaRoot

protected abstract String getJavaRoot()

getTempPackageName

protected abstract String getTempPackageName()

getTempMethodName

protected abstract String getTempMethodName()

getTempClassName

protected abstract String getTempClassName()

shouldAlwaysWriteJavaFile

protected abstract boolean shouldAlwaysWriteJavaFile()

shouldSetConnectionInfo

protected abstract boolean shouldSetConnectionInfo()

flattenTypes

protected abstract RelNode flattenTypes(RelNode rootRel,
                                        boolean restructure)

decorrelate

protected abstract RelNode decorrelate(SqlNode query,
                                       RelNode rootRel)

createCompiler

protected JavaCompiler createCompiler()

visibleBaseClass

private static Class visibleBaseClass(Class clazz,
                                      String fromPackageName)
Returns the lowest ancestor of clazz which is visible from fromPackage.fromClazz.


addDecl

protected void addDecl(Statement statement,
                       ExpressionList exprList)

compile

private BoundMethod compile(ClassDeclaration decl,
                            Environment env,
                            ParseTree parseTree,
                            OJPreparingStmt.Argument[] arguments)

compile

private BoundMethod compile(String packageName,
                            String className,
                            String s,
                            Class[] parameterTypes,
                            String[] parameterNames)

compileClass

protected Class compileClass(String packageName,
                             String className,
                             String source)
Compile a single class with the given source in the given package.

Parameters:
packageName - package name, if null the className must be fully qualified
className - simple class name unless packageName is null
source - source code for the class
Returns:
a Class based on source