← Back to Pull requests

refactor!: migrate SQL query context parameters #20578

Closed
unknown closed this pull request without merging on Oct 18, 2026 02:49 UTC
View on GitHub
unknown unknown commented on Oct 14, 2026 06:52 UTC
Author

Description

Follow-up to #20555.

Migrates the SQL query context parameters documented in sql-query-context.md to typed QueryContextParameter descriptors.

  • Declares descriptors for SQL planner, MSQ and Dart parameters in QueryContextParameters. Field names follow the keys, e.g. plannerStrategy → PLANNER_STRATEGY, inSubQueryThreshold → IN_SUB_QUERY_THRESHOLD.

  • Replaces raw-string reads in PlannerContext, PlannerConfig, the planner rules, MSQ and Dart with descriptor-backed reads.

  • Generates the corresponding rows from the descriptors:

  • - sql-query-context.md, which gains engine, executionMode, catalogValidationEnabled, fullReport and sqlJoinAlgorithm, and now holds sqlPlannerBloat, moved from query-context-reference.md.
    - query-context-reference.md: noProjections, forceProjections, useProjection, useNestedForUnknownTypeInSubquery, numRetriesOnMissingSegments, returnPartialResults and uncoveredIntervalsLimit.
    - sqlJoinAlgorithm is also generated in multi-stage-query/reference.md and dart.md, replacing their hand-written rows.
  • Adds QueryContexts.PlannerStrategy (COUPLED, DECOUPLED) and makes plannerStrategy an enum parameter.

  • Renames the Visibility.INTERNAL level added in #20555 to SYSTEM, which says more plainly that Druid sets these values itself. Visibility has not been released yet.
  • Existing parameter names and defaults are unchanged.

    Deprecations

    The replaced key and default constants are kept as @Deprecated(since = "39.0.0", forRemoval = true) with a link to the descriptor: PlannerContext.CTX_/DEFAULT_, PlannerContext.getJoinAlgorithm(...), PlannerConfig.CTX_KEY_*, ReverseLookupRule.CTX_THRESHOLD/DEFAULT_THRESHOLD, CalciteRulesManager.BLOAT_PROPERTY/DEFAULT_BLOAT, SketchQueryContext.CTX_FINALIZE_OUTER_SKETCHES/DEFAULT_FINALIZE_OUTER_SKETCHES, the matching QueryContexts keys, QueryContexts.NATIVE_QUERY_SQL_PLANNING_MODE_COUPLED/DECOUPLED, and BaseQuery.QUERY_ID/SUB_QUERY_ID/SQL_QUERY_ID.

    Behavior changes

  • plannerStrategy and druid.sql.planner.nativeQuerySqlPlanningMode accept values in any case, e.g. decoupled. An unknown value is now rejected instead of silently falling back to COUPLED. This includes an empty druid.sql.planner.nativeQuerySqlPlanningMode=, which now fails at startup.

  • Integer and long parameters (maxNumericInFilters, sqlReverseLookupThreshold, sqlPlannerBloat, sqlOuterLimit, maxPlanningTimeMs, inSubQueryThreshold, inFunctionThreshold, inFunctionExprThreshold, uncoveredIntervalsLimit, numRetriesOnMissingSegments, defaultTimeout) reject values that aren't exact integers, such as 1.5, and values out of range, instead of truncating them, as in #20555. This applies to native queries as well as SQL.

  • PlannerContext used one generated ID for the planner and a different one in the context when no sqlQueryId was given. It now uses the same ID.
  • This PR and #20579 both touch QueryContextParameters and QueryContexts; whichever merges second will be rebased.

    <hr>

    This PR has:

  • been self-reviewed.

  • added documentation for new or modified features or behaviors.

  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.

  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • Diff: 446 lines (+334 / -112) across 5 files Reviewer: GWphua Review duration: 5517m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.69) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.69 · 446 lines diff across 5 files
    0.69
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.365
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.069
    Real PR Conversation Timeline
    1 comments
    "Review active on #20578"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 68.5% (HIGH) · Higher = larger blast radius
    68.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.1% · Safe to merge
    27.1%
    Repository