-
Notifications
You must be signed in to change notification settings - Fork 14k
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): clean comments within quotes #23908
fix(sqllab): clean comments within quotes #23908
Conversation
Codecov Report
@@ Coverage Diff @@
## master #23908 +/- ##
=======================================
Coverage 68.11% 68.12%
=======================================
Files 1938 1940 +2
Lines 74972 75048 +76
Branches 8141 8155 +14
=======================================
+ Hits 51067 51124 +57
- Misses 21826 21841 +15
- Partials 2079 2083 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
66791a0
to
944d22b
Compare
70f21e3
to
167d6a2
Compare
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.
LGTM but it would be nice to get @villebro and @betodealmeida approvals too.
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.
Interesting approach
) | ||
.join('') | ||
// Clean out the commented-out blocks | ||
.replace(/(--.*?$|\/\*[\s\S]*?\*\/)\n?/gm, '\n') |
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.
.replace(/(--.*?$|\/\*[\s\S]*?\*\/)\n?/gm, '\n') | |
.replace(/(--.*$|\/\*[\s\S]*\*\/)\n?/gm, '\n') |
I don't think these question marks are necessary
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.
This ?
mark covers the multiple comment group case
i.e.
/*
comments
*/
no-comments
/*
comments
*/
.replace(/(--.?$|/*[\s\S]?*/)\n?/gm, '\n') => no-comments
.replace(/(--.$|/*[\s\S]*/)\n?/gm, '\n') => '\n'
@justinpark @michael-s-molina @ktmud we have a fair deal of logic for this in the backend - is there some reason we want to parse for this kind of stuff in the frontend? It feels like we should centralize this in one place. |
I didn't know about that @villebro. Could you point to the code? I agree that if there's no reason for doing it in the frontend, we should centralize it in the backend. |
I agree this logic is probably better to live in the backend---it's more useful to record the original SQL users wrote, too. Not sure how comments are removed in the backend but my guess is it happens after we render the Jinja template (which is why we saw the error in #23378 in the first place). Maybe we can change it to remove comments before rendering, but how would you know the comments are safe to remove without rendering the template? Also, if we are removing comments using a SQL parser, the parser is likely to fail before you render the template. Not sure what's the best way forward, but since we are already removing comments in the frontend, it's probably still worth merging this PR first. |
I agree with ktmud's idea |
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.
@ktmud @justinpark I agree, this is an improvement to the status quo; we can follow up later by moving this into the backend. @michael-s-molina you can check superset/sql_parse.py
which we use for parsing queries in the backend, and I seem to recall having added tests that ensure '--comment'
aren't stripped out, which is very similar to what's being checked here.
Sounds good. yeah definitely backend is a better place. until then, we can use this solution |
This reverts commit 841726d.
This reverts commit 63d8015.
(cherry picked from commit 841726d)
This reverts commit 841726d.
SUMMARY
minor regression from #23378
The regex for commented out block also clean up the block within the quotes.
Therefore following query threw a syntax error since it removes the quoted value.
This commit adds the condition to skip the quoted block.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
After:
Before:
TESTING INSTRUCTIONS
Added tests for edge cases
ADDITIONAL INFORMATION