Skip to content
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

fix(sqllab): throw errors of commented out query #23378

Merged
merged 3 commits into from
Mar 23, 2023

Conversation

justinpark
Copy link
Member

SUMMARY

sqllab threw an error for undefined parameters even when those parameters are commented out of/not used by the query.
This commit cleans out the commented out part from the requested query to fix the issue (and also reduce the payload size since commented-out parts are unnecessary)

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

After:

Screenshot 2023-03-14 at 3 55 17 PM

Before:
Screenshot 2023-03-14 at 3 54 23 PM

TESTING INSTRUCTIONS

Go to sqllab and then run a query including a template string within comment-out block like select 123 --,{{ds}}

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Merging #23378 (b82e57e) into master (db95a93) will increase coverage by 1.72%.
The diff coverage is 86.90%.

❗ Current head b82e57e differs from pull request most recent head 2e3b6c5. Consider uploading reports for the commit 2e3b6c5 to get more accurate results

@@            Coverage Diff             @@
##           master   #23378      +/-   ##
==========================================
+ Coverage   65.91%   67.64%   +1.72%     
==========================================
  Files        1907     1908       +1     
  Lines       73453    73741     +288     
  Branches     7976     7987      +11     
==========================================
+ Hits        48420    49881    +1461     
+ Misses      22983    21814    -1169     
+ Partials     2050     2046       -4     
Flag Coverage Δ
javascript 53.82% <77.24%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...-core/src/hooks/useChangeEffect/useChangeEffect.ts 100.00% <ø> (ø)
...hooks/useComponentDidMount/useComponentDidMount.ts 100.00% <ø> (ø)
...oks/useComponentDidUpdate/useComponentDidUpdate.ts 100.00% <ø> (ø)
...src/hooks/useElementOnScreen/useElementOnScreen.ts 100.00% <ø> (ø)
...erset-ui-core/src/hooks/usePrevious/usePrevious.ts 100.00% <ø> (ø)
...re/src/hooks/useTruncation/useCSSTextTruncation.ts 100.00% <ø> (ø)
...c/hooks/useTruncation/useChildElementTruncation.ts 100.00% <ø> (ø)
...ackages/superset-ui-core/src/utils/featureFlags.ts 100.00% <ø> (ø)
...s/legacy-plugin-chart-country-map/src/countries.ts 100.00% <ø> (ø)
...chart-echarts/src/Timeseries/Area/controlPanel.tsx 40.00% <ø> (ø)
... and 102 more

... and 74 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@justinpark
Copy link
Member Author

@michael-s-molina could you help this code review?

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thank you for the PR @justinpark. I left a couple of comments.

export function cleanSqlComments(sql) {
if (!sql) return '';

return sql.replace(/(\/\*[^*]*\*\/)|(\/\/[^*]*)|(--[^.].*)/gm, '').trim();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return sql.replace(/(\/\*[^*]*\*\/)|(\/\/[^*]*)|(--[^.].*)/gm, '').trim();
// group 1 -> /* */
// group 2 -> //
// group 3 -> --
return sql.replace(/(\/\*[^*]*\*\/)|(\/\/[^*]*)|(--[^.].*)/gm, '').trim();

Copy link
Member

Choose a reason for hiding this comment

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

select * queries are only supported by double dashes. I'm not sure if you want to support them for other comment types.

Screenshot 2023-03-17 at 10 43 33

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch. I'll update the pr to support other styles too.

Copy link
Member Author

Choose a reason for hiding this comment

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

According to the current editor inspection, it won't accept the group 2 style //.
I'll update to clean up both cases of /* */ and --

Screenshot 2023-03-22 at 2 59 45 PM

Copy link
Member

Choose a reason for hiding this comment

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

It seems there's a case with empty spaces where it's matching but it shouldn’t.

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-s-molina just update to preserve the newlines.

Copy link
Member

Choose a reason for hiding this comment

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

@justinpark The latest update broke // comments. You can test the regex here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-s-molina that's intended.

As I mentioned above, // comment visually not recognized as comment-out block so it doesn't sanitize the // comments.

fix_sqllab___throw_errors_of_commented_out_query_by_justinpark_·_Pull_Request__23378_·_apache_superset

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see. Thank you for the clarification.

@justinpark
Copy link
Member Author

@michael-s-molina could you help the review for updates?

@michael-s-molina
Copy link
Member

@michael-s-molina could you help the review for updates?

@justinpark I reviewed and left this comment.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM

@justinpark justinpark merged commit d1947f7 into apache:master Mar 23, 2023
justinpark added a commit to airbnb/superset-fork that referenced this pull request Mar 23, 2023
justinpark added a commit to airbnb/superset-fork that referenced this pull request Mar 24, 2023
justinpark added a commit to airbnb/superset-fork that referenced this pull request Apr 18, 2023
justinpark added a commit to justinpark/superset that referenced this pull request May 10, 2023
justinpark added a commit to airbnb/superset-fork that referenced this pull request May 10, 2023
john-bodley added a commit to airbnb/superset-fork that referenced this pull request May 10, 2023
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants