本文整理汇总了Java中org.apache.calcite.plan.hep.HepPlanner类的典型用法代码示例。如果您正苦于以下问题:Java HepPlanner类的具体用法?Java HepPlanner怎么用?Java HepPlanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HepPlanner类属于org.apache.calcite.plan.hep包,在下文中一共展示了HepPlanner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: substitute
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/**
* Normalizes the given query and target {@link RelNode}s and finds substitutions on canonical
* representations.
*
* @param query incoming query
* @param materialization materialization to apply
* @return list of substitutions
*/
protected List<Substitution> substitute(RelNode query,
final RelOptMaterialization materialization) {
// First, if the materialization is in terms of a star table, rewrite
// the query in terms of the star table.
if (materialization.starTable != null) {
final RelNode newRoot = RelOptMaterialization.tryUseStar(query,
materialization.starRelOptTable);
if (newRoot != null) {
query = newRoot;
}
}
// Push filters to the bottom, and combine projects on top.
final HepProgram program = getProgramBuilder().build();
final HepPlanner hepPlanner = new HepPlanner(program);
hepPlanner.setRoot(materialization.queryRel);
final RelNode canonicalTarget = hepPlanner.findBestExp();
hepPlanner.setRoot(query);
final RelNode canonicalQuery = hepPlanner.findBestExp();
return substitute(canonicalQuery, canonicalTarget, materialization.tableRel);
}
开发者ID:dremio,项目名称:dremio-oss,代码行数:33,代码来源:UnifyingSubstitutionProvider.java
示例2: decorrelate
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
private RelNode decorrelate(RelNode root) {
// first adjust count() expression if any
HepProgram program = HepProgram.builder().addRuleInstance(new AdjustProjectForCountAggregateRule(false)).addRuleInstance(new AdjustProjectForCountAggregateRule(true)).addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterCorrelateRule.INSTANCE).build();
HepPlanner planner = createPlanner(program);
planner.setRoot(root);
root = planner.findBestExp();
// Perform decorrelation.
map.clear();
final Frame frame = getInvoke(root, null);
if (frame != null) {
// has been rewritten; apply rules post-decorrelation
final HepProgram program2 = HepProgram.builder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).build();
final HepPlanner planner2 = createPlanner(program2);
final RelNode newRoot = frame.r;
planner2.setRoot(newRoot);
return planner2.findBestExp();
}
return root;
}
开发者ID:axbaretto,项目名称:flink,代码行数:26,代码来源:FlinkRelDecorrelator.java
示例3: getParsedSql
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
public static String getParsedSql(RelNode relNode, SqlDialect dialect) throws SQLException {
if (dialect.getDatabaseProduct() == SqlDialect.DatabaseProduct.HIVE) {
final HepProgram program = new HepProgramBuilder()
.addRuleInstance(JoinCalcTransposeRule.LEFT_CALC)
.addRuleInstance(JoinCalcTransposeRule.RIGHT_CALC)
.addRuleInstance(CalcMergeRule.INSTANCE)
.build();
final RelOptPlanner planner = relNode.getCluster().getPlanner();
final HepPlanner hepPlanner =
new HepPlanner(program, planner.getContext());
hepPlanner.setRoot(relNode);
relNode = hepPlanner.findBestExp();
}
RelToSqlConverter relToSqlConverter = new RelToSqlConverter(dialect);
RelToSqlConverter.Result res = relToSqlConverter.visitChild(0, relNode);
SqlNode sqlNode = res.asQuery();
String result = sqlNode.toSqlString(dialect, false).getSql();
return result.replace("\n", " ");
}
开发者ID:qubole,项目名称:quark,代码行数:20,代码来源:ResultProcessor.java
示例4: of
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/** Creates a program that executes a {@link HepProgram}. */
public static Program of(final HepProgram hepProgram, final boolean noDag,
final RelMetadataProvider metadataProvider) {
return new Program() {
public RelNode run(RelOptPlanner planner, RelNode rel,
RelTraitSet requiredOutputTraits,
List<RelOptMaterialization> materializations,
List<RelOptLattice> lattices) {
final HepPlanner hepPlanner = new HepPlanner(hepProgram,
null, noDag, null, RelOptCostImpl.FACTORY);
List<RelMetadataProvider> list = Lists.newArrayList();
if (metadataProvider != null) {
list.add(metadataProvider);
}
hepPlanner.registerMetadataProviders(list);
RelMetadataProvider plannerChain =
ChainedRelMetadataProvider.of(list);
rel.getCluster().setMetadataProvider(plannerChain);
hepPlanner.setRoot(rel);
return hepPlanner.findBestExp();
}
};
}
开发者ID:apache,项目名称:kylin,代码行数:26,代码来源:Programs.java
示例5: of
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/** Creates a program that executes a {@link HepProgram}. */
public static Program of(final HepProgram hepProgram, final boolean noDag,
final RelMetadataProvider metadataProvider) {
return new Program() {
public RelNode run(RelOptPlanner planner, RelNode rel,
RelTraitSet requiredOutputTraits,
List<RelOptMaterialization> materializations,
List<RelOptLattice> lattices) {
final HepPlanner hepPlanner = new HepPlanner(hepProgram,
null, noDag, null, RelOptCostImpl.FACTORY);
List<RelMetadataProvider> list = Lists.newArrayList();
if (metadataProvider != null) {
list.add(metadataProvider);
}
hepPlanner.registerMetadataProviders(list);
RelMetadataProvider plannerChain =
ChainedRelMetadataProvider.of(list);
rel.getCluster().setMetadataProvider(plannerChain);
hepPlanner.setRoot(rel);
return hepPlanner.findBestExp();
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:Programs.java
示例6: testThreeQueryUnion
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1586">[CALCITE-1586]
* JDBC adapter generates wrong SQL if UNION has more than two inputs</a>. */
@Test public void testThreeQueryUnion() {
String query = "SELECT \"product_id\" FROM \"product\" "
+ " UNION ALL "
+ "SELECT \"product_id\" FROM \"sales_fact_1997\" "
+ " UNION ALL "
+ "SELECT \"product_class_id\" AS product_id FROM \"product_class\"";
String expected = "SELECT \"product_id\"\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "UNION ALL\n"
+ "SELECT \"product_id\"\n"
+ "FROM \"foodmart\".\"sales_fact_1997\"\n"
+ "UNION ALL\n"
+ "SELECT \"product_class_id\" AS \"PRODUCT_ID\"\n"
+ "FROM \"foodmart\".\"product_class\"";
final HepProgram program =
new HepProgramBuilder().addRuleClass(UnionMergeRule.class).build();
final RuleSet rules = RuleSets.ofList(UnionMergeRule.INSTANCE);
sql(query)
.optimize(rules, new HepPlanner(program))
.ok(expected);
}
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:RelToSqlConverterTest.java
示例7: testRuleClass
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
@Test public void testRuleClass() throws Exception {
// Verify that an entire class of rules can be applied.
HepProgramBuilder programBuilder = HepProgram.builder();
programBuilder.addRuleClass(CoerceInputsRule.class);
HepPlanner planner =
new HepPlanner(
programBuilder.build());
planner.addRule(
new CoerceInputsRule(LogicalUnion.class, false,
RelFactories.LOGICAL_BUILDER));
planner.addRule(
new CoerceInputsRule(LogicalIntersect.class, false,
RelFactories.LOGICAL_BUILDER));
checkPlanning(planner,
"(select name from dept union select ename from emp)"
+ " intersect (select fname from customer.contact)");
}
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:HepPlannerTest.java
示例8: testRuleDescription
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
@Test public void testRuleDescription() throws Exception {
// Verify that a rule can be applied via its description.
HepProgramBuilder programBuilder = HepProgram.builder();
programBuilder.addRuleByDescription("FilterToCalcRule");
HepPlanner planner =
new HepPlanner(
programBuilder.build());
planner.addRule(FilterToCalcRule.INSTANCE);
checkPlanning(
planner,
"select name from sales.dept where deptno=12");
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:HepPlannerTest.java
示例9: testCommonSubExpression
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/** Tests that if two relational expressions are equivalent, the planner
* notices, and only applies the rule once. */
@Test public void testCommonSubExpression() {
// In the following,
// (select 1 from dept where abs(-1)=20)
// occurs twice, but it's a common sub-expression, so the rule should only
// apply once.
HepProgramBuilder programBuilder = HepProgram.builder();
programBuilder.addRuleInstance(FilterToCalcRule.INSTANCE);
final HepTestListener listener = new HepTestListener(0);
HepPlanner planner = new HepPlanner(programBuilder.build());
planner.addListener(listener);
final String sql = "(select 1 from dept where abs(-1)=20)\n"
+ "union all\n"
+ "(select 1 from dept where abs(-1)=20)";
planner.setRoot(tester.convertSqlToRel(sql).rel);
RelNode bestRel = planner.findBestExp();
assertThat(bestRel.getInput(0).equals(bestRel.getInput(1)), is(true));
assertThat(listener.getApplyTimes() == 1, is(true));
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:HepPlannerTest.java
示例10: testGC
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
@Test public void testGC() throws Exception {
HepProgramBuilder programBuilder = HepProgram.builder();
programBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN);
programBuilder.addRuleInstance(CalcMergeRule.INSTANCE);
programBuilder.addRuleInstance(ProjectToCalcRule.INSTANCE);
programBuilder.addRuleInstance(FilterToCalcRule.INSTANCE);
HepPlanner planner = new HepPlanner(programBuilder.build());
planner.setRoot(
tester.convertSqlToRel("select upper(name) from dept where deptno=20").rel);
planner.findBestExp();
// Reuse of HepPlanner (should trigger GC).
planner.setRoot(
tester.convertSqlToRel("select upper(name) from dept where deptno=20").rel);
planner.findBestExp();
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:HepPlannerTest.java
示例11: testReduceNestedCaseWhen
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
@Test public void testReduceNestedCaseWhen() {
HepProgram preProgram = new HepProgramBuilder()
.build();
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ReduceExpressionsRule.class);
HepPlanner hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(ReduceExpressionsRule.FILTER_INSTANCE);
final String sql = "select sal\n"
+ "from emp\n"
+ "where case when (sal = 1000) then\n"
+ "(case when sal = 1000 then null else 1 end is null) else\n"
+ "(case when sal = 2000 then null else 1 end is null) end is true";
checkPlanning(tester, preProgram, hepPlanner, sql);
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RelOptRulesTest.java
示例12: testProjectToWindowRuleForMultipleWindows
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
@Test public void testProjectToWindowRuleForMultipleWindows() {
HepProgram preProgram = new HepProgramBuilder()
.build();
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ProjectToWindowRule.class);
HepPlanner hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(ProjectToWindowRule.PROJECT);
final String sql = "select\n"
+ " count(*) over(partition by empno order by sal) as count1,\n"
+ " count(*) over(partition by deptno order by sal) as count2,\n"
+ " sum(deptno) over(partition by empno order by sal) as sum1,\n"
+ " sum(deptno) over(partition by deptno order by sal) as sum2\n"
+ "from emp";
checkPlanning(tester, preProgram, hepPlanner, sql);
}
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:RelOptRulesTest.java
示例13: testJoinProjectTranspose
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
@Test public void testJoinProjectTranspose() {
final HepProgram preProgram =
HepProgram.builder()
.addRuleInstance(ProjectJoinTransposeRule.INSTANCE)
.addRuleInstance(ProjectMergeRule.INSTANCE)
.build();
final HepProgram program =
HepProgram.builder()
.addRuleInstance(JoinProjectTransposeRule.LEFT_PROJECT_INCLUDE_OUTER)
.addRuleInstance(ProjectMergeRule.INSTANCE)
.addRuleInstance(JoinProjectTransposeRule.RIGHT_PROJECT_INCLUDE_OUTER)
.addRuleInstance(JoinProjectTransposeRule.LEFT_PROJECT_INCLUDE_OUTER)
.addRuleInstance(ProjectMergeRule.INSTANCE)
.build();
final String sql = "select a.name\n"
+ "from dept a\n"
+ "left join dept b on b.deptno > 10\n"
+ "right join dept c on b.deptno > 10\n";
checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:RelOptRulesTest.java
示例14: testPullFilterThroughAggregateGroupingSets
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
@Test public void testPullFilterThroughAggregateGroupingSets()
throws Exception {
HepProgram preProgram = HepProgram.builder()
.addRuleInstance(ProjectMergeRule.INSTANCE)
.addRuleInstance(ProjectFilterTransposeRule.INSTANCE)
.build();
HepProgram program = HepProgram.builder()
.addRuleInstance(AggregateFilterTransposeRule.INSTANCE)
.build();
final String sql = "select ename, sal, deptno from ("
+ " select ename, sal, deptno"
+ " from emp"
+ " where sal > 5000)"
+ "group by rollup(ename, sal, deptno)";
checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RelOptRulesTest.java
示例15: testExpressionInWindowFunction
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-841">[CALCITE-841]
* Redundant windows when window function arguments are expressions</a>. */
@Test public void testExpressionInWindowFunction() {
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ProjectToWindowRule.class);
HepPlanner hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(ProjectToWindowRule.PROJECT);
final String sql = "select\n"
+ " sum(deptno) over(partition by deptno order by sal) as sum1,\n"
+ "sum(deptno + sal) over(partition by deptno order by sal) as sum2\n"
+ "from emp";
sql(sql)
.with(hepPlanner)
.check();
}
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:RelOptRulesTest.java
示例16: testPushAggregateFunctionsThroughJoin
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/** Push a variety of aggregate functions. */
@Test public void testPushAggregateFunctionsThroughJoin() {
final HepProgram preProgram = new HepProgramBuilder()
.addRuleInstance(AggregateProjectMergeRule.INSTANCE)
.build();
final HepProgram program = new HepProgramBuilder()
.addRuleInstance(AggregateJoinTransposeRule.EXTENDED)
.build();
final String sql = "select e.job,\n"
+ " min(sal) as min_sal, min(e.deptno) as min_deptno,\n"
+ " sum(sal) + 1 as sum_sal_plus, max(sal) as max_sal,\n"
+ " sum(sal) as sum_sal_2, count(sal) as count_sal,\n"
+ " count(mgr) as count_mgr\n"
+ "from sales.emp as e\n"
+ "join sales.dept as d on e.job = d.name\n"
+ "group by e.job,d.name";
checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:RelOptRulesTest.java
示例17: testPushAggregateThroughJoinDistinct
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/** Push a aggregate functions into a relation that is unique on the join
* key. */
@Test public void testPushAggregateThroughJoinDistinct() {
final HepProgram preProgram = new HepProgramBuilder()
.addRuleInstance(AggregateProjectMergeRule.INSTANCE)
.build();
final HepProgram program = new HepProgramBuilder()
.addRuleInstance(AggregateJoinTransposeRule.EXTENDED)
.build();
final String sql = "select d.name,\n"
+ " sum(sal) as sum_sal, count(*) as c\n"
+ "from sales.emp as e\n"
+ "join (select distinct name from sales.dept) as d\n"
+ " on e.job = d.name\n"
+ "group by d.name";
checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:RelOptRulesTest.java
示例18: testSortJoinTranspose5
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1498">[CALCITE-1498]
* Avoid LIMIT with trivial ORDER BY being pushed through JOIN endlessly</a>. */
@Test public void testSortJoinTranspose5() {
final HepProgram preProgram = new HepProgramBuilder()
.addRuleInstance(SortProjectTransposeRule.INSTANCE)
.addRuleInstance(SortJoinTransposeRule.INSTANCE)
.addRuleInstance(SortProjectTransposeRule.INSTANCE)
.build();
final HepProgram program = new HepProgramBuilder()
.addRuleInstance(SortJoinTransposeRule.INSTANCE)
.build();
// SortJoinTransposeRule should not be fired again.
final String sql = "select * from sales.emp e right join (\n"
+ "select * from sales.dept d) using (deptno)\n"
+ "limit 10";
checkPlanning(tester, preProgram, new HepPlanner(program), sql, true);
}
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:RelOptRulesTest.java
示例19: DrillSqlWorker
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
public DrillSqlWorker(QueryContext context) {
final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(DrillDistributionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
this.context = context;
RelOptCostFactory costFactory = (context.getPlannerSettings().useDefaultCosting()) ?
null : new DrillCostBase.DrillCostFactory() ;
int idMaxLength = (int)context.getPlannerSettings().getIdentifierMaxLength();
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setLex(Lex.MYSQL)
.setIdentifierMaxLength(idMaxLength)
.setParserFactory(DrillParserWithCompoundIdConverter.FACTORY)
.build()) //
.defaultSchema(context.getNewDefaultSchema()) //
.operatorTable(context.getDrillOperatorTable()) //
.traitDefs(traitDefs) //
.convertletTable(new DrillConvertletTable()) //
.context(context.getPlannerSettings()) //
.ruleSets(getRules(context)) //
.costFactory(costFactory) //
.executor(new DrillConstExecutor(context.getFunctionRegistry(), context, context.getPlannerSettings()))
.typeSystem(DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM) //
.build();
this.planner = Frameworks.getPlanner(config);
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ReduceExpressionsRule.class);
builder.addRuleClass(ProjectToWindowRule.class);
this.hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(ReduceExpressionsRule.CALC_INSTANCE);
hepPlanner.addRule(ProjectToWindowRule.PROJECT);
}
开发者ID:skhalifa,项目名称:QDrill,代码行数:36,代码来源:DrillSqlWorker.java
示例20: getLoptJoinOrderTree
import org.apache.calcite.plan.hep.HepPlanner; //导入依赖的package包/类
/**
* Appy Join Order Optimizations using Hep Planner.
*/
private RelNode getLoptJoinOrderTree(RelNode root,
Class<? extends Join> joinClass,
RelFactories.JoinFactory joinFactory,
RelFactories.FilterFactory filterFactory,
RelFactories.ProjectFactory projectFactory) {
final HepProgramBuilder hepPgmBldr = new HepProgramBuilder()
.addMatchOrder(HepMatchOrder.BOTTOM_UP)
.addRuleInstance(new JoinToMultiJoinRule(joinClass))
.addRuleInstance(new LoptOptimizeJoinRule(joinFactory, projectFactory, filterFactory))
.addRuleInstance(ProjectRemoveRule.INSTANCE);
// .addRuleInstance(new ProjectMergeRule(true, projectFactory));
// .addRuleInstance(DrillMergeProjectRule.getInstance(true, projectFactory, this.context.getFunctionRegistry()));
final HepProgram hepPgm = hepPgmBldr.build();
final HepPlanner hepPlanner = new HepPlanner(hepPgm);
final List<RelMetadataProvider> list = Lists.newArrayList();
list.add(DrillDefaultRelMetadataProvider.INSTANCE);
hepPlanner.registerMetadataProviders(list);
final RelMetadataProvider cachingMetaDataProvider = new CachingRelMetadataProvider(ChainedRelMetadataProvider.of(list), hepPlanner);
// Modify RelMetaProvider for every RelNode in the SQL operator Rel tree.
root.accept(new MetaDataProviderModifier(cachingMetaDataProvider));
hepPlanner.setRoot(root);
RelNode calciteOptimizedPlan = hepPlanner.findBestExp();
return calciteOptimizedPlan;
}
开发者ID:skhalifa,项目名称:QDrill,代码行数:36,代码来源:DefaultSqlHandler.java
注:本文中的org.apache.calcite.plan.hep.HepPlanner类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论