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


Java HepProgramBuilder类代码示例

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


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

示例1: getParsedSql

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

示例2: testPushAggregateThroughJoinDistinct

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

示例3: 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

示例4: 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

示例5: testSubprogram

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入依赖的package包/类
@Test public void testSubprogram() throws Exception {
  // Verify that subprogram gets re-executed until fixpoint.
  // In this case, the first time through we limit it to generate
  // only one calc; the second time through it will generate
  // a second calc, and then merge them.
  HepProgramBuilder subprogramBuilder = HepProgram.builder();
  subprogramBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN);
  subprogramBuilder.addMatchLimit(1);
  subprogramBuilder.addRuleInstance(ProjectToCalcRule.INSTANCE);
  subprogramBuilder.addRuleInstance(CalcMergeRule.INSTANCE);

  HepProgramBuilder programBuilder = HepProgram.builder();
  programBuilder.addSubprogram(subprogramBuilder.build());

  checkPlanning(
      programBuilder.build(),
      "select upper(ename) from (select lower(ename) as ename from emp)");
}
 
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:HepPlannerTest.java

示例6: 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

示例7: testReduceCompositeInSubQuery

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1479">[CALCITE-1479]
 * AssertionError in ReduceExpressionsRule on multi-column IN
 * sub-query</a>. */
@Test public void testReduceCompositeInSubQuery() {
  final HepProgram hepProgram = new HepProgramBuilder()
      .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
      .build();
  final String sql = "select *\n"
      + "from emp\n"
      + "where (empno, deptno) in (\n"
      + "  select empno, deptno from (\n"
      + "    select empno, deptno\n"
      + "    from emp\n"
      + "    group by empno, deptno))\n"
      + "or deptno < 40 + 60";
  checkSubQuery(sql)
      .with(hepProgram)
      .check();
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:RelOptRulesTest.java

示例8: 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

示例9: testSortJoinTranspose7

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1507">[CALCITE-1507]
 * OFFSET cannot be pushed through a JOIN if the non-preserved side of outer
 * join is not count-preserving</a>. */
@Test public void testSortJoinTranspose7() {
  final HepProgram preProgram = new HepProgramBuilder()
      .addRuleInstance(SortProjectTransposeRule.INSTANCE)
      .build();
  final HepProgram program = new HepProgramBuilder()
      .addRuleInstance(SortJoinTransposeRule.INSTANCE)
      .build();
  // This one cannot be pushed down
  final String sql = "select d.deptno, empno from sales.dept d\n"
      + "left join sales.emp e using (deptno) order by d.deptno offset 1";
  sql(sql)
      .withPre(preProgram)
      .with(program)
      .checkUnchanged();
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:RelOptRulesTest.java

示例10: testMergeFilterWithJoinCondition

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入依赖的package包/类
@Ignore("cycles")
@Test public void testMergeFilterWithJoinCondition() throws Exception {
  HepProgram program = new HepProgramBuilder()
      .addRuleInstance(TableScanRule.INSTANCE)
      .addRuleInstance(JoinExtractFilterRule.INSTANCE)
      .addRuleInstance(FilterToCalcRule.INSTANCE)
      .addRuleInstance(CalcMergeRule.INSTANCE)
      .addRuleInstance(ProjectToCalcRule.INSTANCE)
      .build();

  checkPlanning(program,
      "select d.name as dname,e.ename as ename"
          + " from emp e inner join dept d"
          + " on e.deptno=d.deptno"
          + " where d.name='Propane'");
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RelOptRulesTest.java

示例11: testUnionMergeRule

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入依赖的package包/类
/** Tests to see if the final branch of union is missed */
@Test
public void testUnionMergeRule() throws Exception {
  HepProgram program = new HepProgramBuilder()
          .addRuleInstance(ProjectSetOpTransposeRule.INSTANCE)
          .addRuleInstance(ProjectRemoveRule.INSTANCE)
          .addRuleInstance(UnionMergeRule.INSTANCE)
          .build();

  checkPlanning(program,
          "select * from (\n"
                  + "select * from (\n"
                  + "  select name, deptno from dept\n"
                  + "  union all\n"
                  + "  select name, deptno from\n"
                  + "  (\n"
                  + "    select name, deptno, count(1) from dept group by name, deptno\n"
                  + "    union all\n"
                  + "    select name, deptno, count(1) from dept group by name, deptno\n"
                  + "  ) subq\n"
                  + ") a\n"
                  + "union all\n"
                  + "select name, deptno from dept\n"
                  + ") aa\n");
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:RelOptRulesTest.java

示例12: testMergeJoinFilter

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入依赖的package包/类
/** Tests that a filters is combined are combined if they are identical,
 * even if one of them originates in an ON clause of a JOIN. */
@Test public void testMergeJoinFilter() throws Exception {
  HepProgram program = new HepProgramBuilder()
      .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
      .addRuleInstance(FilterMergeRule.INSTANCE)
      .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
      .build();

  checkPlanning(program,
      "select * from (\n"
          + "  select d.deptno, e.ename\n"
          + "  from emp as e\n"
          + "  join dept as d\n"
          + "  on e.deptno = d.deptno\n"
          + "  and d.deptno = 10)\n"
          + "where deptno = 10\n");
}
 
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:RelOptRulesTest.java

示例13: testProjectWindowTransposeRuleWithConstants

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入依赖的package包/类
@Test public void testProjectWindowTransposeRuleWithConstants() {
  HepProgram program = new HepProgramBuilder()
      .addRuleInstance(ProjectToWindowRule.PROJECT)
      .addRuleInstance(ProjectMergeRule.INSTANCE)
      .addRuleInstance(ProjectWindowTransposeRule.INSTANCE)
      .build();

  final String sql = "select col1, col2\n"
      + "from (\n"
      + "  select empno,\n"
      + "    sum(100) over (partition by  deptno order by sal) as col1,\n"
      + "  sum(1000) over(partition by deptno order by sal) as col2\n"
      + "  from emp)";

  checkPlanning(program, sql);
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RelOptRulesTest.java

示例14: testCustomColumnResolvingInCorrelatedSubQuery

import org.apache.calcite.plan.hep.HepProgramBuilder; //导入依赖的package包/类
@Test public void testCustomColumnResolvingInCorrelatedSubQuery() {
  final String sql = "select *\n"
      + "from struct.t t1\n"
      + "where c0 = (\n"
      + "  select max(f1.c0) from struct.t t2 where t1.k0 = t2.k0)";
  final HepProgram program = new HepProgramBuilder()
      .addRuleInstance(SubQueryRemoveRule.PROJECT)
      .addRuleInstance(SubQueryRemoveRule.FILTER)
      .addRuleInstance(SubQueryRemoveRule.JOIN)
      .build();
  sql(sql)
      .withTrim(true)
      .expand(false)
      .with(program)
      .check();
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RelOptRulesTest.java

示例15: testPushAggregateFunctionsThroughJoin

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


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