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(dashboard): Native filters - add type to native filter configuration #16549

Merged

Conversation

m-ajay
Copy link
Contributor

@m-ajay m-ajay commented Sep 1, 2021

SUMMARY

In a future PR, we will add a "Section" component to the native filters. We will need a new key to distinguish between them.

TESTING INSTRUCTIONS

Testing existing filters

  1. Run migration using superset db upgrade
  2. Verify in the dashboards DB table that all the filters have a type (Check json_metadata column in dashboards table)
    Testing new filters
  3. Add a new filter
  4. Make sure that the type key appears in the new filter (Check json_metadata column in dashboards table)

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

@m-ajay m-ajay requested a review from a team as a code owner September 1, 2021 16:35
@codecov
Copy link

codecov bot commented Sep 1, 2021

Codecov Report

Merging #16549 (cea8a7d) into master (c5a5cf7) will decrease coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16549      +/-   ##
==========================================
- Coverage   76.71%   76.55%   -0.16%     
==========================================
  Files        1002     1004       +2     
  Lines       53784    53964     +180     
  Branches     6859     7332     +473     
==========================================
+ Hits        41259    41312      +53     
- Misses      12288    12412     +124     
- Partials      237      240       +3     
Flag Coverage Δ
hive ?
javascript 71.08% <100.00%> (+0.08%) ⬆️
mysql 81.54% <ø> (+<0.01%) ⬆️
postgres 81.60% <ø> (+0.04%) ⬆️
presto ?
python 81.69% <ø> (-0.38%) ⬇️
sqlite 81.25% <ø> (+0.08%) ⬆️

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

Impacted Files Coverage Δ
...mponents/nativeFilters/FiltersConfigModal/utils.ts 72.22% <ø> (-1.39%) ⬇️
...nd/src/dashboard/components/nativeFilters/utils.ts 56.25% <ø> (ø)
...onfigModal/FiltersConfigForm/FiltersConfigForm.tsx 73.20% <100.00%> (+0.07%) ⬆️
...nd/src/dashboard/components/nativeFilters/types.ts 100.00% <100.00%> (ø)
superset/db_engines/hive.py 0.00% <0.00%> (-82.15%) ⬇️
superset/db_engine_specs/hive.py 69.80% <0.00%> (-16.87%) ⬇️
superset/db_engine_specs/presto.py 83.47% <0.00%> (-6.91%) ⬇️
superset/views/database/mixins.py 81.03% <0.00%> (-1.73%) ⬇️
superset/connectors/sqla/models.py 88.04% <0.00%> (-1.66%) ⬇️
... and 34 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 c5a5cf7...cea8a7d. Read the comment docs.

@graceguo-supercat
Copy link

graceguo-supercat commented Sep 2, 2021

Hi @m-ajay this PR is good. After this PR is merged and migration is executed, all exist native filter components should have a type property, but how about new filter component in the new dashboard, which will be created in the near future?
Besides migration, should we also add default type in the code at the same time?

@m-ajay
Copy link
Contributor Author

m-ajay commented Sep 2, 2021

Hi @m-ajay this PR is good. After this PR is merged and migration is executed, all exist native filter components should have a type property, but how about new filter component in the new dashboard, which will be created in the near future?
Besides migration, should we also add default type in the code at the same time?

@Grace Thanks for the review.
I'm adding type as NATIVE_FILTER when creating a new filter. In the future, when we add a section, we will add type as SECTION

)
continue

json_meta = json.loads(dashboard.json_metadata)
Copy link
Member

Choose a reason for hiding this comment

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

You might want to wrap this in a try/except since some charts could store invalid JSON. You can see how other migrations handle this.

json_meta = json.loads(dashboard.json_metadata)

for native_filter in json_meta.get("native_filter_configuration", []):
native_filter.setdefault("type", "NATIVE_FILTER")
Copy link
Member

Choose a reason for hiding this comment

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

Why not just native_filter["type"] = "NATIVE_FILTER" if type is a new key (which per line 90 it would indicate that it is)? I always forget how dict.setdefault works as it's rarely used.


for native_filter in json_meta.get("native_filter_configuration", []):
native_filter.setdefault("type", "NATIVE_FILTER")
dashboard.json_metadata = json.dumps(json_meta)
Copy link
Member

Choose a reason for hiding this comment

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

For efficiency we likely should only be updating dashboard.json_metadata for those dashboards which were modified, so maybe something of the form,

if "native_filter_configuration" in json_meta:
    for native_filter in json_meta["native_filter_configuration"]:
        native_filter["type"] = "NATIVE_FILTER"
    
    dashboard.json_metadata = json.dumps(json_meta)

@pull-request-size pull-request-size bot added size/L and removed size/M labels Sep 3, 2021
Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

this lgtm, i love the verbose logging in the db migration too, it makes it easy to understand exactly what's happening

@etr2460 etr2460 merged commit 4b70d46 into apache:master Sep 9, 2021
@m-ajay m-ajay deleted the feat/migration-add-type-to-native-filter branch September 9, 2021 20:50
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
…tion (apache#16549)

* iSort fixes

* Add type key to the new filters

* Fix wrong attribute

* PR comments

* PR comments

* Fix failing tests
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
…tion (apache#16549)

* iSort fixes

* Add type key to the new filters

* Fix wrong attribute

* PR comments

* PR comments

* Fix failing tests
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.4.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.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants