Skip to content

[ZEPPELIN-6234] fix: table() function not working#4987

Merged
ParkGyeongTae merged 2 commits into
apache:masterfrom
kmularise:ZEPPELIN-6234
Aug 28, 2025
Merged

[ZEPPELIN-6234] fix: table() function not working#4987
ParkGyeongTae merged 2 commits into
apache:masterfrom
kmularise:ZEPPELIN-6234

Conversation

@kmularise

Copy link
Copy Markdown
Contributor

What is this PR for?

This PR introduces the ensureTableFunction() method to enhance compatibility with mongosh (MongoDB Shell) in the Apache Zeppelin Mongo interpreter context. Previously, the .table() function was attached to DBQuery.prototype, which may not be sufficient in newer MongoDB environments where command cursors or altered prototypes are used.
The new method safely injects the .table() utility function into relevant cursor prototypes at runtime, ensuring table rendering works as expected even under mongosh.

Additionally, the changes:

  • Introduce safer prototype extension using a dummy cursor check.
  • Preserve the original behavior for backwards compatibility.
  • Avoid redundant registration in unsupported environments.

What type of PR is it?

Bug Fix

Todos

  • - Add ensureTableFunction() for dynamic prototype injection

What is the Jira issue?

  • ZEPPELIN-6234: MongoDB interpreter: .table() function not working

How should this be tested?

  1. Use Apache Zeppelin with the MongoDB interpreter.
  2. Connect to a MongoDB 8.x instance using mongosh.
  3. Execute a standard query with .table():
db.collection.find().table()
  1. Verify:
  • %table format renders properly in Zeppelin UI.
  • No registration or prototype errors occur in shell.
  • Legacy Mongo Shells continue to function as before.

Screenshots (if appropriate)

Pasted Graphic

Questions:

  • Does the license files need to update? No
  • Is there breaking changes for older versions? No. The solution maintains backward compatibility.
  • Does this needs documentation? Optional. Could be mentioned in Mongo interpreter tips or mongosh compatibility notes.

tbonelee
tbonelee previously approved these changes Jul 22, 2025

@tbonelee tbonelee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Ran some sample queries with MongoDB interpreter, and everything worked as expected

var proto = Object.getPrototypeOf(sampleCursor);

if (proto && !proto.table) {
proto.table = tableFunc;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we apply tableLimit here as well, like in line 102?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I missed applying the tableLimit check in the tableFunc. I'll update the code to include the tableLimit check.

} catch (e) {
print("Registration Error: prototype registration failed:", e.message);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think about merging the existing table prototype logic into ensureTableFunction to avoid duplication?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think you're right to avoid duplication. Looking at this again, there's potential for duplicate registration, and merging into ensureTableFunction makes more sense. I'll move the existing table prototype logic into ensureTableFunction.

Thanks for the feedback!

@jongyoul jongyoul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ParkGyeongTae ParkGyeongTae left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 LGTM

@ParkGyeongTae ParkGyeongTae merged commit ade854e into apache:master Aug 28, 2025
15 of 18 checks passed
ParkGyeongTae pushed a commit that referenced this pull request Aug 28, 2025
### What is this PR for?
This PR introduces the ensureTableFunction() method to enhance compatibility with mongosh (MongoDB Shell) in the Apache Zeppelin Mongo interpreter context. Previously, the .table() function was attached to DBQuery.prototype, which may not be sufficient in newer MongoDB environments where command cursors or altered prototypes are used.
The new method safely injects the .table() utility function into relevant cursor prototypes at runtime, ensuring table rendering works as expected even under mongosh.

Additionally, the changes:

- Introduce safer prototype extension using a dummy cursor check.
- Preserve the original behavior for backwards compatibility.
- Avoid redundant registration in unsupported environments.

### What type of PR is it?
Bug Fix

### Todos
* [x] - Add ensureTableFunction() for dynamic prototype injection

### What is the Jira issue?
* [ZEPPELIN-6234](https://issues.apache.org/jira/browse/ZEPPELIN-6234): MongoDB interpreter: .table() function not working

### How should this be tested?
1. Use Apache Zeppelin with the MongoDB interpreter.
2. Connect to a MongoDB 8.x instance using mongosh.
3. Execute a standard query with .table():
```js
db.collection.find().table()
```

4. Verify:
- `%table` format renders properly in Zeppelin UI.
- No registration or prototype errors occur in shell.
- Legacy Mongo Shells continue to function as before.

### Screenshots (if appropriate)
<img width="510" height="270" alt="Pasted Graphic" src="https://github.com/user-attachments/assets/9da70f3e-739a-46fa-819a-b8877de213cc" />

### Questions:
* Does the license files need to update? No
* Is there breaking changes for older versions? No. The solution maintains backward compatibility.
* Does this needs documentation? Optional. Could be mentioned in Mongo interpreter tips or mongosh compatibility notes.

Closes #4987 from kmularise/ZEPPELIN-6234.

Signed-off-by: ParkGyeongTae <gyeongtae@apache.org>
(cherry picked from commit ade854e)
Signed-off-by: ParkGyeongTae <gyeongtae@apache.org>
@ParkGyeongTae

Copy link
Copy Markdown
Member

Merged into master and branch-0.12

@ParkGyeongTae ParkGyeongTae self-assigned this Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants