[ZEPPELIN-6234] fix: table() function not working#4987
Conversation
tbonelee
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Shouldn't we apply tableLimit here as well, like in line 102?
There was a problem hiding this comment.
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); | ||
| } | ||
| } |
There was a problem hiding this comment.
What do you think about merging the existing table prototype logic into ensureTableFunction to avoid duplication?
There was a problem hiding this comment.
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!
### 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>
|
Merged into master and branch-0.12 |
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:
What type of PR is it?
Bug Fix
Todos
What is the Jira issue?
How should this be tested?
%tableformat renders properly in Zeppelin UI.Screenshots (if appropriate)
Questions: