当前位置: 首页>>代码示例>>Java>>正文


Java HepProgramBuilder.build方法代码示例

本文整理汇总了Java中org.apache.calcite.plan.hep.HepProgramBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java HepProgramBuilder.build方法的具体用法?Java HepProgramBuilder.build怎么用?Java HepProgramBuilder.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.plan.hep.HepProgramBuilder的用法示例。


在下文中一共展示了HepProgramBuilder.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRuleClass

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例2: testRuleDescription

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例3: testCommonSubExpression

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例4: testGC

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例5: testReduceNestedCaseWhen

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例6: testProjectToWindowRuleForMultipleWindows

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例7: testExpressionInWindowFunction

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例8: DrillSqlWorker

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例9: getLoptJoinOrderTree

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的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

示例10: checkRuleApplyCount

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的package包/类
private long checkRuleApplyCount(HepMatchOrder matchOrder) {
  final HepProgramBuilder programBuilder = HepProgram.builder();
  programBuilder.addMatchOrder(matchOrder);
  programBuilder.addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE);
  programBuilder.addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE);

  final HepTestListener listener = new HepTestListener(0);
  HepPlanner planner = new HepPlanner(programBuilder.build());
  planner.addListener(listener);
  planner.setRoot(tester.convertSqlToRel(COMPLEX_UNION_TREE).rel);
  planner.findBestExp();
  return listener.getApplyTimes();
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:HepPlannerTest.java

示例11: testReduceNot

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的package包/类
@Test public void testReduceNot() {
  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 *\n"
      + "from (select (case when sal > 1000 then null else false end) as caseCol from emp)\n"
      + "where NOT(caseCol)";
  checkPlanning(tester, preProgram, hepPlanner, sql, true);
}
 
开发者ID:apache,项目名称:calcite,代码行数:15,代码来源:RelOptRulesTest.java

示例12: testReduceOrCaseWhen

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的package包/类
@Test public void testReduceOrCaseWhen() {
  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 null else 1 end is null\n"
      + "OR case when sal = 2000 then null else 1 end is null";
  checkPlanning(tester, preProgram, hepPlanner, sql);
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:RelOptRulesTest.java

示例13: testReduceNullableCase

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的package包/类
@Test public void testReduceNullableCase() {
  HepProgramBuilder builder = new HepProgramBuilder();
  builder.addRuleClass(ReduceExpressionsRule.class);
  HepPlanner hepPlanner = new HepPlanner(builder.build());
  hepPlanner.addRule(ReduceExpressionsRule.PROJECT_INSTANCE);

  final String sql = "SELECT CASE WHEN 1=2 "
      + "THEN cast((values(1)) as integer) "
      + "ELSE 2 end from (values(1))";
  sql(sql).with(hepPlanner).check();
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:RelOptRulesTest.java

示例14: testReduceNullableCase2

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的package包/类
@Test public void testReduceNullableCase2() {
  HepProgramBuilder builder = new HepProgramBuilder();
  builder.addRuleClass(ReduceExpressionsRule.class);
  HepPlanner hepPlanner = new HepPlanner(builder.build());
  hepPlanner.addRule(ReduceExpressionsRule.PROJECT_INSTANCE);

  final String sql = "SELECT deptno, ename, CASE WHEN 1=2 "
      + "THEN substring(ename, 1, cast(2 as int)) ELSE NULL end from emp"
      + " group by deptno, ename, case when 1=2 then substring(ename,1, cast(2 as int))  else null end";
  sql(sql).with(hepPlanner).check();
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:RelOptRulesTest.java

示例15: testWindowInParenthesis

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入方法依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-888">[CALCITE-888]
 * Overlay window loses PARTITION BY list</a>. */
@Test public void testWindowInParenthesis() {
  HepProgramBuilder builder = new HepProgramBuilder();
  builder.addRuleClass(ProjectToWindowRule.class);
  HepPlanner hepPlanner = new HepPlanner(builder.build());
  hepPlanner.addRule(ProjectToWindowRule.PROJECT);

  final String sql = "select count(*) over (w), count(*) over w\n"
      + "from emp\n"
      + "window w as (partition by empno order by empno)";
  sql(sql)
      .with(hepPlanner)
      .check();
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RelOptRulesTest.java


注:本文中的org.apache.calcite.plan.hep.HepProgramBuilder.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。