net.sf.farrago.defimpl
Class FarragoDefaultSessionPersonality

java.lang.Object
  extended by net.sf.farrago.defimpl.FarragoDefaultSessionPersonality
All Implemented Interfaces:
FarragoSessionPersonality, FarragoStreamFactoryProvider
Direct Known Subclasses:
FarragoAutoCalcRulesTest.TestDbSessionPersonality, FarragoMiniplanPersonalityFactory.FarragoMiniplanSessionPersonality, FarragoTestPersonalityFactory.FarragoTestSessionPersonality, FarragoVolcanoPersonalityFactory.FarragoVolcanoSessionPersonality, LucidDbSessionPersonality

public class FarragoDefaultSessionPersonality
extends Object
implements FarragoSessionPersonality

FarragoDefaultSessionPersonality is a default implementation of the FarragoSessionPersonality interface.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/defimpl/FarragoDefaultSessionPersonality.java#55 $
Author:
John V. Sichi

Nested Class Summary
private  class FarragoDefaultSessionPersonality.ParamDesc
          ParamDesc represents a session parameter descriptor
 class FarragoDefaultSessionPersonality.ParamValidator
          ParamValidator is a basic session parameter validator
 
Field Summary
static String CACHE_STATEMENTS
          Whether statement caching is enabled for a session
static String CACHE_STATEMENTS_DEFAULT
           
protected  FarragoDatabase database
           
static String DEGREE_OF_PARALLELISM
          Degree of parallelism to use for parallel executor; a value of 1 (the default) causes the default non-parallel executor to be used.
static String DEGREE_OF_PARALLELISM_DEFAULT
           
static String LABEL
          The label for the current session
static String LABEL_DEFAULT
           
protected  FarragoDefaultSessionPersonality.ParamValidator paramValidator
           
static String REDUCE_NON_CORRELATED_SUBQUERIES
          Whether non-correlated subqueries should be converted to constants
static String REDUCE_NON_CORRELATED_SUBQUERIES_FARRAGO_DEFAULT
           
static String SQUEEZE_JDBC_NUMERIC
          Numeric data from external data sources may have a greater precision than Farrago.
static String SQUEEZE_JDBC_NUMERIC_DEFAULT
           
static String VALIDATE_DDL_ON_PREPARE
          Whether DDL validation should be done at prepare time
static String VALIDATE_DDL_ON_PREPARE_DEFAULT
           
 
Constructor Summary
protected FarragoDefaultSessionPersonality(FarragoDbSession session)
           
 
Method Summary
protected  boolean addRowCount(ResultSet resultSet, List<Long> rowCounts)
           
 FarragoSessionVariables createInheritedSessionVariables(FarragoSessionVariables variables)
          Creates a set of session variables for use in a cloned session.
 void defineDdlHandlers(FarragoSessionDdlValidator ddlValidator, List<DdlHandler> handlerList)
          See FarragoSessionModelExtension.defineDdlHandlers(net.sf.farrago.session.FarragoSessionDdlValidator, java.util.List).
 void definePlannerListeners(FarragoSessionPlanner planner)
          Defines listeners for events which occur during planning.
 void definePrivileges(FarragoSessionPrivilegeMap map)
          Defines privileges allowed on various object types.
private  void defineTypePrivileges(FarragoSessionPrivilegeMap map, RefClass refClass, PrivilegedAction[] actions)
           
 String getDefaultLocalDataServerName(FarragoSessionStmtValidator stmtValidator)
          Gets the name of the local data server to use for tables when none is specified by CREATE TABLE.
 OJRexImplementorTable getOJRexImplementorTable(FarragoSessionPreparingStmt preparingStmt)
          Gets the implementation table to use for compiling a statement that uses a Java calculator.
 void getRowCounts(ResultSet resultSet, List<Long> rowCounts, TableModificationRelBase.Operation tableModOp)
          Gives this personality the opportunity to retrieve rowcount information returned by a DML operation.
 Class getRuntimeContextClass(FarragoSessionPreparingStmt preparingStmt)
          Determines the class to use for runtime context.
 SqlOperatorTable getSqlOperatorTable(FarragoSessionPreparingStmt preparingStmt)
          Gets the SQL operator table to use for validating a statement.
protected  void initPreparingStmt(FarragoPreparingStmt stmt)
           
 boolean isAlterTableAddColumnIncremental()
          Tests whether this session personality implements ALTER TABLE ADD COLUMN in an incremental fashion (only adding on the new column as opposed to reformatting existing rows).
 boolean isJavaUdxRestartable()
          Returns whether a JavaUDX is implemented as a restartable data source.
 boolean isSupportedType(SqlTypeName type)
          Returns whether a type is valid in this database.
 void loadDefaultSessionVariables(FarragoSessionVariables variables)
          Loads variables from the session personality into a session variables object.
<C> C
newComponentImpl(Class<C> componentInterface)
          Gets the component associated with the given Class object from the personality.
 FarragoSessionDdlValidator newDdlValidator(FarragoSessionStmtValidator stmtValidator)
          Creates a new validator for DDL commands.
 JmiQueryProcessor newJmiQueryProcessor(String language)
          Creates a new processor for JMI queries.
 FarragoSessionParser newParser(FarragoSession session)
          Creates a new SQL parser.
 FarragoSessionPlanner newPlanner(FarragoSessionPreparingStmt stmt, boolean init)
          Creates a new planner.
 FarragoSessionPreparingStmt newPreparingStmt(FarragoSessionStmtContext stmtContext, FarragoSessionStmtContext rootStmtContext, FarragoSessionStmtValidator stmtValidator)
          Creates a new preparing statement tied to this session and its underlying database.
 FarragoSessionPreparingStmt newPreparingStmt(FarragoSessionStmtContext stmtContext, FarragoSessionStmtValidator stmtValidator)
          Creates a new preparing statement tied to this session and its underlying database.
 FarragoSessionPreparingStmt newPreparingStmt(FarragoSessionStmtValidator stmtValidator)
           
 FarragoSessionRuntimeContext newRuntimeContext(FarragoSessionRuntimeParams params)
          Creates a new runtime context.
 RelDataTypeFactory newTypeFactory(FarragoRepos repos)
          Creates a new type factory.
 void registerRelMetadataProviders(ChainedRelMetadataProvider chain)
          Gives this personality a chance to register one or more RelMetadataProviders in the chain which will be used to answer relational expression metadata queries during optimization.
 void registerStreamFactories(long hStreamGraph)
          Registers factories for extension ExecStreams in Fennel.
 void resetRowCounts(FemAbstractColumnSet table)
          Gives this personality the opportunity to reset rowcount information in the catalog tables for a specified table
 boolean shouldReplacePreserveOriginalSql()
          Tests whether this personality wants original SQL to be preserved for dependent objects where possible during the revalidation triggered by CREATE OR REPLACE.
 boolean supportsFeature(org.eigenbase.resgen.ResourceDefinition feature)
          Tests whether a feature is supported in this personality.
 void updateIndexRoot(FemLocalIndex index, FarragoDataWrapperCache wrapperCache, FarragoSessionIndexMap baseIndexMap, Long newRoot)
          Gives the personality the opportunity to update an index root page when the index is rebuilt
 long updateRowCounts(FarragoSession session, List<String> tableName, List<Long> rowCounts, TableModificationRelBase.Operation tableModOp, FarragoSessionRuntimeContext runningContext)
          Gives this personality the opportunity to update rowcount information in the catalog tables for a specified table as a result of a particular DML operation.
 void validateSessionVariable(FarragoSessionDdlValidator ddlValidator, FarragoSessionVariables variables, String name, String value)
          Checks whether a parameter value is appropriate for a session variable and, if the value is appropriate, sets the session variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SQUEEZE_JDBC_NUMERIC

public static final String SQUEEZE_JDBC_NUMERIC
Numeric data from external data sources may have a greater precision than Farrago. Whether data of greater precision should be replaced with null when it overflows due to the greater precision.

See Also:
Constant Field Values

SQUEEZE_JDBC_NUMERIC_DEFAULT

public static final String SQUEEZE_JDBC_NUMERIC_DEFAULT
See Also:
Constant Field Values

CACHE_STATEMENTS

public static final String CACHE_STATEMENTS
Whether statement caching is enabled for a session

See Also:
Constant Field Values

CACHE_STATEMENTS_DEFAULT

public static final String CACHE_STATEMENTS_DEFAULT
See Also:
Constant Field Values

VALIDATE_DDL_ON_PREPARE

public static final String VALIDATE_DDL_ON_PREPARE
Whether DDL validation should be done at prepare time

See Also:
Constant Field Values

VALIDATE_DDL_ON_PREPARE_DEFAULT

public static final String VALIDATE_DDL_ON_PREPARE_DEFAULT
See Also:
Constant Field Values

REDUCE_NON_CORRELATED_SUBQUERIES

public static final String REDUCE_NON_CORRELATED_SUBQUERIES
Whether non-correlated subqueries should be converted to constants

See Also:
Constant Field Values

REDUCE_NON_CORRELATED_SUBQUERIES_FARRAGO_DEFAULT

public static final String REDUCE_NON_CORRELATED_SUBQUERIES_FARRAGO_DEFAULT
See Also:
Constant Field Values

DEGREE_OF_PARALLELISM

public static final String DEGREE_OF_PARALLELISM
Degree of parallelism to use for parallel executor; a value of 1 (the default) causes the default non-parallel executor to be used.

See Also:
Constant Field Values

DEGREE_OF_PARALLELISM_DEFAULT

public static final String DEGREE_OF_PARALLELISM_DEFAULT
See Also:
Constant Field Values

LABEL

public static final String LABEL
The label for the current session

See Also:
Constant Field Values

LABEL_DEFAULT

public static final String LABEL_DEFAULT

database

protected final FarragoDatabase database

paramValidator

protected final FarragoDefaultSessionPersonality.ParamValidator paramValidator
Constructor Detail

FarragoDefaultSessionPersonality

protected FarragoDefaultSessionPersonality(FarragoDbSession session)
Method Detail

newPlanner

public FarragoSessionPlanner newPlanner(FarragoSessionPreparingStmt stmt,
                                        boolean init)
Description copied from interface: FarragoSessionPersonality
Creates a new planner.

Specified by:
newPlanner in interface FarragoSessionPersonality
Parameters:
stmt - stmt on whose behalf planner will operate
init - whether to initialize default rules in new planner
Returns:
new planner

definePlannerListeners

public void definePlannerListeners(FarragoSessionPlanner planner)
Description copied from interface: FarragoSessionPersonality
Defines listeners for events which occur during planning.

Specified by:
definePlannerListeners in interface FarragoSessionPersonality
Parameters:
planner - planner to which listeners should be added

registerStreamFactories

public void registerStreamFactories(long hStreamGraph)
Description copied from interface: FarragoStreamFactoryProvider
Registers factories for extension ExecStreams in Fennel.

Specified by:
registerStreamFactories in interface FarragoStreamFactoryProvider
Parameters:
hStreamGraph - native handle to unprepared stream graph

getDefaultLocalDataServerName

public String getDefaultLocalDataServerName(FarragoSessionStmtValidator stmtValidator)
Description copied from interface: FarragoSessionPersonality
Gets the name of the local data server to use for tables when none is specified by CREATE TABLE.

Specified by:
getDefaultLocalDataServerName in interface FarragoSessionPersonality
Parameters:
stmtValidator - validator for statement being prepared
Returns:
server name

isAlterTableAddColumnIncremental

public boolean isAlterTableAddColumnIncremental()
Description copied from interface: FarragoSessionPersonality
Tests whether this session personality implements ALTER TABLE ADD COLUMN in an incremental fashion (only adding on the new column as opposed to reformatting existing rows). For example, a column store can just create a new vertical partition; a smart row store may be able to transform old tuple formats during queries by filling in default values on the fly.

Specified by:
isAlterTableAddColumnIncremental in interface FarragoSessionPersonality
Returns:
true iff the incremental optimization is implemented

isJavaUdxRestartable

public boolean isJavaUdxRestartable()
Description copied from interface: FarragoSessionPersonality
Returns whether a JavaUDX is implemented as a restartable data source.

Specified by:
isJavaUdxRestartable in interface FarragoSessionPersonality
Returns:
true if a JavaUDXRel implementation is restartable.

getSqlOperatorTable

public SqlOperatorTable getSqlOperatorTable(FarragoSessionPreparingStmt preparingStmt)
Description copied from interface: FarragoSessionPersonality
Gets the SQL operator table to use for validating a statement.

Specified by:
getSqlOperatorTable in interface FarragoSessionPersonality
Parameters:
preparingStmt - statement being prepared
Returns:
table of builtin SQL operators and functions to use for validation; user-defined functions are not included here

getOJRexImplementorTable

public OJRexImplementorTable getOJRexImplementorTable(FarragoSessionPreparingStmt preparingStmt)
Description copied from interface: FarragoSessionPersonality
Gets the implementation table to use for compiling a statement that uses a Java calculator.

Specified by:
getOJRexImplementorTable in interface FarragoSessionPersonality
Parameters:
preparingStmt - statement being prepared
Returns:
table of implementations corresponding to result of FarragoSessionPersonality.getSqlOperatorTable(FarragoSessionPreparingStmt)

newComponentImpl

public <C> C newComponentImpl(Class<C> componentInterface)
Description copied from interface: FarragoSessionPersonality
Gets the component associated with the given Class object from the personality. If the personality does not support (or recognize) the component type, it returns null. The returned instance is guaranteed to be of type C or a subclass.

Specified by:
newComponentImpl in interface FarragoSessionPersonality
Parameters:
componentInterface - the interface desired
Returns:
an implementation of componentInterface or null

newParser

public FarragoSessionParser newParser(FarragoSession session)
Description copied from interface: FarragoSessionPersonality
Creates a new SQL parser.

Specified by:
newParser in interface FarragoSessionPersonality
Parameters:
session - session which will use the parser
Returns:
new parser

newPreparingStmt

public FarragoSessionPreparingStmt newPreparingStmt(FarragoSessionStmtValidator stmtValidator)
Specified by:
newPreparingStmt in interface FarragoSessionPersonality

newPreparingStmt

public FarragoSessionPreparingStmt newPreparingStmt(FarragoSessionStmtContext stmtContext,
                                                    FarragoSessionStmtValidator stmtValidator)
Description copied from interface: FarragoSessionPersonality
Creates a new preparing statement tied to this session and its underlying database. Used to construct and implement an internal query plan.

Specified by:
newPreparingStmt in interface FarragoSessionPersonality
Parameters:
stmtContext - embracing stmt context, if any; otherwise, null.
stmtValidator - generic stmt validator
Returns:
a new FarragoSessionPreparingStmt.

newPreparingStmt

public FarragoSessionPreparingStmt newPreparingStmt(FarragoSessionStmtContext stmtContext,
                                                    FarragoSessionStmtContext rootStmtContext,
                                                    FarragoSessionStmtValidator stmtValidator)
Description copied from interface: FarragoSessionPersonality
Creates a new preparing statement tied to this session and its underlying database. Used to construct and implement an internal query plan.

Specified by:
newPreparingStmt in interface FarragoSessionPersonality
Parameters:
stmtContext - embracing stmt context, if any; otherwise, null.
rootStmtContext - the root stmt context
stmtValidator - generic stmt validator
Returns:
a new FarragoSessionPreparingStmt.

initPreparingStmt

protected void initPreparingStmt(FarragoPreparingStmt stmt)

newDdlValidator

public FarragoSessionDdlValidator newDdlValidator(FarragoSessionStmtValidator stmtValidator)
Description copied from interface: FarragoSessionPersonality
Creates a new validator for DDL commands.

Specified by:
newDdlValidator in interface FarragoSessionPersonality
Parameters:
stmtValidator - generic stmt validator
Returns:
new validator

defineDdlHandlers

public void defineDdlHandlers(FarragoSessionDdlValidator ddlValidator,
                              List<DdlHandler> handlerList)
Description copied from interface: FarragoSessionPersonality
See FarragoSessionModelExtension.defineDdlHandlers(net.sf.farrago.session.FarragoSessionDdlValidator, java.util.List).

Specified by:
defineDdlHandlers in interface FarragoSessionPersonality
Parameters:
ddlValidator - validator which will invoke handlers
handlerList - receives handler objects in order in which they should be invoked

definePrivileges

public void definePrivileges(FarragoSessionPrivilegeMap map)
Description copied from interface: FarragoSessionPersonality
Defines privileges allowed on various object types.

Specified by:
definePrivileges in interface FarragoSessionPersonality
Parameters:
map - receives allowed privileges

defineTypePrivileges

private void defineTypePrivileges(FarragoSessionPrivilegeMap map,
                                  RefClass refClass,
                                  PrivilegedAction[] actions)

getRuntimeContextClass

public Class getRuntimeContextClass(FarragoSessionPreparingStmt preparingStmt)
Description copied from interface: FarragoSessionPersonality
Determines the class to use for runtime context.

Specified by:
getRuntimeContextClass in interface FarragoSessionPersonality
Parameters:
preparingStmt - stmt on whose behalf planner will operate
Returns:
runtime context class, which must implement FarragoSessionRuntimeContext

newRuntimeContext

public FarragoSessionRuntimeContext newRuntimeContext(FarragoSessionRuntimeParams params)
Description copied from interface: FarragoSessionPersonality
Creates a new runtime context. The object returned must be assignable to the result of getRuntimeContextClass().

Specified by:
newRuntimeContext in interface FarragoSessionPersonality
Parameters:
params - context initialization parameters
Returns:
new context

newTypeFactory

public RelDataTypeFactory newTypeFactory(FarragoRepos repos)
Description copied from interface: FarragoSessionPersonality
Creates a new type factory.

Specified by:
newTypeFactory in interface FarragoSessionPersonality
Parameters:
repos - a repository containing Farrago metadata
Returns:
a new type factory

loadDefaultSessionVariables

public void loadDefaultSessionVariables(FarragoSessionVariables variables)
Description copied from interface: FarragoSessionPersonality
Loads variables from the session personality into a session variables object. Each personality uses on its own variables. This method allows the personality to declare its variables and set default values for them. If any variables already have values, then they will not be overwritten.

This method should be called when initializing a new session or when loading a new session personality for an existing session. This method "leaves a mark", as it has the side effect of permanently updating the session variables. Even if the session personality is swapped out, the changes will remain.

Specified by:
loadDefaultSessionVariables in interface FarragoSessionPersonality
Parameters:
variables - the session variables object

createInheritedSessionVariables

public FarragoSessionVariables createInheritedSessionVariables(FarragoSessionVariables variables)
Description copied from interface: FarragoSessionPersonality
Creates a set of session variables for use in a cloned session. Default implementation is to just return variables.cloneVariables(), but personalities may override, e.g. to reset some variables which should never be inherited.

Specified by:
createInheritedSessionVariables in interface FarragoSessionPersonality
Parameters:
variables - set of variables to be inherited
Returns:
result of variable inheritance

validateSessionVariable

public void validateSessionVariable(FarragoSessionDdlValidator ddlValidator,
                                    FarragoSessionVariables variables,
                                    String name,
                                    String value)
Description copied from interface: FarragoSessionPersonality
Checks whether a parameter value is appropriate for a session variable and, if the value is appropriate, sets the session variable. If an error is encountered, then the method throws an EigenbaseException. Possible errors include when no session variable has the specified name, when a non-numeric value was specified for a numeric variable, when a directory does not exist, or other errors.

Specified by:
validateSessionVariable in interface FarragoSessionPersonality
Parameters:
ddlValidator - a ddl statement validator
variables - a session variables object
name - name of the session variable to be validated
value - value to set for the session variable

newJmiQueryProcessor

public JmiQueryProcessor newJmiQueryProcessor(String language)
Description copied from interface: FarragoSessionPersonality
Creates a new processor for JMI queries.

Specified by:
newJmiQueryProcessor in interface FarragoSessionPersonality
Parameters:
language - query language (e.g. "LURQL")
Returns:
query processor, or null if language not supported

isSupportedType

public boolean isSupportedType(SqlTypeName type)
Description copied from interface: FarragoSessionPersonality
Returns whether a type is valid in this database.

Specified by:
isSupportedType in interface FarragoSessionPersonality
Parameters:
type - Type
Returns:
whether a type is valid in this database

supportsFeature

public boolean supportsFeature(org.eigenbase.resgen.ResourceDefinition feature)
Description copied from interface: FarragoSessionPersonality
Tests whether a feature is supported in this personality.

Specified by:
supportsFeature in interface FarragoSessionPersonality
Parameters:
feature - EigenbaseResource resource definition representing the feature to be tested
Returns:
true iff feature is supported

shouldReplacePreserveOriginalSql

public boolean shouldReplacePreserveOriginalSql()
Description copied from interface: FarragoSessionPersonality
Tests whether this personality wants original SQL to be preserved for dependent objects where possible during the revalidation triggered by CREATE OR REPLACE.

Specified by:
shouldReplacePreserveOriginalSql in interface FarragoSessionPersonality
Returns:
true iff an attempt should be made to preserve original SQL

registerRelMetadataProviders

public void registerRelMetadataProviders(ChainedRelMetadataProvider chain)
Description copied from interface: FarragoSessionPersonality
Gives this personality a chance to register one or more RelMetadataProviders in the chain which will be used to answer relational expression metadata queries during optimization. Personalities which define their own relational expressions will generally need to supply corresponding metadata providers.

Specified by:
registerRelMetadataProviders in interface FarragoSessionPersonality
Parameters:
chain - receives personality's custom providers, if any

getRowCounts

public void getRowCounts(ResultSet resultSet,
                         List<Long> rowCounts,
                         TableModificationRelBase.Operation tableModOp)
                  throws SQLException
Description copied from interface: FarragoSessionPersonality
Gives this personality the opportunity to retrieve rowcount information returned by a DML operation.

Specified by:
getRowCounts in interface FarragoSessionPersonality
Parameters:
resultSet - result set returned by DML operation
rowCounts - list of rowcounts returned by the DML operation
tableModOp - table modification operation that caused the rowcounts to be modified
Throws:
SQLException

addRowCount

protected boolean addRowCount(ResultSet resultSet,
                              List<Long> rowCounts)
                       throws SQLException
Throws:
SQLException

updateRowCounts

public long updateRowCounts(FarragoSession session,
                            List<String> tableName,
                            List<Long> rowCounts,
                            TableModificationRelBase.Operation tableModOp,
                            FarragoSessionRuntimeContext runningContext)
Description copied from interface: FarragoSessionPersonality
Gives this personality the opportunity to update rowcount information in the catalog tables for a specified table as a result of a particular DML operation.

Specified by:
updateRowCounts in interface FarragoSessionPersonality
Parameters:
session - session that needs to update rowcounts
tableName - fully qualified table name for which rowcounts will be updated
rowCounts - list of row counts returned by the DML statement
tableModOp - table modification operation that caused the rowcounts to be modified
runningContext - the currently running session context.
Returns:
number of rows affected by the DML operation

resetRowCounts

public void resetRowCounts(FemAbstractColumnSet table)
Description copied from interface: FarragoSessionPersonality
Gives this personality the opportunity to reset rowcount information in the catalog tables for a specified table

Specified by:
resetRowCounts in interface FarragoSessionPersonality
Parameters:
table - column set corresponding to table

updateIndexRoot

public void updateIndexRoot(FemLocalIndex index,
                            FarragoDataWrapperCache wrapperCache,
                            FarragoSessionIndexMap baseIndexMap,
                            Long newRoot)
Description copied from interface: FarragoSessionPersonality
Gives the personality the opportunity to update an index root page when the index is rebuilt

Specified by:
updateIndexRoot in interface FarragoSessionPersonality
Parameters:
index - index whose root is being updated
wrapperCache - cache for looking up data wrappers
baseIndexMap - map for managing index storage
newRoot - index's new root page