Skip to content

fix(plugin-druid): Add validation for schema names in Druid#26723

Merged
agrawalreetika merged 1 commit intoprestodb:masterfrom
agrawalreetika:druid-schema-validation
Dec 2, 2025
Merged

fix(plugin-druid): Add validation for schema names in Druid#26723
agrawalreetika merged 1 commit intoprestodb:masterfrom
agrawalreetika:druid-schema-validation

Conversation

@agrawalreetika
Copy link
Copy Markdown
Member

Description

Add validation for schema names in Druid

Motivation and Context

For Druid connector in Presto, schema name is provided via druid catalog config - https://github.com/prestodb/presto/blob/master/presto-druid/src/main/java/com/facebook/presto/druid/DruidConfig.java#L92

Apart from the schema name validation in ShowQueriesRewrite for some of the sql queries, there is no validation for schema names in the connector.

This change is to have the schema name validation in the connector.

Impact

Add validation for schema names in Druid

Here in Druid catalog, druid.schema-name=wikipedia
Before -
Below query should fail, since schema name is configured as wikipedia not wikipedia1
image

After -
image

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

Druid Connector Changes
* Add validation for schema names in Druid connector

@agrawalreetika agrawalreetika requested a review from a team as a code owner December 1, 2025 15:32
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Dec 1, 2025
@prestodb-ci prestodb-ci requested review from a team, BryanCutler and sh-shamsan and removed request for a team December 1, 2025 15:32
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Dec 1, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds schema name validation to the Druid connector by enforcing that queried schema names match the configured Druid schema and raising a NOT_FOUND PrestoException when they do not.

Sequence diagram for Druid schema validation in getTableHandle

sequenceDiagram
    actor User
    participant PrestoCoordinator
    participant DruidMetadata
    participant DruidClient

    User->>PrestoCoordinator: Submit query (SELECT ... FROM wikipedia1.table)
    PrestoCoordinator->>DruidMetadata: getTableHandle(session, tableName)
    DruidMetadata->>DruidClient: getSchema()
    DruidClient-->>DruidMetadata: configuredSchema
    DruidMetadata->>DruidMetadata: normalizeIdentifier(session, configuredSchema)
    DruidMetadata->>DruidMetadata: normalizeIdentifier(session, tableName.getSchemaName())
    alt schema matches configured schema
        DruidMetadata->>DruidClient: getTables()
        DruidClient-->>DruidMetadata: tableNames
        DruidMetadata-->>PrestoCoordinator: ConnectorTableHandle
        PrestoCoordinator-->>User: Query continues to planning/execution
    else schema does not match
        DruidMetadata-->>PrestoCoordinator: throw PrestoException(NOT_FOUND)
        PrestoCoordinator-->>User: Error Schema wikipedia1 does not exist
    end
Loading

Class diagram for updated DruidMetadata schema validation

classDiagram
    class DruidMetadata {
        +listSchemaNames(ConnectorSession session) List~String~
        +getTableHandle(ConnectorSession session, SchemaTableName tableName) ConnectorTableHandle
    }

    class DruidClient {
        +getSchema() String
        +getTables() List~String~
    }

    class ConnectorSession
    class SchemaTableName {
        +getSchemaName() String
        +getTableName() String
    }

    class PrestoException {
        +PrestoException(StandardErrorCode errorCode, String message)
    }

    class StandardErrorCode {
        <<enumeration>>
        NOT_FOUND
    }

    DruidMetadata --> DruidClient : uses
    DruidMetadata --> ConnectorSession : uses
    DruidMetadata --> SchemaTableName : uses
    DruidMetadata --> PrestoException : throws
    PrestoException --> StandardErrorCode : uses
Loading

File-Level Changes

Change Details Files
Validate that requested Druid schema matches the configured schema before resolving table handles.
  • Normalize both the configured Druid schema name and the requested schema name using the session before comparison.
  • Compare normalized schema names in getTableHandle and short‑circuit if they do not match.
  • Throw a PrestoException with NOT_FOUND error code when the requested schema does not match, using a user-facing message indicating the schema does not exist.
  • Leave existing table handle resolution logic unchanged, only executing it when schema validation passes.
presto-druid/src/main/java/com/facebook/presto/druid/DruidMetadata.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@agrawalreetika agrawalreetika self-assigned this Dec 1, 2025
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider normalizing and caching the configured schema name once (e.g., in the constructor) instead of calling normalizeIdentifier on druidClient.getSchema() for every getTableHandle invocation to avoid repeated work on a hot path.
  • It may be safer to skip the validation or fail fast with a clearer configuration error if druidClient.getSchema() is null or blank, rather than throwing a NOT_FOUND error tied to the query.
  • To keep error handling consistent with other connectors, consider using a schema-specific error code or existing helper (e.g., a SchemaNotFound utility) and align the error message format with other schema-not-found messages in Presto.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider normalizing and caching the configured schema name once (e.g., in the constructor) instead of calling `normalizeIdentifier` on `druidClient.getSchema()` for every `getTableHandle` invocation to avoid repeated work on a hot path.
- It may be safer to skip the validation or fail fast with a clearer configuration error if `druidClient.getSchema()` is `null` or blank, rather than throwing a NOT_FOUND error tied to the query.
- To keep error handling consistent with other connectors, consider using a schema-specific error code or existing helper (e.g., a `SchemaNotFound` utility) and align the error message format with other schema-not-found messages in Presto.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

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

@agrawalreetika thanks for the fix, looks good to me. Could you update the PR title? This doesn't look like an Iceberg change.

@agrawalreetika agrawalreetika changed the title fix(plugin-iceberg): Add validation for schema names in Druid fix(plugin-druid): Add validation for schema names in Druid Dec 1, 2025
Copy link
Copy Markdown
Contributor

@BryanCutler BryanCutler left a comment

Choose a reason for hiding this comment

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

LGTM, could you add a test?

@agrawalreetika agrawalreetika merged commit af23a10 into prestodb:master Dec 2, 2025
89 of 90 checks passed
@agrawalreetika agrawalreetika deleted the druid-schema-validation branch December 2, 2025 02:33
@agrawalreetika
Copy link
Copy Markdown
Member Author

LGTM, could you add a test?

I’m sorry — I didn’t see your comment before the merge. Currently, there are no actual integration tests available for Druid. I had opened an issue earlier to highlight this gap: #26143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants