github-advanced-security[bot] commented on code in PR #20314:
URL: https://github.com/apache/druid/pull/20314#discussion_r3984624743


##########
sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java:
##########
@@ -303,12 +308,44 @@
     cleanupRules.addRuleInstance(CoreRules.PROJECT_MERGE);
     
cleanupRules.addRuleInstance(AggregateProjectMergeRule.Config.DEFAULT.toRule());
     return Programs.sequence(
-        Programs.of(builder.build(), true, 
DefaultRelMetadataProvider.INSTANCE),
+        hepProgram(builder.build(), plannerContext),
         new DruidTrimFieldsProgram(),
-        Programs.of(cleanupRules.build(), true, 
DefaultRelMetadataProvider.INSTANCE)
+        hepProgram(cleanupRules.build(), plannerContext)
     );
   }
 
+  /**
+   * Equivalent to {@link Programs#of(HepProgram, boolean, 
org.apache.calcite.rel.metadata.RelMetadataProvider)} with
+   * {@code noDag=true} and {@link DefaultRelMetadataProvider}, except the 
{@link HepPlanner} is given a
+   * {@link org.apache.calcite.plan.Context} carrying the per-query {@link 
org.apache.calcite.util.CancelFlag}.
+   * {@code Programs.of} builds its {@code HepPlanner} with a {@code null} 
context, so it never observes our cancel
+   * flag; a query that spends its planning budget in these Hep rule loops 
would otherwise ignore the planning timeout.
+   */
+  private static Program hepProgram(final HepProgram hepProgram, final 
PlannerContext plannerContext)
+  {
+    return (planner, rel, requiredOutputTraits, materializations, lattices) -> 
{
+      final HepPlanner hepPlanner = new HepPlanner(
+          hepProgram,
+          Contexts.of(plannerContext.getCancelFlag()),
+          true,
+          null,
+          RelOptCostImpl.FACTORY
+      );
+      final List<RelMetadataProvider> metadataProviders = new ArrayList<>();
+      metadataProviders.add(DefaultRelMetadataProvider.INSTANCE);
+      hepPlanner.registerMetadataProviders(metadataProviders);

Review Comment:
   ## CodeQL / Deprecated method or constructor invocation
   
   Invoking [HepPlanner.registerMetadataProviders](1) should be avoided because 
it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/11951)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to