-
Notifications
You must be signed in to change notification settings - Fork 389
[Trino] Adding explain query method #3645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,26 @@ def _get_columns(self, database, table): | |
] | ||
|
||
|
||
@query_error_handler | ||
def explain(self, notebook, snippet): | ||
statement = snippet['statement'].rstrip(';') | ||
explanation = '' | ||
|
||
if statement: | ||
try: | ||
TrinoQuery(self.trino_request, 'USE ' + snippet['database']).execute() | ||
result = TrinoQuery(self.trino_request, 'EXPLAIN ' + statement).execute() | ||
explanation = result.rows | ||
except Exception as e: | ||
explanation = str(e) | ||
|
||
return { | ||
'status': 0, | ||
wing2fly marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the TrinoQuery.execute() throws any exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the try catch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wing2fly we should try to move away from using the status flag, today API users expect the proper http error code when something goes bad. That being said the UI might have some old code that checks for status == 0. |
||
'explanation': explanation, | ||
'statement': statement | ||
} | ||
|
||
|
||
def download(self, notebook, snippet, file_format='csv'): | ||
result_wrapper = TrinoExecutionWrapper(self, notebook, snippet) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding error in explanation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what we are doing in the Hive also
https://github.com/cloudera/hue/blob/master/desktop/libs/notebook/src/notebook/connectors/hiveserver2.py#L608
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JohanAhlen Is UI expecting this for both editor v1 and editor v2?
Just a heads up, we need to improve all this flow then once we pick up this roadmap item. cc @agl29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit odd indeed, @agl29 did you try how the UI behave if you would return a 500 request with the error message instead?