net.sf.farrago.query
Class FarragoPreparingStmt

java.lang.Object
  extended by org.eigenbase.oj.stmt.OJPreparingStmt
      extended by net.sf.farrago.query.FarragoPreparingStmt
All Implemented Interfaces:
FarragoSessionPreparingStmt, FarragoAllocation, RelOptConnection, RelOptSchema, RelOptSchemaWithSampling, SqlValidatorCatalogReader, ClosableAllocation
Direct Known Subclasses:
LucidDbPreparingStmt

public class FarragoPreparingStmt
extends OJPreparingStmt
implements FarragoSessionPreparingStmt, RelOptConnection, RelOptSchemaWithSampling, SqlValidatorCatalogReader

FarragoPreparingStmt subclasses OJPreparingStmt to implement the FarragoSessionPreparingStmt interface.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/query/FarragoPreparingStmt.java#106 $
Author:
John V. Sichi

Nested Class Summary
protected static class FarragoPreparingStmt.InvalidPlanException
          Exception describing why a plan is invalid.
protected  class FarragoPreparingStmt.PermutingRelOptTable
          Transform which permutes the columns of an input table, applying casts amd renaming columns if necessary, to make the output rowtype match the desired rowtype.
protected static class FarragoPreparingStmt.ValidatorTable
           
 
Nested classes/interfaces inherited from class org.eigenbase.oj.stmt.OJPreparingStmt
OJPreparingStmt.Argument, OJPreparingStmt.JavaRelFinder
 
Field Summary
protected  Set<CwmModelElement> allDependencies
           
private  boolean allowPartialImplementation
           
private  boolean cachingDisabled
           
private  File classesRoot
          Root directory for all generated Java.
private  Set<CwmModelElement> directDependencies
           
private  PrivilegedAction dmlAction
           
private  SqlIdentifier dmlTarget
           
private static Logger dynamicTracer
           
private  int expansionDepth
           
private static AtomicLong idGen
           
private  OJPreparingStmt.Argument[] implementingArgs
           
private  ClassDeclaration implementingClassDecl
           
private  Map<String,RelDataType> iterCalcTypeMap
           
private  Set<URL> jarUrlSet
           
private  FarragoAllocation javaCodeDir
           
private  Set<String> loadedServerClassNameSet
           
private  boolean needRestore
           
private  RelDataType originalRowType
           
private  File packageDir
          Directory containing code generated for this statement.
private  String packageName
          Name of Java package containing code generated for this statement.
private  FarragoPreparingStmt parentStmt
           
private static Logger planDumpTracer
           
private  FarragoSessionPlanner planner
           
private  FarragoRelImplementor relImplementor
           
protected  ChainedRelMetadataProvider relMetadataProvider
           
private  Map<String,RelDataType> resultSetTypeMap
           
private  FarragoSessionStmtContext rootStmtContext
           
private  FarragoUserDefinedRoutineLookup routineLookup
           
private  OJClass savedDeclarer
           
private  String sql
           
protected  SqlOperatorTable sqlOperatorTable
           
protected  SqlToRelConverter sqlToRelConverter
           
protected  SqlValidatorImpl sqlValidator
           
private  FarragoSessionStmtValidator stmtValidator
           
private static Logger streamGraphTracer
           
private  TableAccessMap tableAccessMap
           
 
Fields inherited from class org.eigenbase.oj.stmt.OJPreparingStmt
connection, connectionVariable, containsJava, env, javaCompiler, timingTracer
 
Constructor Summary
FarragoPreparingStmt(FarragoSessionStmtContext rootStmtContext, FarragoSessionStmtValidator stmtValidator, String sql)
          Creates a new FarragoPreparingStmt object.
 
Method Summary
 void addDependency(CwmModelElement supplier, PrivilegedAction action)
           
(package private)  void addJarUrl(String jarUrl)
           
(package private)  void analyzeRoutineDependencies(SqlNode sqlNode)
           
 void analyzeSql(SqlNode sqlNode, FarragoSessionAnalyzedSql analyzedSql)
          Analyzes an SQL expression, and returns information about it.
 void clearDmlValidation()
           
 void closeAllocation()
          Closes this object.
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.
 Object contentsAsArray(String qualifier, String tableName)
          In theory, this method returns the contents of tableName as an array; in practice, it is a placeholder recognized by the optimizer to do something much more efficient.
protected  RelDataType createTableRowType(CwmNamedColumnSet table)
          Creates a row-type for a given table.
protected  RelNode decorrelate(SqlNode query, RelNode rootRel)
           
private  void definePackageName()
           
 void disableStatementCaching()
          Disables caching for the statement
 void enablePartialImplementation()
          Tells this statement not to throw an exception if optimizer can't find a valid physical plan.
(package private)  RexNode expandInvocationExpression(SqlNode sqlExpr, FarragoRoutineInvocation invocation)
           
protected  RelNode expandView(RelDataType rowType, String queryString)
          Returns a relational expression which is to be substituted for an access to a SQL view.
 void finalizeRelMetadata(RelNode rootRel)
           
protected  RelNode flattenTypes(RelNode rootRel, boolean restructure)
           
 List<SqlMoniker> getAllSchemaObjectNames(List<String> names)
          Gets schema object names as specified.
protected  String getClassRoot()
           
protected  String getCompilerClassName()
           
 Variable getConnectionVariable()
           
 FarragoTypeFactory getFarragoTypeFactory()
           
 FennelDbHandle getFennelDbHandle()
           
private  FarragoMedColumnSet getForeignTableFromNamespace(FarragoSessionResolvedObject<CwmNamedColumnSet> resolved)
           
protected  OJPreparingStmt.Argument[] getImplementingArgs()
           
protected  ClassDeclaration getImplementingClassDecl()
           
 FarragoSessionIndexMap getIndexMap()
           
protected  Map<String,RelDataType> getIterCalcTypeMap()
           
protected  String getJavaRoot()
           
 RelDataType getNamedType(SqlIdentifier typeName)
          Finds a user-defined type with the given name, possibly qualified.
protected  File getPackageDir()
           
protected  RelDataType getParamRowType()
           
 FarragoPreparingStmt getParentStmt()
           
 FarragoSessionPlanner getPlanner()
           
protected  Map<String,String> getReferencedObjectTimestampMap()
           
 JavaRelImplementor getRelImplementor(RexBuilder rexBuilder)
          Protected method to allow subclasses to override construction of JavaRelImplementor.
 RelOptCluster getRelOptCluster()
           
 RelOptSchema getRelOptSchema()
          Returns the schema underlying this connection.
 FarragoRepos getRepos()
           
protected  Map<String,RelDataType> getResultSetTypeMap()
           
 FarragoSessionStmtContext getRootStmtContext()
           
 FarragoUserDefinedRoutineLookup getRoutineLookup()
           
 String getSchemaName()
          Returns the name of the current schema.
 FarragoSession getSession()
           
 String getSql()
           
 SqlOperatorTable getSqlOperatorTable()
           
 SqlToRelConverter getSqlToRelConverter()
           
protected  SqlToRelConverter getSqlToRelConverter(SqlValidator validator, RelOptConnection connection)
          Protected method to allow subclasses to override construction of SqlToRelConverter.
 SqlValidator getSqlValidator()
           
 FarragoSessionStmtValidator getStmtValidator()
           
 SqlValidatorTable getTable(String[] names)
          Finds a table with the given name, possibly qualified.
protected  TableAccessMap getTableAccessMap()
           
 RelOptTable getTableForMember(String[] names)
          Retrieves a RelOptTable based upon a member access.
 RelOptTable getTableForMember(String[] names, String datasetName, boolean[] usedDataset)
          Retrieves a RelOptTable based upon a member access, using a sample dataset if it exists.
protected  String getTempClassName()
           
protected  String getTempMethodName()
           
protected  String getTempPackageName()
           
protected  List<FarragoTransformDef> getTransformDefs()
           
 RelDataTypeFactory getTypeFactory()
          Returns the type factory used to generate types for this schema.
 boolean hasSqlValidator()
           
protected  FarragoSessionExecutableStmt implement(PreparedResult preparedResult)
           
 FarragoSessionExecutableStmt implement(RelNode rootRel, SqlKind sqlKind, boolean logical)
          Implements a logical or physical query plan but does not execute it.
protected  void initClassDecl()
           
private  void initializeQueryColumnSet(RelOptTable relOptTable, CwmNamedColumnSet cwmColumnSet)
           
 boolean isExpandingDefinition()
           
 RelOptTable loadColumnSet(SqlIdentifier name)
          Looks up a named ColumnSet and loads its optimizer representation.
private  FarragoMedDataServer loadDataServerFromCache(FemDataServer femServer)
           
 void mapIterCalcType(String iterCalcName, RelDataType rowType)
           
 void mapResultSetType(String resultSetName, RelDataType rowType)
           
 boolean mayCacheImplementation()
          Test if the implementation may be saved for reuse.
protected  FarragoRelImplementor newRelImplementor(RexBuilder rexBuilder)
           
protected  SqlValidatorTable newValidatorTable(String[] qualifiedName, RelDataType rowType, SqlAccessType allowedAccess, ModalityType modality)
          Factory method, creates a table.
protected  RelNode optimize(RelDataType rowType, RelNode rootRel)
          Optimizes a query plan.
 void postValidate(SqlNode sqlNode)
          Performs post-validation work after SqlValidator has been called.
 void preImplement()
          Sets up the environment the FarragoPreparingStmt needs in order to implement (i.e.
 FarragoSessionExecutableStmt prepare(SqlNode sqlNode, SqlNode sqlNodeOriginal)
          Prepares (translates and implements) a parsed query or DML statement, but does not execute it.
protected  void prepareForCompilation()
           
 void registerRules(RelOptPlanner planner)
          Registers all of the rules supported by this schema.
 void setDmlValidation(SqlIdentifier target, PrivilegedAction action)
           
 void setParentStmt(FarragoPreparingStmt parentStmt)
          Sets the parent FarragoPreparingStmt corresponding to this statement.
 void setPlanner(FarragoSessionPlanner planner)
           
protected  boolean shouldAlwaysWriteJavaFile()
           
protected  boolean shouldSetConnectionInfo()
           
protected  boolean treeContainsJava(RelNode rootRel)
          Determines if the RelNode tree contains Java RelNodes.
protected  void validatePlan(RelNode rel, RelTraitSet desiredTraits)
           
 
Methods inherited from class org.eigenbase.oj.stmt.OJPreparingStmt
addDecl, bindArgument, createCompiler, getDesiredRootTraitSet, getEnvironment, init, initSub, prepareSql, prepareSql, prepareSql, setResultCallingConvention
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dynamicTracer

private static final Logger dynamicTracer

streamGraphTracer

private static final Logger streamGraphTracer

planDumpTracer

private static final Logger planDumpTracer

idGen

private static final AtomicLong idGen

sql

private final String sql

stmtValidator

private final FarragoSessionStmtValidator stmtValidator

needRestore

private boolean needRestore

sqlToRelConverter

protected SqlToRelConverter sqlToRelConverter

savedDeclarer

private OJClass savedDeclarer

javaCodeDir

private FarragoAllocation javaCodeDir

sqlValidator

protected SqlValidatorImpl sqlValidator

directDependencies

private final Set<CwmModelElement> directDependencies

allDependencies

protected final Set<CwmModelElement> allDependencies

jarUrlSet

private final Set<URL> jarUrlSet

sqlOperatorTable

protected SqlOperatorTable sqlOperatorTable

routineLookup

private final FarragoUserDefinedRoutineLookup routineLookup

expansionDepth

private int expansionDepth

originalRowType

private RelDataType originalRowType

dmlTarget

private SqlIdentifier dmlTarget

dmlAction

private PrivilegedAction dmlAction

tableAccessMap

private TableAccessMap tableAccessMap

relMetadataProvider

protected ChainedRelMetadataProvider relMetadataProvider

allowPartialImplementation

private boolean allowPartialImplementation

resultSetTypeMap

private final Map<String,RelDataType> resultSetTypeMap

iterCalcTypeMap

private final Map<String,RelDataType> iterCalcTypeMap

cachingDisabled

private boolean cachingDisabled

parentStmt

private FarragoPreparingStmt parentStmt

rootStmtContext

private final FarragoSessionStmtContext rootStmtContext

packageName

private String packageName
Name of Java package containing code generated for this statement.


packageDir

private File packageDir
Directory containing code generated for this statement.


classesRoot

private File classesRoot
Root directory for all generated Java.


implementingClassDecl

private ClassDeclaration implementingClassDecl

implementingArgs

private OJPreparingStmt.Argument[] implementingArgs

loadedServerClassNameSet

private Set<String> loadedServerClassNameSet

planner

private FarragoSessionPlanner planner

relImplementor

private FarragoRelImplementor relImplementor
Constructor Detail

FarragoPreparingStmt

public FarragoPreparingStmt(FarragoSessionStmtContext rootStmtContext,
                            FarragoSessionStmtValidator stmtValidator,
                            String sql)
Creates a new FarragoPreparingStmt object.

Parameters:
rootStmtContext - the root statement context
stmtValidator - generic stmt validator
sql - SQL text of statement being prepared
Method Detail

mayCacheImplementation

public boolean mayCacheImplementation()
Description copied from interface: FarragoSessionPreparingStmt
Test if the implementation may be saved for reuse. Called after the statement has been prepared.

Specified by:
mayCacheImplementation in interface FarragoSessionPreparingStmt

disableStatementCaching

public void disableStatementCaching()
Description copied from interface: FarragoSessionPreparingStmt
Disables caching for the statement

Specified by:
disableStatementCaching in interface FarragoSessionPreparingStmt

getRootStmtContext

public FarragoSessionStmtContext getRootStmtContext()
Specified by:
getRootStmtContext in interface FarragoSessionPreparingStmt
Returns:
the root statement context for this statement

getStmtValidator

public FarragoSessionStmtValidator getStmtValidator()
Specified by:
getStmtValidator in interface FarragoSessionPreparingStmt
Returns:
generic stmt validator

getParentStmt

public FarragoPreparingStmt getParentStmt()
Returns:
the FarragoPreparingStmt that's the parent of this one

setParentStmt

public void setParentStmt(FarragoPreparingStmt parentStmt)
Sets the parent FarragoPreparingStmt corresponding to this statement. This is used when this is a reentrant statement. The parent corresponds to the statement that requires the reentrant statement.

Parameters:
parentStmt - the parent of this statement

setPlanner

public void setPlanner(FarragoSessionPlanner planner)

enablePartialImplementation

public void enablePartialImplementation()
Tells this statement not to throw an exception if optimizer can't find a valid physical plan. This is intended for use mainly by unit tests which need to peer into intermediate query optimization states.


getPlanner

public FarragoSessionPlanner getPlanner()

getSqlOperatorTable

public SqlOperatorTable getSqlOperatorTable()
Specified by:
getSqlOperatorTable in interface FarragoSessionPreparingStmt
Returns:
the SqlOperatorTable used for operator lookup during this stmt's preparation; this includes both system-defined and user-defined functions

hasSqlValidator

public boolean hasSqlValidator()

getSqlValidator

public SqlValidator getSqlValidator()
Specified by:
getSqlValidator in interface FarragoSessionPreparingStmt
Returns:
the SqlValidator for this statement (creating it if it does not yet exist)

prepare

public FarragoSessionExecutableStmt prepare(SqlNode sqlNode,
                                            SqlNode sqlNodeOriginal)
Description copied from interface: FarragoSessionPreparingStmt
Prepares (translates and implements) a parsed query or DML statement, but does not execute it.

Specified by:
prepare in interface FarragoSessionPreparingStmt
Parameters:
sqlNode - top-level node of parsed statement
sqlNodeOriginal - original form of sqlNode if it has been rewritten by validation; otherwise, same as sqlNode
Returns:
prepared FarragoSessionExecutableStmt

preImplement

public void preImplement()
Description copied from interface: FarragoSessionPreparingStmt
Sets up the environment the FarragoPreparingStmt needs in order to implement (i.e. to generate code). When preparing a parsed query (by calling FarragoSessionPreparingStmt.prepare(org.eigenbase.sql.SqlNode, org.eigenbase.sql.SqlNode)) this happens automatically. But when implementing a query presented as a query plan (by calling FarragoSessionPreparingStmt.implement(org.eigenbase.rel.RelNode, org.eigenbase.sql.SqlKind, boolean)), you must call this method first, even before constructing the query plan.

Specified by:
preImplement in interface FarragoSessionPreparingStmt

initClassDecl

protected void initClassDecl()

getImplementingClassDecl

protected ClassDeclaration getImplementingClassDecl()

getImplementingArgs

protected OJPreparingStmt.Argument[] getImplementingArgs()

getTableAccessMap

protected TableAccessMap getTableAccessMap()

getResultSetTypeMap

protected Map<String,RelDataType> getResultSetTypeMap()

getIterCalcTypeMap

protected Map<String,RelDataType> getIterCalcTypeMap()

getTransformDefs

protected List<FarragoTransformDef> getTransformDefs()

postValidate

public void postValidate(SqlNode sqlNode)
Description copied from interface: FarragoSessionPreparingStmt
Performs post-validation work after SqlValidator has been called.

Specified by:
postValidate in interface FarragoSessionPreparingStmt
Parameters:
sqlNode - output of SqlValidator

implement

public FarragoSessionExecutableStmt implement(RelNode rootRel,
                                              SqlKind sqlKind,
                                              boolean logical)
Description copied from interface: FarragoSessionPreparingStmt
Implements a logical or physical query plan but does not execute it. You must call FarragoSessionPreparingStmt.preImplement() first, in fact before constructing the query plan.

Specified by:
implement in interface FarragoSessionPreparingStmt
Parameters:
rootRel - root of query plan (relational expression)
sqlKind - SqlKind for the relational expression: only SqlKind.Explain and SqlKind.Dml are special cases.
logical - true for a logical query plan (still needs to be optimized), false for a physical plan.
Returns:
prepared FarragoSessionExecutableStmt

getRoutineLookup

public FarragoUserDefinedRoutineLookup getRoutineLookup()
Returns:
lookup table for user-defined routines

addJarUrl

void addJarUrl(String jarUrl)

prepareForCompilation

protected void prepareForCompilation()

definePackageName

private void definePackageName()

compileClass

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

Overrides:
compileClass in class OJPreparingStmt
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

compileAndBind

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

treeContainsJava

protected boolean treeContainsJava(RelNode rootRel)
Description copied from class: OJPreparingStmt
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.

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

implement

protected FarragoSessionExecutableStmt implement(PreparedResult preparedResult)

analyzeSql

public void analyzeSql(SqlNode sqlNode,
                       FarragoSessionAnalyzedSql analyzedSql)
Description copied from interface: FarragoSessionPreparingStmt
Analyzes an SQL expression, and returns information about it. Used when an expression is not going to be executed directly, but needs to be validated as part of the definition of some containing object such as a view.

Specified by:
analyzeSql in interface FarragoSessionPreparingStmt
Parameters:
sqlNode - SQL expression to be analyzed
analyzedSql - receives analysis result

analyzeRoutineDependencies

void analyzeRoutineDependencies(SqlNode sqlNode)

getReferencedObjectTimestampMap

protected Map<String,String> getReferencedObjectTimestampMap()

getSqlToRelConverter

public SqlToRelConverter getSqlToRelConverter()
Specified by:
getSqlToRelConverter in interface FarragoSessionPreparingStmt
Returns:
the SqlToRelConverter used by this stmt (creating it if it does not yet exist)

getRelOptCluster

public RelOptCluster getRelOptCluster()
Specified by:
getRelOptCluster in interface FarragoSessionPreparingStmt
Returns:
the RelOptCluster used by this stmt (possibly creating the SqlToRelConverter as a side effect if it does not yet exist).

flattenTypes

protected RelNode flattenTypes(RelNode rootRel,
                               boolean restructure)
Specified by:
flattenTypes in class OJPreparingStmt

decorrelate

protected RelNode decorrelate(SqlNode query,
                              RelNode rootRel)
Specified by:
decorrelate in class OJPreparingStmt

optimize

protected RelNode optimize(RelDataType rowType,
                           RelNode rootRel)
Description copied from class: OJPreparingStmt
Optimizes a query plan.

Overrides:
optimize in class OJPreparingStmt
Parameters:
rowType - 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

validatePlan

protected void validatePlan(RelNode rel,
                            RelTraitSet desiredTraits)
                     throws FarragoPreparingStmt.InvalidPlanException
Throws:
FarragoPreparingStmt.InvalidPlanException

finalizeRelMetadata

public void finalizeRelMetadata(RelNode rootRel)

getParamRowType

protected RelDataType getParamRowType()

closeAllocation

public void closeAllocation()
Description copied from interface: ClosableAllocation
Closes this object.

Specified by:
closeAllocation in interface ClosableAllocation

expandView

protected RelNode expandView(RelDataType rowType,
                             String queryString)
Returns a relational expression which is to be substituted for an access to a SQL view.

Parameters:
rowType - Row type of the view
queryString - Body of the view
Returns:
Relational expression

expandInvocationExpression

RexNode expandInvocationExpression(SqlNode sqlExpr,
                                   FarragoRoutineInvocation invocation)

setDmlValidation

public void setDmlValidation(SqlIdentifier target,
                             PrivilegedAction action)

clearDmlValidation

public void clearDmlValidation()

isExpandingDefinition

public boolean isExpandingDefinition()
Returns:
true iff currently expanding a view or function

getSqlToRelConverter

protected SqlToRelConverter getSqlToRelConverter(SqlValidator validator,
                                                 RelOptConnection connection)
Description copied from class: OJPreparingStmt
Protected method to allow subclasses to override construction of SqlToRelConverter.

Specified by:
getSqlToRelConverter in class OJPreparingStmt

getRelImplementor

public JavaRelImplementor getRelImplementor(RexBuilder rexBuilder)
Description copied from class: OJPreparingStmt
Protected method to allow subclasses to override construction of JavaRelImplementor.

Specified by:
getRelImplementor in interface FarragoSessionPreparingStmt
Specified by:
getRelImplementor in class OJPreparingStmt
Parameters:
rexBuilder - RexBuilder to use for constructing row expressions
Returns:
new expression implementor

newRelImplementor

protected FarragoRelImplementor newRelImplementor(RexBuilder rexBuilder)

getRepos

public FarragoRepos getRepos()
Specified by:
getRepos in interface FarragoSessionPreparingStmt
Returns:
repos for this stmt

getFennelDbHandle

public FennelDbHandle getFennelDbHandle()
Specified by:
getFennelDbHandle in interface FarragoSessionPreparingStmt
Returns:
handle to Fennel database accessed by this stmt

getFarragoTypeFactory

public FarragoTypeFactory getFarragoTypeFactory()
Specified by:
getFarragoTypeFactory in interface FarragoSessionPreparingStmt
Returns:
type factory for this stmt

getIndexMap

public FarragoSessionIndexMap getIndexMap()
Specified by:
getIndexMap in interface FarragoSessionPreparingStmt
Returns:
FarragoSessionIndexMap to use for accessing index storage

getSession

public FarragoSession getSession()
Specified by:
getSession in interface FarragoSessionPreparingStmt
Returns:
session which invoked statement preparation

getSql

public String getSql()
Specified by:
getSql in interface FarragoSessionPreparingStmt
Returns:
SQL text of the statement being prepared

getRelOptSchema

public RelOptSchema getRelOptSchema()
Description copied from interface: RelOptConnection
Returns the schema underlying this connection. Non-abstract classes implementing this interface must also provide public static Schema getRelOptSchemaStatic().

Specified by:
getRelOptSchema in interface RelOptConnection
Overrides:
getRelOptSchema in class OJPreparingStmt

contentsAsArray

public Object contentsAsArray(String qualifier,
                              String tableName)
Description copied from interface: RelOptConnection
In theory, this method returns the contents of tableName as an array; in practice, it is a placeholder recognized by the optimizer to do something much more efficient. This involves calling RelOptSchema.getTableForMember(java.lang.String[])(qualifier,tableName).RelOptTable.toRel(org.eigenbase.relopt.RelOptCluster, org.eigenbase.relopt.RelOptConnection)(cluster, exp).

Specified by:
contentsAsArray in interface RelOptConnection

loadColumnSet

public RelOptTable loadColumnSet(SqlIdentifier name)
Description copied from interface: FarragoSessionPreparingStmt
Looks up a named ColumnSet and loads its optimizer representation.

Specified by:
loadColumnSet in interface FarragoSessionPreparingStmt
Parameters:
name - name of ColumnSet
Returns:
optimizer representation, or null if not found

getTableForMember

public RelOptTable getTableForMember(String[] names)
Description copied from interface: RelOptSchema
Retrieves a RelOptTable based upon a member access.

For example, the Saffron expression salesSchema.emps would be resolved using a call to salesSchema.getTableForMember(new String[]{"emps" }).

Note that name.length is only greater than 1 for queries originating from JDBC.

Specified by:
getTableForMember in interface RelOptSchema

getTableForMember

public RelOptTable getTableForMember(String[] names,
                                     String datasetName,
                                     boolean[] usedDataset)
Description copied from interface: RelOptSchemaWithSampling
Retrieves a RelOptTable based upon a member access, using a sample dataset if it exists.

Specified by:
getTableForMember in interface RelOptSchemaWithSampling
Parameters:
names - Compound name of table
datasetName - Name of sample dataset to substitute, if it exists; null to not look for a sample
usedDataset - Output parameter which is set to true if a sample dataset is found; may be null
Returns:
Table, or null if not found

initializeQueryColumnSet

private void initializeQueryColumnSet(RelOptTable relOptTable,
                                      CwmNamedColumnSet cwmColumnSet)

getForeignTableFromNamespace

private FarragoMedColumnSet getForeignTableFromNamespace(FarragoSessionResolvedObject<CwmNamedColumnSet> resolved)

loadDataServerFromCache

private FarragoMedDataServer loadDataServerFromCache(FemDataServer femServer)

getTypeFactory

public RelDataTypeFactory getTypeFactory()
Description copied from interface: RelOptSchema
Returns the type factory used to generate types for this schema.

Specified by:
getTypeFactory in interface RelOptSchema

registerRules

public void registerRules(RelOptPlanner planner)
Description copied from interface: RelOptSchema
Registers all of the rules supported by this schema. Only called by RelOptPlanner.registerSchema(org.eigenbase.relopt.RelOptSchema).

Specified by:
registerRules in interface RelOptSchema

getTable

public SqlValidatorTable getTable(String[] names)
Description copied from interface: SqlValidatorCatalogReader
Finds a table with the given name, possibly qualified.

Specified by:
getTable in interface SqlValidatorCatalogReader
Parameters:
names - Name of table
Returns:
named table, or null if not found

createTableRowType

protected RelDataType createTableRowType(CwmNamedColumnSet table)
Creates a row-type for a given table. This row-type includes any system columns which are implicit for this type of type.

Parameters:
table - Repository table
Returns:
Row type including system columns

newValidatorTable

protected SqlValidatorTable newValidatorTable(String[] qualifiedName,
                                              RelDataType rowType,
                                              SqlAccessType allowedAccess,
                                              ModalityType modality)
Factory method, creates a table.


getNamedType

public RelDataType getNamedType(SqlIdentifier typeName)
Description copied from interface: SqlValidatorCatalogReader
Finds a user-defined type with the given name, possibly qualified.

NOTE jvs 12-Feb-2005: the reason this method is defined here instead of on RelDataTypeFactory is that it has to take into account context-dependent information such as SQL schema path, whereas a type factory is context-independent.

Specified by:
getNamedType in interface SqlValidatorCatalogReader
Parameters:
typeName - Name of type
Returns:
named type, or null if not found

getAllSchemaObjectNames

public List<SqlMoniker> getAllSchemaObjectNames(List<String> names)
Description copied from interface: SqlValidatorCatalogReader
Gets schema object names as specified. They can be schema or table object. If names array contain 1 element, return all schema names and all table names under the default schema (if that is set) If names array contain 2 elements, treat 1st element as schema name and return all table names in this schema

Specified by:
getAllSchemaObjectNames in interface SqlValidatorCatalogReader
Parameters:
names - the array contains either 2 elements representing a partially qualified object name in the format of 'schema.object', or an unqualified name in the format of 'object'
Returns:
the list of all object (schema and table) names under the above criteria

getSchemaName

public String getSchemaName()
Description copied from interface: SqlValidatorCatalogReader
Returns the name of the current schema.

Specified by:
getSchemaName in interface SqlValidatorCatalogReader
Returns:
name of the current schema

addDependency

public void addDependency(CwmModelElement supplier,
                          PrivilegedAction action)

mapResultSetType

public void mapResultSetType(String resultSetName,
                             RelDataType rowType)

mapIterCalcType

public void mapIterCalcType(String iterCalcName,
                            RelDataType rowType)

getConnectionVariable

public Variable getConnectionVariable()

getCompilerClassName

protected String getCompilerClassName()
Specified by:
getCompilerClassName in class OJPreparingStmt

shouldSetConnectionInfo

protected boolean shouldSetConnectionInfo()
Specified by:
shouldSetConnectionInfo in class OJPreparingStmt

shouldAlwaysWriteJavaFile

protected boolean shouldAlwaysWriteJavaFile()
Specified by:
shouldAlwaysWriteJavaFile in class OJPreparingStmt

getPackageDir

protected File getPackageDir()

getClassRoot

protected String getClassRoot()
Specified by:
getClassRoot in class OJPreparingStmt

getJavaRoot

protected String getJavaRoot()
Specified by:
getJavaRoot in class OJPreparingStmt

getTempPackageName

protected String getTempPackageName()
Specified by:
getTempPackageName in class OJPreparingStmt

getTempClassName

protected String getTempClassName()
Specified by:
getTempClassName in class OJPreparingStmt

getTempMethodName

protected String getTempMethodName()
Specified by:
getTempMethodName in class OJPreparingStmt