Package org.apache.calcite.test
Class SqlToRelTestBase.TesterImpl
- java.lang.Object
-
- org.apache.calcite.test.SqlToRelTestBase.TesterImpl
-
- All Implemented Interfaces:
SqlToRelTestBase.Tester
- Enclosing class:
- SqlToRelTestBase
public static class SqlToRelTestBase.TesterImpl extends java.lang.Object implements SqlToRelTestBase.Tester
Default implementation ofSqlToRelTestBase.Tester
, using mock classesSqlToRelTestBase.MockRelOptSchema
andMockRelOptPlanner
.
-
-
Field Summary
Fields Modifier and Type Field Description private SqlTestFactory.MockCatalogReaderFactory
catalogReaderFactory
private java.util.function.Function<org.apache.calcite.plan.RelOptCluster,org.apache.calcite.plan.RelOptCluster>
clusterFactory
org.apache.calcite.sql2rel.SqlToRelConverter.Config
config
private org.apache.calcite.sql.validate.SqlConformance
conformance
private org.apache.calcite.plan.Context
context
private DiffRepository
diffRepos
private boolean
enableDecorrelate
private boolean
enableExpand
private boolean
enableLateDecorrelate
private boolean
enableTrim
private org.apache.calcite.sql.SqlOperatorTable
opTab
private org.apache.calcite.plan.RelOptPlanner
planner
private org.apache.calcite.rel.type.RelDataTypeFactory
typeFactory
-
Constructor Summary
Constructors Modifier Constructor Description protected
TesterImpl(DiffRepository diffRepos, boolean enableDecorrelate, boolean enableTrim, boolean enableExpand, boolean enableLateDecorrelate, SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory, java.util.function.Function<org.apache.calcite.plan.RelOptCluster,org.apache.calcite.plan.RelOptCluster> clusterFactory)
Creates a TesterImpl.protected
TesterImpl(DiffRepository diffRepos, boolean enableDecorrelate, boolean enableTrim, boolean enableExpand, boolean enableLateDecorrelate, SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory, java.util.function.Function<org.apache.calcite.plan.RelOptCluster,org.apache.calcite.plan.RelOptCluster> clusterFactory, org.apache.calcite.sql2rel.SqlToRelConverter.Config config, org.apache.calcite.sql.validate.SqlConformance conformance, org.apache.calcite.plan.Context context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertConvertsTo(java.lang.String sql, java.lang.String plan)
Checks that a SQL statement converts to a given plan.void
assertConvertsTo(java.lang.String sql, java.lang.String plan, boolean trim)
Checks that a SQL statement converts to a given plan, optionally trimming columns that are not needed.org.apache.calcite.rel.RelRoot
convertSqlToRel(java.lang.String sql)
Converts a SQL string to aRelNode
tree.org.apache.calcite.prepare.Prepare.CatalogReader
createCatalogReader(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory)
Factory method for aPrepare.CatalogReader
.org.apache.calcite.sql2rel.RelFieldTrimmer
createFieldTrimmer(org.apache.calcite.tools.RelBuilder relBuilder)
Creates a RelFieldTrimmer.protected org.apache.calcite.sql.SqlOperatorTable
createOperatorTable()
Creates an operator table.org.apache.calcite.plan.RelOptPlanner
createPlanner()
protected org.apache.calcite.sql2rel.SqlToRelConverter
createSqlToRelConverter(org.apache.calcite.sql.validate.SqlValidator validator, org.apache.calcite.prepare.Prepare.CatalogReader catalogReader, org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.sql2rel.SqlToRelConverter.Config config)
protected org.apache.calcite.rel.type.RelDataTypeFactory
createTypeFactory()
org.apache.calcite.sql.validate.SqlValidator
createValidator(org.apache.calcite.sql.validate.SqlValidatorCatalogReader catalogReader, org.apache.calcite.rel.type.RelDataTypeFactory typeFactory)
Factory method to create aSqlValidator
.org.apache.calcite.sql.validate.SqlConformance
getConformance()
Returns the SQL dialect to test.DiffRepository
getDiffRepos()
Returns the diff repository.org.apache.calcite.sql.SqlOperatorTable
getOperatorTable()
Returns theSqlOperatorTable
to use.protected org.apache.calcite.plan.RelOptPlanner
getPlanner()
protected org.apache.calcite.rel.type.RelDataTypeFactory
getTypeFactory()
org.apache.calcite.sql.validate.SqlValidator
getValidator()
Returns the validator.boolean
isLateDecorrelate()
org.apache.calcite.sql.SqlNode
parseQuery(java.lang.String sql)
SqlToRelTestBase.Tester
withCatalogReaderFactory(SqlTestFactory.MockCatalogReaderFactory factory)
SqlToRelTestBase.Tester
withClusterFactory(java.util.function.Function<org.apache.calcite.plan.RelOptCluster,org.apache.calcite.plan.RelOptCluster> clusterFactory)
SqlToRelTestBase.TesterImpl
withConfig(org.apache.calcite.sql2rel.SqlToRelConverter.Config config)
Returns a tester that optionally uses aSqlToRelConverter.Config
.SqlToRelTestBase.Tester
withConformance(org.apache.calcite.sql.validate.SqlConformance conformance)
Returns a tester with aSqlConformance
.SqlToRelTestBase.Tester
withContext(org.apache.calcite.plan.Context context)
Returns a tester that uses a given context.SqlToRelTestBase.TesterImpl
withDecorrelation(boolean enableDecorrelate)
Returns a tester that optionally decorrelates queries.SqlToRelTestBase.Tester
withExpand(boolean enableExpand)
Returns a tester that optionally expands sub-queries.SqlToRelTestBase.Tester
withLateDecorrelation(boolean enableLateDecorrelate)
Returns a tester that optionally decorrelates queries after planner rules have fired.SqlToRelTestBase.Tester
withTrim(boolean enableTrim)
Returns a tester that optionally trims unused fields.
-
-
-
Field Detail
-
planner
private org.apache.calcite.plan.RelOptPlanner planner
-
opTab
private org.apache.calcite.sql.SqlOperatorTable opTab
-
diffRepos
private final DiffRepository diffRepos
-
enableDecorrelate
private final boolean enableDecorrelate
-
enableLateDecorrelate
private final boolean enableLateDecorrelate
-
enableTrim
private final boolean enableTrim
-
enableExpand
private final boolean enableExpand
-
conformance
private final org.apache.calcite.sql.validate.SqlConformance conformance
-
catalogReaderFactory
private final SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory
-
clusterFactory
private final java.util.function.Function<org.apache.calcite.plan.RelOptCluster,org.apache.calcite.plan.RelOptCluster> clusterFactory
-
typeFactory
private org.apache.calcite.rel.type.RelDataTypeFactory typeFactory
-
config
public final org.apache.calcite.sql2rel.SqlToRelConverter.Config config
-
context
private final org.apache.calcite.plan.Context context
-
-
Constructor Detail
-
TesterImpl
protected TesterImpl(DiffRepository diffRepos, boolean enableDecorrelate, boolean enableTrim, boolean enableExpand, boolean enableLateDecorrelate, SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory, java.util.function.Function<org.apache.calcite.plan.RelOptCluster,org.apache.calcite.plan.RelOptCluster> clusterFactory)
Creates a TesterImpl.- Parameters:
diffRepos
- Diff repositoryenableDecorrelate
- Whether to decorrelateenableTrim
- Whether to trim unused fieldsenableExpand
- Whether to expand sub-queriescatalogReaderFactory
- Function to create catalog reader, or nullclusterFactory
- Called after a cluster has been created
-
TesterImpl
protected TesterImpl(DiffRepository diffRepos, boolean enableDecorrelate, boolean enableTrim, boolean enableExpand, boolean enableLateDecorrelate, SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory, java.util.function.Function<org.apache.calcite.plan.RelOptCluster,org.apache.calcite.plan.RelOptCluster> clusterFactory, org.apache.calcite.sql2rel.SqlToRelConverter.Config config, org.apache.calcite.sql.validate.SqlConformance conformance, org.apache.calcite.plan.Context context)
-
-
Method Detail
-
convertSqlToRel
public org.apache.calcite.rel.RelRoot convertSqlToRel(java.lang.String sql)
Description copied from interface:SqlToRelTestBase.Tester
Converts a SQL string to aRelNode
tree.- Specified by:
convertSqlToRel
in interfaceSqlToRelTestBase.Tester
- Parameters:
sql
- SQL statement- Returns:
- Relational expression, never null
-
createSqlToRelConverter
protected org.apache.calcite.sql2rel.SqlToRelConverter createSqlToRelConverter(org.apache.calcite.sql.validate.SqlValidator validator, org.apache.calcite.prepare.Prepare.CatalogReader catalogReader, org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.sql2rel.SqlToRelConverter.Config config)
-
getTypeFactory
protected final org.apache.calcite.rel.type.RelDataTypeFactory getTypeFactory()
-
createTypeFactory
protected org.apache.calcite.rel.type.RelDataTypeFactory createTypeFactory()
-
getPlanner
protected final org.apache.calcite.plan.RelOptPlanner getPlanner()
-
parseQuery
public org.apache.calcite.sql.SqlNode parseQuery(java.lang.String sql) throws java.lang.Exception
- Specified by:
parseQuery
in interfaceSqlToRelTestBase.Tester
- Throws:
java.lang.Exception
-
getConformance
public org.apache.calcite.sql.validate.SqlConformance getConformance()
Description copied from interface:SqlToRelTestBase.Tester
Returns the SQL dialect to test.- Specified by:
getConformance
in interfaceSqlToRelTestBase.Tester
-
createValidator
public org.apache.calcite.sql.validate.SqlValidator createValidator(org.apache.calcite.sql.validate.SqlValidatorCatalogReader catalogReader, org.apache.calcite.rel.type.RelDataTypeFactory typeFactory)
Description copied from interface:SqlToRelTestBase.Tester
Factory method to create aSqlValidator
.- Specified by:
createValidator
in interfaceSqlToRelTestBase.Tester
-
getOperatorTable
public final org.apache.calcite.sql.SqlOperatorTable getOperatorTable()
Description copied from interface:SqlToRelTestBase.Tester
Returns theSqlOperatorTable
to use.- Specified by:
getOperatorTable
in interfaceSqlToRelTestBase.Tester
-
createOperatorTable
protected org.apache.calcite.sql.SqlOperatorTable createOperatorTable()
Creates an operator table.- Returns:
- New operator table
-
createCatalogReader
public org.apache.calcite.prepare.Prepare.CatalogReader createCatalogReader(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory)
Description copied from interface:SqlToRelTestBase.Tester
Factory method for aPrepare.CatalogReader
.- Specified by:
createCatalogReader
in interfaceSqlToRelTestBase.Tester
-
createPlanner
public org.apache.calcite.plan.RelOptPlanner createPlanner()
- Specified by:
createPlanner
in interfaceSqlToRelTestBase.Tester
-
assertConvertsTo
public void assertConvertsTo(java.lang.String sql, java.lang.String plan)
Description copied from interface:SqlToRelTestBase.Tester
Checks that a SQL statement converts to a given plan.- Specified by:
assertConvertsTo
in interfaceSqlToRelTestBase.Tester
- Parameters:
sql
- SQL queryplan
- Expected plan
-
assertConvertsTo
public void assertConvertsTo(java.lang.String sql, java.lang.String plan, boolean trim)
Description copied from interface:SqlToRelTestBase.Tester
Checks that a SQL statement converts to a given plan, optionally trimming columns that are not needed.- Specified by:
assertConvertsTo
in interfaceSqlToRelTestBase.Tester
- Parameters:
sql
- SQL queryplan
- Expected plantrim
- Whether to trim columns that are not needed
-
createFieldTrimmer
public org.apache.calcite.sql2rel.RelFieldTrimmer createFieldTrimmer(org.apache.calcite.tools.RelBuilder relBuilder)
Creates a RelFieldTrimmer.- Parameters:
relBuilder
- Builder- Returns:
- Field trimmer
-
getDiffRepos
public DiffRepository getDiffRepos()
Description copied from interface:SqlToRelTestBase.Tester
Returns the diff repository.- Specified by:
getDiffRepos
in interfaceSqlToRelTestBase.Tester
- Returns:
- Diff repository
-
getValidator
public org.apache.calcite.sql.validate.SqlValidator getValidator()
Description copied from interface:SqlToRelTestBase.Tester
Returns the validator.- Specified by:
getValidator
in interfaceSqlToRelTestBase.Tester
- Returns:
- Validator
-
withDecorrelation
public SqlToRelTestBase.TesterImpl withDecorrelation(boolean enableDecorrelate)
Description copied from interface:SqlToRelTestBase.Tester
Returns a tester that optionally decorrelates queries.- Specified by:
withDecorrelation
in interfaceSqlToRelTestBase.Tester
-
withLateDecorrelation
public SqlToRelTestBase.Tester withLateDecorrelation(boolean enableLateDecorrelate)
Description copied from interface:SqlToRelTestBase.Tester
Returns a tester that optionally decorrelates queries after planner rules have fired.- Specified by:
withLateDecorrelation
in interfaceSqlToRelTestBase.Tester
-
withConfig
public SqlToRelTestBase.TesterImpl withConfig(org.apache.calcite.sql2rel.SqlToRelConverter.Config config)
Description copied from interface:SqlToRelTestBase.Tester
Returns a tester that optionally uses aSqlToRelConverter.Config
.- Specified by:
withConfig
in interfaceSqlToRelTestBase.Tester
-
withTrim
public SqlToRelTestBase.Tester withTrim(boolean enableTrim)
Description copied from interface:SqlToRelTestBase.Tester
Returns a tester that optionally trims unused fields.- Specified by:
withTrim
in interfaceSqlToRelTestBase.Tester
-
withExpand
public SqlToRelTestBase.Tester withExpand(boolean enableExpand)
Description copied from interface:SqlToRelTestBase.Tester
Returns a tester that optionally expands sub-queries. Ifexpand
is false, the plan contains aRexSubQuery
for each sub-query.- Specified by:
withExpand
in interfaceSqlToRelTestBase.Tester
- See Also:
Prepare.THREAD_EXPAND
-
withConformance
public SqlToRelTestBase.Tester withConformance(org.apache.calcite.sql.validate.SqlConformance conformance)
Description copied from interface:SqlToRelTestBase.Tester
Returns a tester with aSqlConformance
.- Specified by:
withConformance
in interfaceSqlToRelTestBase.Tester
-
withCatalogReaderFactory
public SqlToRelTestBase.Tester withCatalogReaderFactory(SqlTestFactory.MockCatalogReaderFactory factory)
- Specified by:
withCatalogReaderFactory
in interfaceSqlToRelTestBase.Tester
-
withClusterFactory
public SqlToRelTestBase.Tester withClusterFactory(java.util.function.Function<org.apache.calcite.plan.RelOptCluster,org.apache.calcite.plan.RelOptCluster> clusterFactory)
- Specified by:
withClusterFactory
in interfaceSqlToRelTestBase.Tester
-
withContext
public SqlToRelTestBase.Tester withContext(org.apache.calcite.plan.Context context)
Description copied from interface:SqlToRelTestBase.Tester
Returns a tester that uses a given context.- Specified by:
withContext
in interfaceSqlToRelTestBase.Tester
-
isLateDecorrelate
public boolean isLateDecorrelate()
- Specified by:
isLateDecorrelate
in interfaceSqlToRelTestBase.Tester
-
-