-
Notifications
You must be signed in to change notification settings - Fork 15k
chore(explore): Add format sql and view in SQL Lab option in View Query #33341
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
base: master
Are you sure you want to change the base?
chore(explore): Add format sql and view in SQL Lab option in View Query #33341
Conversation
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.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Status |
---|---|---|
Unexplained API Query Parameters ▹ view | 🧠 Not in scope | |
Unexplained Magic String Separator ▹ view | 🧠 Incorrect | |
Missing Error Handling in API Calls ▹ view | 🧠 Not in scope |
Files scanned
File Path | Reviewed |
---|---|
superset-frontend/src/explore/components/controls/ViewQueryModal.tsx | ✅ |
superset-frontend/src/explore/components/controls/ViewQuery.tsx | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
const queryParams = rison.encode({ | ||
keys: ['none'], | ||
columns: ['database.backend'], | ||
}); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
SupersetClient.get({ | ||
endpoint: `/api/v1/dataset/${datasetId}?q=${queryParams}`, | ||
}).then(({ json }) => { | ||
SupersetClient.post({ | ||
endpoint: `/api/v1/sqllab/format_sql/`, | ||
body: JSON.stringify({ | ||
sql, | ||
engine: json.result.database.backend, | ||
}), | ||
headers: { 'Content-Type': 'application/json' }, | ||
}).then(({ json }) => { | ||
setFormattedSQL(json.result); | ||
setShowFormatSQL(true); | ||
}); | ||
}); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
const StyledSyntaxHighlighter = styled(SyntaxHighlighter)` | ||
flex: 1; | ||
`; | ||
|
||
const ViewQuery: FC<ViewQueryProps> = props => { | ||
const { sql, language = 'sql' } = props; | ||
const { sql, language = 'sql', datasource } = props; | ||
const datasetId = datasource.split('__')[0]; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@justinpark The About the "Format SQL" feature, I think a formatted SQL is better for users when visualizing a query. Given that #30350 states:
and the fact that the dialect will not be generic most of the time, I wonder if we should always format the SQL when visualizing the query. To be clear, I'm not proposing reverting @betodealmeida's changes but to always format the SQL when clicking on If the dialect is generic, then you could always show the non-formatted version of the query and warning saying that the SQL can't be formatted for that database type. Pinging @betodealmeida, who probably has more context, to review too. |
I like the idea too. Since the formatted SQL in this section doesn't modify the original SQL, it should be okay. |
3c4dae5
to
c79e886
Compare
const getFormatSwitch = () => | ||
screen.getByRole('switch', { name: 'Show original SQL' }); | ||
|
||
it('renders the component with Formatted SQL and buttons', async () => { |
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.
Can you use test
instead of it
?
SUMMARY
The "View Query" feature was previously used to display SQL in a formatted manner. However, the prettier formatting was reverted in this pull request due to unintended changes in the original SQL. To minimize the impact while retaining the formatting option, this commit introduces a "Format SQL" feature in View Query modal and an option to show the original SQL for comparison. Additionally, this commit adds a "View in SQL Lab" button, allowing users to conveniently connect to SQL Lab directly from the dashboard, which is particularly useful for users.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:

After:
after--view-query-actions.mov
TESTING INSTRUCTIONS
Click "View Query" in the chart or explore and then check the toolbars above.
ADDITIONAL INFORMATION