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(sql): unable to filter text with quotes #17881

Merged
merged 12 commits into from
Jan 28, 2022

Conversation

stephenLYZ
Copy link
Member

@stephenLYZ stephenLYZ commented Dec 28, 2021

SUMMARY

This PR fixes the problem that the double/single quote will be dropped in SQL query when using filters.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before

image

After

image

image

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue: Fixes Wrong SQL generated when filter is used #11639
  • 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

@stephenLYZ stephenLYZ marked this pull request as draft January 1, 2022 16:11
@stephenLYZ stephenLYZ marked this pull request as ready for review January 1, 2022 16:11
@codecov
Copy link

codecov bot commented Jan 1, 2022

Codecov Report

Merging #17881 (beefae0) into master (ea2d668) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #17881   +/-   ##
=======================================
  Coverage   66.05%   66.05%           
=======================================
  Files        1591     1591           
  Lines       62423    62423           
  Branches     6287     6287           
=======================================
  Hits        41233    41233           
  Misses      19568    19568           
  Partials     1622     1622           
Flag Coverage Δ
hive 52.17% <100.00%> (ø)
mysql 81.28% <100.00%> (ø)
postgres 81.33% <100.00%> (ø)
presto 52.01% <100.00%> (ø)
python 81.77% <100.00%> (ø)
sqlite 81.03% <100.00%> (ø)

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

Impacted Files Coverage Δ
superset/connectors/base/models.py 88.58% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea2d668...beefae0. Read the comment docs.

@pull-request-size pull-request-size bot added size/S and removed size/XS labels Jan 2, 2022
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this. I went through the git blame logs, and it appears this change was added in #4651, so a very long time ago. In addition, it was originally prefixed with the comment "backward compatibility with previous components", so I'm not entirely sure we need this anymore - maybe just handle the special cases '' and "", but even those seem dubious. I wonder if @betodealmeida or @hughhhh happen to still remember this case? Also, the unit tests should probably not be implemented using DruidColumn, as the whole native Druid connector is in the process of being deprecated. Ping me if you want to discuss an alternative testing solution.

@zhaoyongjie
Copy link
Member

zhaoyongjie commented Jan 5, 2022

Hi @villebro . I have discussed this issue with @stephenLYZ. This issue requires more consideration.

  1. different database dialects
  2. how to escape reserved words

There is a virtual dataset (for Postgresql) for test this issue.

SELECT 
'"text in double quotes"' as name
UNION
SELECT '''text in singlequotes''' as name
UNION
SELECT 'double quotes " in text' as name
UNION
SELECT 'single quotes '' in text' as name

@stephenLYZ
Copy link
Member Author

stephenLYZ commented Jan 5, 2022

Yeah. I tried to use it locally. When I try to filter name = '"text in double quotes"', the response data seems to be not correct.
image

@rusackas
Copy link
Member

@stephenLYZ are there more tests to be added to this PR before final review? CC @zhaoyongjie

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jan 28, 2022
),
database=get_example_database(),
)
TableColumn(column_name="foo", type="VARCHAR(255)", table=table)
SqlMetric(metric_name="count", expression="count(*)", table=table)
yield table
Copy link
Member

Choose a reason for hiding this comment

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

table wasn't persisted so we no need delete command.

@zhaoyongjie zhaoyongjie changed the title fix(sql): missing quotes in sql fix(sql): unable to filter text in quotes Jan 28, 2022
@zhaoyongjie zhaoyongjie changed the title fix(sql): unable to filter text in quotes fix(sql): unable to filter text with quotes Jan 28, 2022
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM - good test (+115 +61) to functional code change ratio (+1 -1) 😄

@zhaoyongjie zhaoyongjie merged commit 9671384 into apache:master Jan 28, 2022
shcoderAlex pushed a commit to casual-precision/superset that referenced this pull request Feb 7, 2022
@serenajiang
Copy link
Contributor

@villebro @stephenLYZ While this fix is definitely a good direction, can we make sure to add this to UPDATING.md as a breaking change, since it changes how string filters work?

After deploying this fix, we found out that a lot of our users had been wrapping strings in quotes, so a ton of important charts broke. I think the previous behavior made some people think that you had to wrap string filter values in quotes.

@villebro
Copy link
Member

villebro commented Feb 8, 2022

@serenajiang thanks for flagging this and apologies for the inconvenience. This was a good reminder to always flag breaking changes in UPDATING.md, even if they may seem like pure bugfixes from a developer's perspective. I'll open a PR shortly and be more vigilant going forward.

ofekisr pushed a commit to nielsen-oss/superset that referenced this pull request Feb 8, 2022
@zhaoyongjie
Copy link
Member

zhaoyongjie commented Feb 9, 2022

@serenajiang @villebro
Thanks for the mention and sorry to introduce this broken change. In addition to update UPDATING.md, should we open a backport feature flag to ensure compatibility?

bwang221 pushed a commit to casual-precision/superset that referenced this pull request Feb 10, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.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/L 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants