-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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: don't strip SQL comments in Explore - 2nd try #28753
Changes from all commits
bf49d2b
8853fdb
bd2a0cc
ce38129
2442a55
caf153e
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 |
---|---|---|
|
@@ -24,7 +24,7 @@ jobs: | |
mysql+mysqldb://superset:[email protected]:13306/superset?charset=utf8mb4&binary_prefix=true | ||
services: | ||
mysql: | ||
image: mysql:5.7 | ||
image: mysql:8.0 | ||
env: | ||
MYSQL_ROOT_PASSWORD: root | ||
ports: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1450,7 +1450,7 @@ def get_from_clause( | |
if not self.is_virtual: | ||
return self.get_sqla_table(), None | ||
|
||
from_sql = self.get_rendered_sql(template_processor) | ||
from_sql = self.get_rendered_sql(template_processor) + "\n" | ||
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. This is the fix compared to the original PR, basically forcing a line break after the FROM clause subquery. -- BEFORE, notice how the `) AS` is in-comment
{...}
FROM cte --COMMENT) AS virtual_table GROUP BY col1, col2
-- AFTER, notice the line break after the comment, allowing proper aliasing of the subquery
{...}
FROM cte --COMMENT
) AS virtual_table GROUP BY col1, col2 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. My only suggestion would be to add a comment in the code explaining why do we need the line break. 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. @mistercrunch just to verify, does this logic work for |
||
parsed_query = ParsedQuery(from_sql, engine=self.db_engine_spec.engine) | ||
if not ( | ||
parsed_query.is_unknown() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1070,8 +1070,7 @@ def get_rendered_sql( | |
""" | ||
Render sql with template engine (Jinja). | ||
""" | ||
|
||
sql = self.sql | ||
sql = self.sql.strip("\t\r\n; ") | ||
if template_processor: | ||
try: | ||
sql = template_processor.process_template(sql) | ||
|
@@ -1083,13 +1082,12 @@ def get_rendered_sql( | |
) | ||
) from ex | ||
|
||
script = SQLScript(sql.strip("\t\r\n; "), engine=self.db_engine_spec.engine) | ||
script = SQLScript(sql, engine=self.db_engine_spec.engine) | ||
if len(script.statements) > 1: | ||
raise QueryObjectValidationError( | ||
_("Virtual dataset query cannot consist of multiple statements") | ||
) | ||
|
||
sql = script.statements[0].format(comments=False) | ||
if not sql: | ||
raise QueryObjectValidationError(_("Virtual dataset query cannot be empty")) | ||
return sql | ||
|
@@ -1106,7 +1104,7 @@ def get_from_clause( | |
CTE, the CTE is returned as the second value in the return tuple. | ||
""" | ||
|
||
from_sql = self.get_rendered_sql(template_processor) | ||
from_sql = self.get_rendered_sql(template_processor) + "\n" | ||
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. i noticed (again) that superset/connectors/sqla/models.py and superset/models/helpers.py have a fair amount of copy/pasta/dup-logic. I'll try and fix that in a future PR. |
||
parsed_query = ParsedQuery(from_sql, engine=self.db_engine_spec.engine) | ||
if not ( | ||
parsed_query.is_unknown() | ||
|
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.
Not sure if this was intended as part of this PR 🤷🏼♂️
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 I should have added a note, but my new unit test
test_virtual_dataset_with_comments
uses "in-a-subquery CTE", which apparently isn't supported in mysql5.7
, failing that one test against old mysql. That CTE is one way that I was able to reproduce some of the issues from the previous reverted PR.Given the wikipedia page, 5.7 isn't supported anymore and 8.0 is the next release. I'm unclear about the gap but might have considered doing a smaller bump if there was an option. Bumping to 8.0 seems like the right move.
![Screenshot 2024-06-20 at 12 29 04 PM](https://private-user-images.githubusercontent.com/487433/341539299-4c3974dd-c4fd-4c3e-a670-e1db2bc0514b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNjQyOTIsIm5iZiI6MTczOTE2Mzk5MiwicGF0aCI6Ii80ODc0MzMvMzQxNTM5Mjk5LTRjMzk3NGRkLWM0ZmQtNGMzZS1hNjcwLWUxZGIyYmMwNTE0Yi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMFQwNTA2MzJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mZGJiMDlkMmU4NGE2ZWYwYTFiM2M2OGY3ZTBkNzk4OWQyODE2OGEzOWUwYmU0YTk4ZDE4MzhiMjUzMTZkNTE3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.95s1_M3b9N1qYTarsnFrKvCA7IXBbG9EVFM-6ZFPdf8)