Skip to content

feat: reject unknown query context parameters - #20647

Open
FrankChen021 wants to merge 3 commits into
apache:masterfrom
FrankChen021:reject-unknown-query-context-parameters
Open

FrankChen021 wants to merge 3 commits into
apache:masterfrom
FrankChen021:reject-unknown-query-context-parameters

Conversation

@FrankChen021

Copy link
Copy Markdown
Member

Description

Background

Since #20578 and #20579, every query context parameter is declared in QueryContextParameters. Druid still silently ignores a parameter it doesn't recognize, such as a misspelled useCahce, and only checks a parameter's value when it first reads it, so an invalid value can go unnoticed or fail late.

New configuration and behavior

Property Default Description
druid.query.context.rejectUnknownParameters false Whether to reject query context parameters that Druid doesn't recognize.
  • The Broker checks the context that a query sets before running it: the top-level context of native queries, and the context and SET statements of SQL queries.
    • Values of recognized parameters are always checked; an invalid one is rejected with HTTP 400.
    • Unrecognized parameters are rejected only if rejectUnknownParameters is true, with suggestions for similar names: Unknown query context parameter [useCahce]. Did you mean [useCache]?
    • A query rejected this way fails before it's planned, so it isn't request-logged or counted in query/time / sqlQuery/time, like a query that can't be parsed.
  • The connection properties of a JDBC connection, which are the query context of every statement on it, are checked when the connection opens.
  • Default contexts are checked the same way where they're configured: the Broker fails to start if druid.query.default.context.* or druid.msq.dart.query.context.* is invalid, and the Coordinator rejects a Broker dynamic configuration update with an invalid queryContext.
  • Data servers don't check contexts, so queries keep working during rolling upgrades.

Upgrade note

JDBC connections now fail to open if a connection property, other than user and password, sets a query context parameter to an invalid value; for example sqlTimeZone=Not/AZone. Previously such a property failed only when a query read it, or was ignored if no query did. This matches how databases such as MySQL and PostgreSQL reject invalid session settings at connect. If druid.query.context.rejectUnknownParameters is true, connections with a connection property that Druid doesn't recognize also fail to open. Check the connection properties of your JDBC clients before upgrading.

Release note

New property druid.query.context.rejectUnknownParameters, off by default: when true, Druid rejects queries that set a query context parameter it doesn't recognize, and suggests similar parameter names. Druid also checks the values of query context parameters before running a query, and the default query contexts where they're configured.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated unit tests to cover new code paths.

Add druid.query.context.rejectUnknownParameters, off by default. When it is on, the
Broker rejects queries that set a query context parameter that is not declared in
QueryContextParameters, and suggests parameters with similar names.

The Broker also validates the values of the parameters a query sets before running it:
the top-level context of native queries, the context and SET statements of SQL queries,
and the connection properties of JDBC connections when they open. Default contexts are
validated where they are configured: at Broker startup for druid.query.default.context
and druid.msq.dart.query.context, and by the Coordinator for Broker dynamic configuration
updates.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 12:29

This comment was marked as outdated.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Validate native gRPC query contexts in extensions-contrib/grpc-query/src/main/java/org/apache/druid/grpc/server/QueryDriver.java:326. The gRPC module runs on the Broker, but rejectUnknownParameters is applied only to SQL translation. The native runNativeQuery path deserializes the query and initializes its lifecycle without calling QueryContextParameterValidator, so native gRPC requests can bypass unknown-parameter and invalid-value validation when the feature is enabled. Validate the native query context before lifecycle initialization and return the corresponding request error.

Reviewed 73 of 73 changed files; finding in 1 file.

Validation: git diff --check passed. No build or tests were run; this was a static review.

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

This is an automated review by Codex GPT-5.6-Luna(max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No actionable findings. The previous native-gRPC context-validation finding is addressed in the current head.

Reviewed 73 of 73 changed files.

Validation: git diff --check passed. No build or tests were run; this was a static review.


This is an automated review by Codex GPT-5.6-Luna(max)

@FrankChen021 FrankChen021 added the Approval Recommended Used when AI completes a review and reports no findings label Oct 20, 2026
@github-actions github-actions Bot added Area - Documentation Area - Batch Ingestion Area - Querying Area - Web Console Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 labels Oct 20, 2026
@FrankChen021 FrankChen021 added this to the 40.0.0 milestone Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approval Recommended Used when AI completes a review and reports no findings Area - Batch Ingestion Area - Documentation Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 Area - Querying Area - Web Console

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants