fix: % replace in values_for_column
#28271
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
When we run a query we replace
%%
(in certain SQLAlchemy dialects) with%
:superset/superset/models/core.py
Lines 668 to 669 in 76d897e
These dialects use
pyformat
(%(name)s
) orformat
(%s
) to parameterize arguments passed to the cursor. Normally we'd need to pass%%
for literal percent signs, but the current behavior for most databases (Postgres, Presto, MySQL, Hive, Druid) is to accept unescaped percent symbols when no parameters are passed — which is the case for the calls Superset does tocursor.execute
.This logic is missing from
values_for_column
, which results in queries that are valid but, for some reason, extremely slow in Druid:While the expected query is fast:
This PR adds the same behavior to the
values_for_column
method.Note that while drivers accept unescaped percent symbols when no parameters are passed to the cursor, this behavior is undocument in the DB API 2.0 spec. Ideally we'd not do this replacement in Superset, and instead:
%
by replacing it with%%
before sending the query to the DB.%%
back to%
.This way Superset is not relying on undocument behavior. But that fix is more complicated and requires a lot of testing.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION