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


Java HepProgram类代码示例

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


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

示例1: substitute

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

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

示例8: testSubprogram

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

示例9: testPullFilterThroughAggregateGroupingSets

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

示例10: testSortJoinTranspose6

import org.apache.calcite.plan.hep.HepProgram; //导入依赖的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 testSortJoinTranspose6() {
  final HepProgram preProgram = new HepProgramBuilder()
      .addRuleInstance(SortProjectTransposeRule.INSTANCE)
      .build();
  final HepProgram program = new HepProgramBuilder()
      .addRuleInstance(SortJoinTransposeRule.INSTANCE)
      .build();
  // This one can be pushed down even if it has an OFFSET, since the dept
  // table is count-preserving against the join condition.
  final String sql = "select d.deptno, empno from sales.dept d\n"
      + "right join sales.emp e using (deptno) limit 10 offset 2";
  sql(sql)
      .withPre(preProgram)
      .with(program)
      .check();
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:RelOptRulesTest.java

示例11: testReduceNestedCaseWhen

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

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

示例13: testProjectWindowTransposeRuleWithConstants

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

import org.apache.calcite.plan.hep.HepProgram; //导入依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1495">[CALCITE-1495]
 * SemiJoinRule should not apply to RIGHT and FULL JOIN</a>. */
@Test public void testSemiJoinRuleRight() {
  final HepProgram preProgram =
      HepProgram.builder()
          .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
          .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
          .addRuleInstance(ProjectMergeRule.INSTANCE)
          .build();
  final HepProgram program =
      HepProgram.builder()
          .addRuleInstance(SemiJoinRule.PROJECT)
          .build();
  final String sql = "select dept.* from dept right join (\n"
      + "  select distinct deptno from emp\n"
      + "  where sal > 100) using (deptno)";
  sql(sql)
      .withPre(preProgram)
      .with(program)
      .withDecorrelation(true)
      .withTrim(true)
      .checkUnchanged();
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:RelOptRulesTest.java

示例15: testSemiJoinRuleFull

import org.apache.calcite.plan.hep.HepProgram; //导入依赖的package包/类
/** Similar to {@link #testSemiJoinRuleRight()} but FULL. */
@Test public void testSemiJoinRuleFull() {
  final HepProgram preProgram =
      HepProgram.builder()
          .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
          .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
          .addRuleInstance(ProjectMergeRule.INSTANCE)
          .build();
  final HepProgram program =
      HepProgram.builder()
          .addRuleInstance(SemiJoinRule.PROJECT)
          .build();
  final String sql = "select dept.* from dept full join (\n"
      + "  select distinct deptno from emp\n"
      + "  where sal > 100) using (deptno)";
  sql(sql)
      .withPre(preProgram)
      .with(program)
      .withDecorrelation(true)
      .withTrim(true)
      .checkUnchanged();
}
 
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:RelOptRulesTest.java


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