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(explore): default aggregate for string/numeric columns when creating metric #15798

Merged
merged 4 commits into from
Jul 22, 2021

Conversation

kgabryje
Copy link
Member

@kgabryje kgabryje commented Jul 20, 2021

SUMMARY

When user creates a new adhoc metric with drag and dropping a column into metrics control, auto fill default aggregate in metric popover.
If column's generic type is numeric, set SUM aggregate as default.
if column's generic type is string or boolean, set COUNT_DISTINCT aggregate as default.
Otherwise, don't set a default aggregate.

Also, this PR fixes a bug metrics popover - when user created a metric with a custom label and then tried to create next metric, previous label was set instead of a default label. Now it should work as expected.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screen.Recording.2021-07-20.at.14.06.18.mov

TESTING INSTRUCTIONS

  1. Set ENABLE_EXPLORE_DRAG_AND_DROP and UX_BETA feature flags to True
  2. Drag numeric column to metrics control. The default aggregate should be SUM
  3. Drag string or boolean column to metrics control. The default aggregate should be COUNT_DISTINCT
  4. Drag other type of column to metrics control. Aggregate should be unset.
  5. Click Run and make sure the metrics work properly
  6. Edit the default label of some metric and then try to add a new one. A default label in the new metric popover should match column's name and selected aggregate. Previously set label shouldn't be shown here

ADDITIONAL INFORMATION

CC @junlincc

@codecov
Copy link

codecov bot commented Jul 20, 2021

Codecov Report

Merging #15798 (6179aed) into master (040b941) will decrease coverage by 0.01%.
The diff coverage is 37.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15798      +/-   ##
==========================================
- Coverage   76.91%   76.90%   -0.02%     
==========================================
  Files         984      984              
  Lines       51705    51718      +13     
  Branches     6994     7000       +6     
==========================================
+ Hits        39770    39774       +4     
- Misses      11711    11720       +9     
  Partials      224      224              
Flag Coverage Δ
javascript 71.82% <37.50%> (-0.03%) ⬇️
mysql 81.53% <ø> (ø)
postgres 81.55% <ø> (ø)
python 81.64% <ø> (ø)
sqlite 81.19% <ø> (ø)

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

Impacted Files Coverage Δ
superset/config.py 91.24% <ø> (ø)
...ontrols/DndColumnSelectControl/DndMetricSelect.tsx 41.48% <16.66%> (-2.97%) ⬇️
...ntrols/MetricControl/AdhocMetricPopoverTrigger.tsx 72.30% <100.00%> (+1.81%) ⬆️

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 040b941...6179aed. Read the comment docs.

@zhaoyongjie
Copy link
Member

To fill up pre-aggregate function code look good to me.

the bug fix we should take more effect. When two metrics have the same name, I can't change one of the name.

duplicate.metric.mp4

@kgabryje
Copy link
Member Author

the bug fix we should take more effect. When two metrics have the same name, I can't change one of the name.

duplicate.metric.mp4

Fixed, thanks for reporting! Can you take another look and verify?

Comment on lines 79 to 84
componentDidUpdate(
prevProps: Readonly<AdhocMetricPopoverTriggerProps>,
prevState: Readonly<AdhocMetricPopoverTriggerState>,
snapshot?: any,
) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
componentDidUpdate(
prevProps: Readonly<AdhocMetricPopoverTriggerProps>,
prevState: Readonly<AdhocMetricPopoverTriggerState>,
snapshot?: any,
) {
componentDidUpdate(prevProps: Readonly<AdhocMetricPopoverTriggerProps>) {

Is not the case for getDerivedStateFromProps?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I changed that. That required saving adhocMetric in state though, so that I could compare previous and next in getDerviedStateFromProps. Can you take another look?

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.

The code looks great to me.

@kgabryje
Copy link
Member Author

I'll merge once @junlincc gives a green light - we need to decide if we need a feature flag and if we should replace COUNT_DISTINCT with COUNT.

@junlincc
Copy link
Member

LGTM. let's put the change behind an umbrella feature flag, e.g. UX_beta and set it to false by default.

@kgabryje
Copy link
Member Author

/testenv up FEATURE_ENABLE_EXPLORE_DRAG_AND_DROP=true

@github-actions
Copy link
Contributor

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

@junlincc
Copy link
Member

"I don’t recommend doing count_distinct for string column. This is a precise deduplication operation. It is very resource intensive for the database. imagine, if this column has many values(high cardinality), this query can easily crash the database. some databases have special functions to do this calculation." @zhaoyongjie

I dont think this should be a concern. Even there's a preselected aggregate, users still need to click SAVE and RUN to run query that potentially crush anything. From UX standpoint, having a preselected aggregate has the equal amount of clicks to no preselected if users need to choose COUNT instead. and for most cases, count_distinct is indeed what users choose for STRING columns. I don't see any reasons why we should use COUNT as preselected.

@kgabryje
Copy link
Member Author

kgabryje commented Jul 22, 2021

@junlincc I added a UX_BETA feature flag, which is set to False by default - the auto filling of aggregates will work when that flag is set to True

@kgabryje kgabryje merged commit 5e1c469 into apache:master Jul 22, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
…ting metric (apache#15798)

* feat(explore): default aggregate for string/numeric columns when creating metric

* Fix for editing items with the same label

* Replace componentDidUpdate with getDerivedStateFromProps

* Wrap changes in feature flag
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
…ting metric (apache#15798)

* feat(explore): default aggregate for string/numeric columns when creating metric

* Fix for editing items with the same label

* Replace componentDidUpdate with getDerivedStateFromProps

* Wrap changes in feature flag
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
…ting metric (apache#15798)

* feat(explore): default aggregate for string/numeric columns when creating metric

* Fix for editing items with the same label

* Replace componentDidUpdate with getDerivedStateFromProps

* Wrap changes in feature flag
@mistercrunch mistercrunch added the 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels label 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 test:case 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Explore] Metric/Filter Popover should always corresponds to the actual metric/filter item
5 participants