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(viz): deduce metric name if empty #16194

Merged
merged 2 commits into from
Aug 12, 2021

Conversation

villebro
Copy link
Member

@villebro villebro commented Aug 11, 2021

SUMMARY

This is part 1 of a fix for #16067 to make the backend more resilient to incomplete chart metadata. If an adhoc metric is missing the label property, the backend can in most cases deduce what the label should be. Since the util get_metric_name is used in quite a few places in the backend and didn't have a single unit test, this PR also adds tests to ensure that the function works as expected. In addition, related types are improved and affected code updated.

AFTER

image

BEFORE

image

TESTING INSTRUCTIONS

  1. create an adhoc metric that either has a missing or empty label
  2. make a chart data request
  3. notice how the request fails

ADDITIONAL INFORMATION

  • Has associated issue:
  • 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 Aug 11, 2021

Codecov Report

Merging #16194 (ddf06b6) into master (4df3672) will decrease coverage by 0.12%.
The diff coverage is 93.75%.

❗ Current head ddf06b6 differs from pull request most recent head 0aa628f. Consider uploading reports for the commit 0aa628f to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16194      +/-   ##
==========================================
- Coverage   76.83%   76.70%   -0.13%     
==========================================
  Files         996      996              
  Lines       53060    53095      +35     
  Branches     6766     6766              
==========================================
- Hits        40766    40729      -37     
- Misses      12066    12138      +72     
  Partials      228      228              
Flag Coverage Δ
hive ?
mysql 81.59% <97.82%> (+0.01%) ⬆️
postgres 81.65% <97.82%> (+0.06%) ⬆️
presto 81.48% <97.82%> (+0.05%) ⬆️
python 81.91% <97.82%> (-0.25%) ⬇️
sqlite 81.25% <97.82%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
...ontrols/DndColumnSelectControl/DndMetricSelect.tsx 41.78% <0.00%> (ø)
superset/common/query_object.py 90.66% <ø> (ø)
superset/typing.py 97.77% <94.44%> (-2.23%) ⬇️
superset/connectors/druid/models.py 82.99% <100.00%> (+0.03%) ⬆️
superset/connectors/sqla/models.py 89.46% <100.00%> (-0.23%) ⬇️
superset/utils/core.py 88.98% <100.00%> (+0.13%) ⬆️
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 89.95% <0.00%> (-0.42%) ⬇️
... and 2 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 4df3672...0aa628f. Read the comment docs.

@villebro villebro force-pushed the villebro/implied-metric-name branch from 8a1f609 to 0aa628f Compare August 11, 2021 13:02
Copy link
Member

@kgabryje kgabryje 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 the change! The code looks good, but it would be nice to get a 👍 from someone more experienced in python 🙂

:return: String representation of metric
:raises ValueError: if metric object is invalid
"""
if is_adhoc_metric(metric):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make is_adhoc_metric a type guard so that we don't need to use cast and # type: ignore so much? It's available in typing_extensions.

Copy link
Member Author

@villebro villebro Aug 12, 2021

Choose a reason for hiding this comment

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

Amazing, I didn't know these were forthcoming! 🚀 Super cool, I'll implement right away and try to stay on top of new PEPs. Btw, the functionality surrounding the Metric type is is pretty bad shape (e.g. QueryObject assumes the presence of a metric type consisting of a dict with only the property label that doesn't have a type definition, some geospatial viz plugins in viz.py apparently rely on get_metric_name to return None and int values in some cases), so I decided to break up the refactor into multiple smaller PRs to keep them manageable. So I will follow-up with some additional cleanup avoid this becoming XXXL.

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI adding support for type guards ended up being a deep rabbit hole involving upgrading mypy, needing to change pre-commit-hooks confs and a few monitors worth of new linting errors. I'll merge this now and follow up with a PR that bumps mypy and adds support for type guards.

@junlincc
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@junlincc Ephemeral environment spinning up at http://34.221.179.62:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@junlincc
Copy link
Member

tested locally, lgtm

@zhaoyongjie zhaoyongjie self-requested a review August 12, 2021 06:37
Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

LGTM

@villebro villebro merged commit b61c34f into apache:master Aug 12, 2021
@villebro villebro deleted the villebro/implied-metric-name branch August 12, 2021 08:16
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
* fix(viz): deduce metric name if empty

* fix unit test
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
* fix(viz): deduce metric name if empty

* fix unit test
@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 preset-io size/L 🚢 1.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants