| 255 | } |
| 256 | |
| 257 | public static Program subQuery(RelMetadataProvider metadataProvider) { |
| 258 | final HepProgramBuilder builder = HepProgram.builder(); |
| 259 | builder.addRuleCollection( |
| 260 | ImmutableList.of(CoreRules.FILTER_SUB_QUERY_TO_CORRELATE, |
| 261 | CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE, |
| 262 | CoreRules.JOIN_SUB_QUERY_TO_CORRELATE, |
| 263 | CoreRules.PROJECT_OVER_SUM_TO_SUM0_RULE)); |
| 264 | final Program oldProgram = of(builder.build(), true, metadataProvider); |
| 265 | |
| 266 | final HepProgramBuilder newBuilder = HepProgram.builder(); |
| 267 | newBuilder.addRuleCollection( |
| 268 | ImmutableList.of(CoreRules.FILTER_SUB_QUERY_TO_MARK_CORRELATE, |
| 269 | CoreRules.PROJECT_SUB_QUERY_TO_MARK_CORRELATE, |
| 270 | CoreRules.JOIN_SUB_QUERY_TO_CORRELATE, |
| 271 | CoreRules.PROJECT_OVER_SUM_TO_SUM0_RULE)); |
| 272 | final Program newProgram = of(newBuilder.build(), true, metadataProvider); |
| 273 | |
| 274 | return (planner, rel, requiredOutputTraits, materializations, lattices) -> { |
| 275 | final CalciteConnectionConfig config = |
| 276 | planner.getContext().maybeUnwrap(CalciteConnectionConfig.class) |
| 277 | .orElse(CalciteConnectionConfig.DEFAULT); |
| 278 | final Program program = config.topDownGeneralDecorrelationEnabled() |
| 279 | ? newProgram |
| 280 | : oldProgram; |
| 281 | return program.run(planner, rel, requiredOutputTraits, materializations, |
| 282 | lattices); |
| 283 | }; |
| 284 | } |
| 285 | |
| 286 | public static Program measure(RelMetadataProvider metadataProvider) { |
| 287 | return conditional(Programs::containsAggM2v, |