Skip to content

Conversation

@auden-woolfson
Copy link
Contributor

@auden-woolfson auden-woolfson commented Jan 20, 2026

Description

Since Mongo treats views as regular documents, the find function that's used in the connector works fine. The change here is to prevent mongo from using functions that are not allowed on views when querying a view. In this instance, get indexes

Motivation and Context

Impact

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.

== NO RELEASE NOTE ==

 

Summary by Sourcery

Allow MongoDB connector to handle views without invoking unsupported index operations.

New Features:

  • Support querying MongoDB views by treating them as collections while avoiding view-incompatible operations.

Enhancements:

  • Skip index retrieval for MongoDB tables that are detected to be views by querying collection metadata.

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jan 20, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds view-awareness to the Mongo connector by short-circuiting index lookup for views and introducing a helper to detect MongoDB views via listCollections, ensuring disallowed operations are not used on views.

Sequence diagram for MongoSession.getIndexes handling views

sequenceDiagram
    actor PrestoPlanner
    participant MongoSession
    participant MongoClient
    participant MongoDatabase
    participant MongoCollection

    PrestoPlanner->>MongoSession: getIndexes(SchemaTableName)
    MongoSession->>MongoSession: isView(schema, table)
    MongoSession->>MongoClient: getDatabase(schema)
    MongoClient-->>MongoSession: MongoDatabase
    MongoSession->>MongoDatabase: runCommand(listCollections filter name, type=view)
    MongoDatabase-->>MongoSession: result Document
    MongoSession->>MongoSession: parse cursor.firstBatch
    alt is view
        MongoSession-->>PrestoPlanner: return empty MongoIndex list
    else is not view
        MongoSession->>MongoSession: getCollection(SchemaTableName)
        MongoSession->>MongoCollection: listIndexes()
        MongoCollection-->>MongoSession: indexDocuments
        MongoSession->>MongoSession: MongoIndex.parse(indexDocuments)
        MongoSession-->>PrestoPlanner: List<MongoIndex>
    end
Loading

Updated class diagram for MongoSession view-aware index lookup

classDiagram
    class MongoSession {
        +List~MongoIndex~ getIndexes(SchemaTableName tableName)
        +boolean isView(String schema, String table)
        -MongoClient client
        -LoadingCache~SchemaTableName, MongoTableHandle~ tableCache
        +MongoCollection~Document~ getCollection(SchemaTableName tableName)
        +MongoCollection~Document~ getCollection(String schema, String table)
        +void dropColumn(MongoTableHandle table, String columnName)
    }

    class MongoClient {
        +MongoDatabase getDatabase(String schema)
    }

    class MongoDatabase {
        +Document runCommand(Document command)
    }

    class MongoCollection {
        +ListIndexesIterable~Document~ listIndexes()
    }

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

    class MongoIndex {
        +List~MongoIndex~ parse(ListIndexesIterable~Document~ indexes)
    }

    class Document {
    }

    class LoadingCache~SchemaTableName, MongoTableHandle~ {
        +void invalidate(SchemaTableName key)
    }

    class MongoTableHandle {
        +SchemaTableName getSchemaTableName()
    }

    MongoSession --> MongoClient : uses
    MongoSession --> MongoDatabase : via client.getDatabase
    MongoSession --> MongoCollection : uses
    MongoSession --> SchemaTableName : parameter
    MongoSession --> MongoIndex : returns
    MongoSession --> Document : constructs commands
    MongoSession --> LoadingCache~SchemaTableName, MongoTableHandle~ : uses
    MongoSession --> MongoTableHandle : parameter
    MongoClient --> MongoDatabase : creates
    MongoDatabase --> Document : returns
    MongoCollection --> Document : returns
    MongoIndex --> Document : parses from
Loading

File-Level Changes

Change Details Files
Skip index retrieval for Mongo views and add a helper to detect views via MongoDB listCollections command.
  • Guard getIndexes with a view check so that it returns an empty list when the target is a view.
  • Introduce an isView helper that issues a listCollections command with a name and type filter to determine whether a collection is a view.
  • Extract and inspect the cursor.firstBatch result from the listCollections command response and derive the is-view result from whether it is empty.
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoSession.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

@auden-woolfson auden-woolfson changed the title getView first draft in session and metadata classes feat: Allow view querying with Mongo connector Jan 22, 2026
@auden-woolfson auden-woolfson marked this pull request as ready for review January 22, 2026 18:07
@auden-woolfson auden-woolfson requested a review from a team as a code owner January 22, 2026 18:07
@prestodb-ci prestodb-ci requested review from a team, bibith4 and nmahadevuni and removed request for a team January 22, 2026 18:07
@auden-woolfson auden-woolfson requested review from a team and BryanCutler January 22, 2026 18:08
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 - I've left some high level feedback:

  • The new isView check adds a round-trip listCollections command on every getIndexes call; consider caching view metadata or reusing existing table metadata to avoid repeated database commands on hot paths.
  • isView currently assumes the listCollections command succeeds and that the result always contains cursor/firstBatch; it would be safer to handle missing fields or command failures explicitly (e.g., permissions issues) to avoid unexpected runtime errors.
  • isView is declared public but appears to be an internal helper; if it’s not intended as part of the MongoSession API, consider making it private or package-private and/or taking SchemaTableName directly instead of separate schema/table strings for consistency with the rest of the class.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new isView check adds a round-trip listCollections command on every getIndexes call; consider caching view metadata or reusing existing table metadata to avoid repeated database commands on hot paths.
- isView currently assumes the listCollections command succeeds and that the result always contains cursor/firstBatch; it would be safer to handle missing fields or command failures explicitly (e.g., permissions issues) to avoid unexpected runtime errors.
- isView is declared public but appears to be an internal helper; if it’s not intended as part of the MongoSession API, consider making it private or package-private and/or taking SchemaTableName directly instead of separate schema/table strings for consistency with the rest of the class.

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
Member

@agrawalreetika agrawalreetika left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. Letf few comments.

Also, can we add test?

tableCache.invalidate(table.getSchemaTableName());
}

public boolean isView(String schema, String table)
Copy link
Member

Choose a reason for hiding this comment

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

Lets make it private

.get("cursor", Document.class)
.getList("firstBatch", Document.class);

return !collections.isEmpty();
Copy link
Member

Choose a reason for hiding this comment

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

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