Java Code Examples for org.apache.calcite.rel.metadata.ChainedRelMetadataProvider#of()
The following examples show how to use
org.apache.calcite.rel.metadata.ChainedRelMetadataProvider#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Programs.java From Bats with Apache License 2.0 | 6 votes |
/** Creates a program that executes a {@link HepProgram}. */ public static Program of(final HepProgram hepProgram, final boolean noDag, final RelMetadataProvider metadataProvider) { return (planner, rel, requiredOutputTraits, materializations, lattices) -> { final HepPlanner hepPlanner = new HepPlanner(hepProgram, null, noDag, null, RelOptCostImpl.FACTORY); List<RelMetadataProvider> list = new ArrayList<>(); if (metadataProvider != null) { list.add(metadataProvider); } hepPlanner.registerMetadataProviders(list); RelMetadataProvider plannerChain = ChainedRelMetadataProvider.of(list); rel.getCluster().setMetadataProvider(plannerChain); hepPlanner.setRoot(rel); return hepPlanner.findBestExp(); }; }
Example 2
Source File: Programs.java From calcite with Apache License 2.0 | 6 votes |
/** Creates a program that executes a {@link HepProgram}. */ public static Program of(final HepProgram hepProgram, final boolean noDag, final RelMetadataProvider metadataProvider) { return (planner, rel, requiredOutputTraits, materializations, lattices) -> { final HepPlanner hepPlanner = new HepPlanner(hepProgram, null, noDag, null, RelOptCostImpl.FACTORY); List<RelMetadataProvider> list = new ArrayList<>(); if (metadataProvider != null) { list.add(metadataProvider); } hepPlanner.registerMetadataProviders(list); for (RelOptMaterialization materialization : materializations) { hepPlanner.addMaterialization(materialization); } for (RelOptLattice lattice : lattices) { hepPlanner.addLattice(lattice); } RelMetadataProvider plannerChain = ChainedRelMetadataProvider.of(list); rel.getCluster().setMetadataProvider(plannerChain); hepPlanner.setRoot(rel); return hepPlanner.findBestExp(); }; }
Example 3
Source File: RelOptTestBase.java From calcite with Apache License 2.0 | 4 votes |
/** * Checks the plan for a SQL statement before/after executing a given rule, * with a pre-program to prepare the tree. * * @param tester Tester * @param preProgram Program to execute before comparing before state * @param planner Planner * @param sql SQL query * @param unchanged Whether the rule is to have no effect */ private void checkPlanning(Tester tester, HepProgram preProgram, RelOptPlanner planner, String sql, boolean unchanged) { final DiffRepository diffRepos = getDiffRepos(); String sql2 = diffRepos.expand("sql", sql); final RelRoot root = tester.convertSqlToRel(sql2); final RelNode relInitial = root.rel; assertNotNull(relInitial); List<RelMetadataProvider> list = new ArrayList<>(); list.add(DefaultRelMetadataProvider.INSTANCE); planner.registerMetadataProviders(list); RelMetadataProvider plannerChain = ChainedRelMetadataProvider.of(list); final RelOptCluster cluster = relInitial.getCluster(); cluster.setMetadataProvider(plannerChain); RelNode relBefore; if (preProgram == null) { relBefore = relInitial; } else { HepPlanner prePlanner = new HepPlanner(preProgram); prePlanner.setRoot(relInitial); relBefore = prePlanner.findBestExp(); } assertThat(relBefore, notNullValue()); final String planBefore = NL + RelOptUtil.toString(relBefore); diffRepos.assertEquals("planBefore", "${planBefore}", planBefore); SqlToRelTestBase.assertValid(relBefore); if (planner instanceof VolcanoPlanner) { relBefore = planner.changeTraits(relBefore, relBefore.getTraitSet().replace(EnumerableConvention.INSTANCE)); } planner.setRoot(relBefore); RelNode r = planner.findBestExp(); if (tester.isLateDecorrelate()) { final String planMid = NL + RelOptUtil.toString(r); diffRepos.assertEquals("planMid", "${planMid}", planMid); SqlToRelTestBase.assertValid(r); final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(cluster, null); r = RelDecorrelator.decorrelateQuery(r, relBuilder); } final String planAfter = NL + RelOptUtil.toString(r); if (unchanged) { assertThat(planAfter, is(planBefore)); } else { diffRepos.assertEquals("planAfter", "${planAfter}", planAfter); if (planBefore.equals(planAfter)) { throw new AssertionError("Expected plan before and after is the same.\n" + "You must use unchanged=true or call checkUnchanged"); } } SqlToRelTestBase.assertValid(r); }