Skip to content

Conversation

@agrawalreetika
Copy link
Member

Description

Add validation for schema names in Pinot

Motivation and Context

For Pinot connector in Presto, schema name is set to default - https://github.com/prestodb/presto/blob/master/presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotMetadata.java#L63

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 Pinot.

Before,

Here below query should fail as schema name is not default -

image image

After,

image 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 ==

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

@agrawalreetika agrawalreetika self-assigned this Dec 1, 2025
@agrawalreetika agrawalreetika requested a review from a team as a code owner December 1, 2025 17:45
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Dec 1, 2025
@prestodb-ci prestodb-ci requested review from a team, bibith4 and wanglinsong and removed request for a team December 1, 2025 17:45
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 1, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds centralized schema name constant and enforces that the Pinot connector only exposes and accepts the single supported schema "default", throwing NOT_FOUND when queries reference any other schema.

Sequence diagram for Pinot schema name validation in getTableHandle

sequenceDiagram
    actor User
    participant PrestoClient
    participant PrestoCoordinator
    participant PinotMetadata

    User->>PrestoClient: Submit query
    PrestoClient->>PrestoCoordinator: Send SQL
    PrestoCoordinator->>PinotMetadata: getTableHandle(session, tableName)
    PinotMetadata->>PinotMetadata: normalizedSchema = normalizeIdentifier(session, tableName.schemaName)
    alt schema is default
        PinotMetadata->>PinotMetadata: pinotTableName = getPinotTableNameFromPrestoTableName(tableName.tableName)
        PinotMetadata-->>PrestoCoordinator: new PinotTableHandle(connectorId, SCHEMA_NAME, pinotTableName)
        PrestoCoordinator-->>PrestoClient: Query planned and executed
        PrestoClient-->>User: Return results
    else schema is not default
        PinotMetadata-->>PrestoCoordinator: throw PrestoException(NOT_FOUND)
        PrestoCoordinator-->>PrestoClient: Error response
        PrestoClient-->>User: Schema does not exist error
    end
Loading

Updated class diagram for PinotMetadata schema handling

classDiagram
    class PinotMetadata {
        +String connectorId
        +PinotConnection pinotPrestoConnection
        +PinotConfig pinotConfig
        +static String SCHEMA_NAME
        +PinotMetadata(ConnectorId connectorId, PinotConnection pinotPrestoConnection, PinotConfig pinotConfig)
        +List~String~ listSchemaNames(ConnectorSession session)
        +PinotTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
        +List~SchemaTableName~ listTables(ConnectorSession session, String schemaName)
        -String getPinotTableNameFromPrestoTableName(String prestoTableName)
    }

    class PinotConnection {
        +List~String~ getTableNames()
    }

    class PinotTableHandle {
        +PinotTableHandle(String connectorId, String schemaName, String pinotTableName)
    }

    class SchemaTableName {
        +SchemaTableName(String schemaName, String tableName)
        +String getSchemaName()
        +String getTableName()
    }

    class ConnectorSession {
    }

    class ConnectorId {
    }

    class PinotConfig {
    }

    PinotMetadata --> PinotConnection : uses
    PinotMetadata --> PinotConfig : uses
    PinotMetadata --> PinotTableHandle : creates
    PinotMetadata --> SchemaTableName : uses
    PinotMetadata --> ConnectorSession : uses
    PinotMetadata --> ConnectorId : uses
Loading

File-Level Changes

Change Details Files
Centralize Pinot schema name and use constant instead of string literal.
  • Introduce a public static final SCHEMA_NAME constant set to "default" in PinotMetadata.
  • Replace hard-coded "default" string in listSchemaNames with the SCHEMA_NAME constant.
  • Replace hard-coded "default" when constructing SchemaTableName instances in listTables with SCHEMA_NAME.
presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotMetadata.java
Add runtime validation that only the supported schema name is allowed for Pinot tables.
  • In getTableHandle, normalize the incoming schema name and compare it to SCHEMA_NAME.
  • If the normalized schema differs from SCHEMA_NAME, throw a PrestoException with NOT_FOUND error code and a message indicating the schema does not exist.
  • Keep existing PinotTableHandle construction logic, still passing through the schema name and mapped Pinot table name when validation passes.
presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotMetadata.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

Copy link
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 making SCHEMA_NAME private static final (and potentially renaming to something like DEFAULT_SCHEMA_NAME) since it is an internal implementation detail and not intended as part of the public API surface for this class.
  • For consistency with getTableHandle, you may want to validate the schemaName argument in listTables (e.g., normalize and compare against SCHEMA_NAME, returning an empty list or throwing if it doesn't match) rather than ignoring the passed schema.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making `SCHEMA_NAME` `private static final` (and potentially renaming to something like `DEFAULT_SCHEMA_NAME`) since it is an internal implementation detail and not intended as part of the public API surface for this class.
- For consistency with `getTableHandle`, you may want to validate the `schemaName` argument in `listTables` (e.g., normalize and compare against `SCHEMA_NAME`, returning an empty list or throwing if it doesn't match) rather than ignoring the passed schema.

## Individual Comments

### Comment 1
<location> `presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotMetadata.java:51-54` </location>
<code_context>
     private final String connectorId;
     private final PinotConnection pinotPrestoConnection;
     private final PinotConfig pinotConfig;
+    public static final String SCHEMA_NAME = "default";

     @Inject
</code_context>

<issue_to_address>
**suggestion:** Consider reducing the visibility of SCHEMA_NAME if it is only intended for internal use.

If nothing outside this class (or package) needs this constant, consider making `SCHEMA_NAME` private or package-private to avoid exposing it as part of the public API and to preserve flexibility for future changes.

```suggestion
    private final String connectorId;
    private final PinotConnection pinotPrestoConnection;
    private final PinotConfig pinotConfig;
    private static final String SCHEMA_NAME = "default";
```
</issue_to_address>

### Comment 2
<location> `presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotMetadata.java:81-89` </location>
<code_context>
     @Override
     public PinotTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
     {
+        if (!SCHEMA_NAME.equals(normalizeIdentifier(session, tableName.getSchemaName()))) {
+            throw new PrestoException(NOT_FOUND, format("Schema %s does not exist", tableName.getSchemaName()));
+        }
         String pinotTableName = getPinotTableNameFromPrestoTableName(tableName.getTableName());
</code_context>

<issue_to_address>
**suggestion:** Align the error message with the enforced schema to make the failure mode clearer.

Because this connector only works with the `SCHEMA_NAME` schema, consider making the error say that explicitly (e.g., mention that only that schema is supported or show the normalized expected value). That way, users who pass another schema understand the real constraint rather than seeing a generic "does not exist" message.

```suggestion
    @Override
    public PinotTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
    {
        String normalizedSchemaName = normalizeIdentifier(session, tableName.getSchemaName());
        if (!SCHEMA_NAME.equals(normalizedSchemaName)) {
            throw new PrestoException(
                    NOT_FOUND,
                    format(
                            "Schema '%s' is not supported by the Pinot connector. Only schema '%s' is supported.",
                            tableName.getSchemaName(),
                            SCHEMA_NAME));
        }
        String pinotTableName = getPinotTableNameFromPrestoTableName(tableName.getTableName());
        return new PinotTableHandle(connectorId, tableName.getSchemaName(), pinotTableName);
    }
```
</issue_to_address>

### Comment 3
<location> `presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotMetadata.java:125` </location>
<code_context>
     public List<SchemaTableName> listTables(ConnectorSession session, String schemaNameOrNull)
</code_context>

<issue_to_address>
**suggestion (bug_risk):** listTables ignores schemaNameOrNull, which can be inconsistent with the stricter schema check in getTableHandle.

Since `getTableHandle` now enforces `SCHEMA_NAME`, `listTables` should probably also honor `schemaNameOrNull`. If `schemaNameOrNull` is non-null and its normalized value differs from `SCHEMA_NAME`, consider returning an empty list rather than listing tables from the default schema, to keep discovery consistent with `getTableHandle`’s access rules.
</issue_to_address>

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.

ImmutableList.Builder<SchemaTableName> builder = ImmutableList.builder();
for (String table : pinotPrestoConnection.getTableNames()) {
builder.add(new SchemaTableName("default", table));
builder.add(new SchemaTableName(SCHEMA_NAME, table));
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): listTables ignores schemaNameOrNull, which can be inconsistent with the stricter schema check in getTableHandle.

Since getTableHandle now enforces SCHEMA_NAME, listTables should probably also honor schemaNameOrNull. If schemaNameOrNull is non-null and its normalized value differs from SCHEMA_NAME, consider returning an empty list rather than listing tables from the default schema, to keep discovery consistent with getTableHandle’s access rules.

@agrawalreetika agrawalreetika force-pushed the pinot-schema-validation branch 4 times, most recently from b98931b to 57b05d3 Compare December 4, 2025 18:26
@agrawalreetika agrawalreetika force-pushed the pinot-schema-validation branch from 57b05d3 to dff918d Compare December 4, 2025 18:31
assertEquals(withAnotherSchema.getTableName(), TestPinotSplitManager.realtimeOnlyTable.getTableName());
// Invalid schema should now fail
assertThrows(PrestoException.class, () -> metadata.getTableHandle(session,
new SchemaTableName("foo", TestPinotSplitManager.realtimeOnlyTable.getTableName())));
Copy link
Contributor

Choose a reason for hiding this comment

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

@agrawalreetika Can we use static import for TestPinotSplitManager.realtimeOnlyTable

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.

3 participants