Package org.apache.calcite.prepare
Class PlannerImpl
- java.lang.Object
-
- org.apache.calcite.prepare.PlannerImpl
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,RelOptTable.ViewExpander
,Planner
public class PlannerImpl extends java.lang.Object implements Planner, RelOptTable.ViewExpander
Implementation ofPlanner
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PlannerImpl.State
Stage of a statement in the query-preparation lifecycle.class
PlannerImpl.ViewExpanderImpl
Deprecated.NowPlannerImpl
implementsRelOptTable.ViewExpander
directly.
-
Field Summary
Fields Modifier and Type Field Description private FrameworkConfig
config
private SqlRexConvertletTable
convertletTable
private SchemaPlus
defaultSchema
private RexExecutor
executor
private boolean
open
private SqlOperatorTable
operatorTable
private SqlParser.Config
parserConfig
private RelOptPlanner
planner
private com.google.common.collect.ImmutableList<Program>
programs
private RelRoot
root
private SqlToRelConverter.Config
sqlToRelConverterConfig
private PlannerImpl.State
state
private com.google.common.collect.ImmutableList<RelTraitDef>
traitDefs
Holds the trait definitions to be registered with planner.private JavaTypeFactory
typeFactory
private SqlNode
validatedSqlNode
private CalciteSqlValidator
validator
-
Constructor Summary
Constructors Constructor Description PlannerImpl(FrameworkConfig config)
Creates a planner.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Releases all internal resources utilized while thisPlanner
exists.private SqlConformance
conformance()
RelNode
convert(SqlNode sql)
private CalciteCatalogReader
createCatalogReader()
private RexBuilder
createRexBuilder()
private void
ensure(PlannerImpl.State state)
Makes sure that the state is at least the given state.RelRoot
expandView(RelDataType rowType, java.lang.String queryString, java.util.List<java.lang.String> schemaPath, java.util.List<java.lang.String> viewPath)
Returns a relational expression that is to be substituted for an access to a SQL view.RelTraitSet
getEmptyTraitSet()
JavaTypeFactory
getTypeFactory()
Returns the type factory.SqlNode
parse(java.io.Reader reader)
Parses and validates a SQL statement.private void
ready()
RelRoot
rel(SqlNode sql)
Converts a SQL parse tree into a tree of relational expressions.void
reset()
Resets thisPlanner
to be used with a new query.private static SchemaPlus
rootSchema(SchemaPlus schema)
RelNode
transform(int ruleSetIndex, RelTraitSet requiredOutputTraits, RelNode rel)
Converts one relational expression tree into another relational expression based on a particular rule set and requires set of traits.SqlNode
validate(SqlNode sqlNode)
Validates a SQL statement.Pair<SqlNode,RelDataType>
validateAndGetType(SqlNode sqlNode)
Validates a SQL statement.
-
-
-
Field Detail
-
operatorTable
private final SqlOperatorTable operatorTable
-
programs
private final com.google.common.collect.ImmutableList<Program> programs
-
config
private final FrameworkConfig config
-
traitDefs
private final com.google.common.collect.ImmutableList<RelTraitDef> traitDefs
Holds the trait definitions to be registered with planner. May be null.
-
parserConfig
private final SqlParser.Config parserConfig
-
sqlToRelConverterConfig
private final SqlToRelConverter.Config sqlToRelConverterConfig
-
convertletTable
private final SqlRexConvertletTable convertletTable
-
state
private PlannerImpl.State state
-
open
private boolean open
-
defaultSchema
private SchemaPlus defaultSchema
-
typeFactory
private JavaTypeFactory typeFactory
-
planner
private RelOptPlanner planner
-
executor
private RexExecutor executor
-
validator
private CalciteSqlValidator validator
-
validatedSqlNode
private SqlNode validatedSqlNode
-
root
private RelRoot root
-
-
Constructor Detail
-
PlannerImpl
public PlannerImpl(FrameworkConfig config)
Creates a planner. Not a public API; callFrameworks.getPlanner(org.apache.calcite.tools.FrameworkConfig)
instead.
-
-
Method Detail
-
ensure
private void ensure(PlannerImpl.State state)
Makes sure that the state is at least the given state.
-
getEmptyTraitSet
public RelTraitSet getEmptyTraitSet()
- Specified by:
getEmptyTraitSet
in interfacePlanner
-
close
public void close()
Description copied from interface:Planner
Releases all internal resources utilized while thisPlanner
exists. Once called, this Planner object is no longer valid.
-
reset
public void reset()
Description copied from interface:Planner
Resets thisPlanner
to be used with a new query. This should be called between each new query.
-
ready
private void ready()
-
parse
public SqlNode parse(java.io.Reader reader) throws SqlParseException
Description copied from interface:Planner
Parses and validates a SQL statement.- Specified by:
parse
in interfacePlanner
- Parameters:
reader
- A reader which will provide the SQL statement to parse.- Returns:
- The root node of the SQL parse tree.
- Throws:
SqlParseException
- on parse error
-
validate
public SqlNode validate(SqlNode sqlNode) throws ValidationException
Description copied from interface:Planner
Validates a SQL statement.- Specified by:
validate
in interfacePlanner
- Parameters:
sqlNode
- Root node of the SQL parse tree.- Returns:
- Validated node
- Throws:
ValidationException
- if not valid
-
conformance
private SqlConformance conformance()
-
validateAndGetType
public Pair<SqlNode,RelDataType> validateAndGetType(SqlNode sqlNode) throws ValidationException
Description copied from interface:Planner
Validates a SQL statement.- Specified by:
validateAndGetType
in interfacePlanner
- Parameters:
sqlNode
- Root node of the SQL parse tree.- Returns:
- Validated node and its validated type.
- Throws:
ValidationException
- if not valid
-
convert
public final RelNode convert(SqlNode sql) throws RelConversionException
- Specified by:
convert
in interfacePlanner
- Throws:
RelConversionException
-
rel
public RelRoot rel(SqlNode sql) throws RelConversionException
Description copied from interface:Planner
Converts a SQL parse tree into a tree of relational expressions.You must call
Planner.validate(org.apache.calcite.sql.SqlNode)
first.- Specified by:
rel
in interfacePlanner
- Parameters:
sql
- The root node of the SQL parse tree.- Returns:
- The root node of the newly generated RelNode tree.
- Throws:
RelConversionException
- if the node cannot be converted or has not been validated
-
expandView
public RelRoot expandView(RelDataType rowType, java.lang.String queryString, java.util.List<java.lang.String> schemaPath, java.util.List<java.lang.String> viewPath)
Description copied from interface:RelOptTable.ViewExpander
Returns a relational expression that is to be substituted for an access to a SQL view.- Specified by:
expandView
in interfaceRelOptTable.ViewExpander
- Parameters:
rowType
- Row type of the viewqueryString
- Body of the viewschemaPath
- Path of a schema wherein to find referenced tablesviewPath
- Path of the view, ending with its name; may be null- Returns:
- Relational expression
-
createCatalogReader
private CalciteCatalogReader createCatalogReader()
-
rootSchema
private static SchemaPlus rootSchema(SchemaPlus schema)
-
createRexBuilder
private RexBuilder createRexBuilder()
-
getTypeFactory
public JavaTypeFactory getTypeFactory()
Description copied from interface:Planner
Returns the type factory.- Specified by:
getTypeFactory
in interfacePlanner
-
transform
public RelNode transform(int ruleSetIndex, RelTraitSet requiredOutputTraits, RelNode rel) throws RelConversionException
Description copied from interface:Planner
Converts one relational expression tree into another relational expression based on a particular rule set and requires set of traits.- Specified by:
transform
in interfacePlanner
- Parameters:
ruleSetIndex
- The RuleSet to use for conversion purposes. Note that this is zero-indexed and is based on the list and order of RuleSets provided in the construction of this Planner.requiredOutputTraits
- The set of RelTraits required of the root node at the termination of the planning cycle.rel
- The root of the RelNode tree to convert.- Returns:
- The root of the new RelNode tree.
- Throws:
RelConversionException
- on conversion error
-
-