Package org.apache.calcite.tools
Interface Planner
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
PlannerImpl
A façade that covers Calcite's query planning process: parse SQL,
validate the parse tree, convert the parse tree to a relational expression,
and optimize the relational expression.
Planner is NOT thread safe. However, it can be reused for different queries. The consumer of this interface is responsible for calling reset() after each use of Planner that corresponds to a different query.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Releases all internal resources utilized while thisPlanner
exists.Deprecated.Returns a record type that contains the name and type of each parameter.Returns the type factory.Parses and validates a SQL statement.default SqlNode
Parses and validates a SQL statement.Converts a SQL parse tree into a tree of relational expressions.void
reset()
Resets thisPlanner
to be used with a new query.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.Validates a SQL statement.validateAndGetType
(SqlNode sqlNode) Validates a SQL statement.
-
Method Details
-
parse
Parses and validates a SQL statement.- Parameters:
sql
- The SQL statement to parse.- Returns:
- The root node of the SQL parse tree.
- Throws:
SqlParseException
- on parse error
-
parse
Parses and validates a SQL statement.- Parameters:
source
- 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
Validates a SQL statement.- Parameters:
sqlNode
- Root node of the SQL parse tree.- Returns:
- Validated node
- Throws:
ValidationException
- if not valid
-
validateAndGetType
Validates a SQL statement.- Parameters:
sqlNode
- Root node of the SQL parse tree.- Returns:
- Validated node and its validated type.
- Throws:
ValidationException
- if not valid
-
getParameterRowType
RelDataType getParameterRowType()Returns a record type that contains the name and type of each parameter. Returns a record type with no fields if there are no parameters.- Returns:
- Record type
-
rel
Converts a SQL parse tree into a tree of relational expressions.You must call
validate(org.apache.calcite.sql.SqlNode)
first.- 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
-
convert
Deprecated.- Throws:
RelConversionException
-
getTypeFactory
RelDataTypeFactory getTypeFactory()Returns the type factory. -
transform
RelNode transform(int ruleSetIndex, RelTraitSet requiredOutputTraits, RelNode rel) throws RelConversionException Converts one relational expression tree into another relational expression based on a particular rule set and requires set of traits.- 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
-
reset
void reset()Resets thisPlanner
to be used with a new query. This should be called between each new query. -
close
void close()Releases all internal resources utilized while thisPlanner
exists. Once called, this Planner object is no longer valid.- Specified by:
close
in interfaceAutoCloseable
-
getEmptyTraitSet
RelTraitSet getEmptyTraitSet()
-
rel(org.apache.calcite.sql.SqlNode)
.