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

feat: add a where_in filter for Jinja2 #19574

Merged
merged 1 commit into from
Apr 7, 2022

Conversation

betodealmeida
Copy link
Member

@betodealmeida betodealmeida commented Apr 6, 2022

SUMMARY

Using the Jinja2 function filter_values in WHERE clauses today is very cumbersome, requiring the user to quote and join elements from the list:

SELECT * FROM some_table
WHERE
    action in ({{ "'" + "','".join(filter_values('action_type')) + "'" }})

I created a simple where_in filter that does the same logic, since this is a common pattern for users. With the filter users only need to write:

SELECT * FROM some_table
WHERE
    action IN {{ filter_values('action_type')|where_in }}

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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 Apr 6, 2022

Codecov Report

Merging #19574 (a088d37) into master (444b4f5) will decrease coverage by 12.70%.
The diff coverage is 100.00%.

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

@@             Coverage Diff             @@
##           master   #19574       +/-   ##
===========================================
- Coverage   66.65%   53.94%   -12.71%     
===========================================
  Files        1680     1680               
  Lines       64271    64280        +9     
  Branches     6564     6564               
===========================================
- Hits        42842    34679     -8163     
- Misses      19727    27899     +8172     
  Partials     1702     1702               
Flag Coverage Δ
hive 52.70% <22.22%> (-0.01%) ⬇️
mysql ?
postgres ?
presto 52.55% <22.22%> (-0.01%) ⬇️
python 56.52% <100.00%> (-25.87%) ⬇️
sqlite ?
unit 47.22% <88.88%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
superset/jinja_context.py 74.75% <100.00%> (-15.10%) ⬇️
superset/utils/dashboard_import_export.py 0.00% <0.00%> (-100.00%) ⬇️
superset/key_value/commands/upsert.py 0.00% <0.00%> (-89.59%) ⬇️
superset/key_value/commands/update.py 0.00% <0.00%> (-89.37%) ⬇️
superset/key_value/commands/delete.py 0.00% <0.00%> (-85.30%) ⬇️
superset/key_value/commands/delete_expired.py 0.00% <0.00%> (-80.77%) ⬇️
superset/dashboards/commands/importers/v0.py 14.79% <0.00%> (-75.15%) ⬇️
superset/datasets/commands/importers/v0.py 24.82% <0.00%> (-68.80%) ⬇️
superset/databases/commands/test_connection.py 31.42% <0.00%> (-68.58%) ⬇️
superset/datasets/commands/update.py 25.88% <0.00%> (-68.24%) ⬇️
... and 264 more

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 444b4f5...fe9f417. Read the comment docs.

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.

Love it! ❤️

@betodealmeida betodealmeida merged commit 83c3779 into apache:master Apr 7, 2022
philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.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 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants