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 renameOperator #19776

Merged
merged 8 commits into from
Apr 20, 2022
Merged

Conversation

zhaoyongjie
Copy link
Member

@zhaoyongjie zhaoyongjie commented Apr 19, 2022

SUMMARY

Before Dataframe

Before PR, in the timeseries charts, the result column names follow the simple rules that combine all the levels into a single string. For example, in the birth_name dataset, select 1) ds as x-axis, 2) sum_num as metrics 3) gender as dimensions 4) 1990 : 2000 as time range 5) 1 year ago and actual values in time comparison. The intermediate MulitiIndex dataframe is:

             sum__num           sum__num__1 year ago          
gender            boy      girl                  boy      girl
ds                                                            
1990-01-01  1294971.0  899028.0            1281700.0  893001.0
1991-01-01  1248012.0  856255.0            1294971.0  899028.0
1992-01-01  1201680.0  820265.0            1248012.0  856255.0
1993-01-01  1154257.0  791723.0            1201680.0  820265.0
1994-01-01  1110122.0  760527.0            1154257.0  791723.0
1995-01-01  1072579.0  726740.0            1110122.0  760527.0
1996-01-01  1045266.0  702602.0            1072579.0  726740.0
1997-01-01  1021626.0  673936.0            1045266.0  702602.0
1998-01-01  1013188.0  657586.0            1021626.0  673936.0
1999-01-01   994617.0  636541.0            1013188.0  657586.0

then, the MultiIndex dataframe is changed plain dataframe by the flatten operator.

          ds  sum__num, boy  sum__num, girl  sum__num__1 year ago, boy  sum__num__1 year ago, girl
0 1990-01-01      1294971.0        899028.0                  1281700.0                    893001.0
1 1991-01-01      1248012.0        856255.0                  1294971.0                    899028.0
2 1992-01-01      1201680.0        820265.0                  1248012.0                    856255.0
3 1993-01-01      1154257.0        791723.0                  1201680.0                    820265.0
4 1994-01-01      1110122.0        760527.0                  1154257.0                    791723.0
5 1995-01-01      1072579.0        726740.0                  1110122.0                    760527.0
6 1996-01-01      1045266.0        702602.0                  1072579.0                    726740.0
7 1997-01-01      1021626.0        673936.0                  1045266.0                    702602.0
8 1998-01-01      1013188.0        657586.0                  1021626.0                    673936.0
9 1999-01-01       994617.0        636541.0                  1013188.0                    657586.0

The legacy NVD3 chart has a special rule that removes or renames columns. The rule will apply to columns if the chart has:

  1. only has 1 metric
  2. exists more than 1 series(breakdown in the line chart)
  3. exists xAxis or TimeIndex
  4. exists time comparison, and the comparison type is "actual values"

After the PR

So the PR introduces rename operator for this case

          ds        boy      girl  1 year ago, boy  1 year ago, girl
0 1990-01-01  1294971.0  899028.0        1281700.0          893001.0
1 1991-01-01  1248012.0  856255.0        1294971.0          899028.0
2 1992-01-01  1201680.0  820265.0        1248012.0          856255.0
3 1993-01-01  1154257.0  791723.0        1201680.0          820265.0
4 1994-01-01  1110122.0  760527.0        1154257.0          791723.0
5 1995-01-01  1072579.0  726740.0        1110122.0          760527.0
6 1996-01-01  1045266.0  702602.0        1072579.0          726740.0
7 1997-01-01  1021626.0  673936.0        1045266.0          702602.0
8 1998-01-01  1013188.0  657586.0        1021626.0          673936.0
9 1999-01-01   994617.0  636541.0        1013188.0          657586.0

Known limitations

  1. Some derived metrics in time comparison are not addressed. the derived metrics refer to difference, percentage change, and radio in the time comparison.
  2. There is no way customized column names after post processing.

I will handle these cases in the future and provide customized rename on the UI.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

After

image

TESTING INSTRUCTIONS

CI and before SUMMARY paragraph

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

@zhaoyongjie zhaoyongjie marked this pull request as draft April 19, 2022 13:15
@codecov
Copy link

codecov bot commented Apr 19, 2022

Codecov Report

Merging #19776 (b14cef1) into master (231716c) will decrease coverage by 0.09%.
The diff coverage is 100.00%.

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

@@            Coverage Diff             @@
##           master   #19776      +/-   ##
==========================================
- Coverage   66.51%   66.41%   -0.10%     
==========================================
  Files        1690     1691       +1     
  Lines       64730    64748      +18     
  Branches     6656     6660       +4     
==========================================
- Hits        43054    43003      -51     
- Misses      19977    20046      +69     
  Partials     1699     1699              
Flag Coverage Δ
hive ?
javascript 51.23% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
...superset-ui-core/src/query/types/PostProcessing.ts 100.00% <ø> (ø)
.../plugin-chart-echarts/src/Timeseries/buildQuery.ts 66.66% <ø> (ø)
...ui-chart-controls/src/operators/flattenOperator.ts 100.00% <100.00%> (ø)
...-ui-chart-controls/src/operators/renameOperator.ts 100.00% <100.00%> (ø)
...rontend/src/SqlLab/components/QueryTable/index.tsx 70.17% <100.00%> (+0.53%) ⬆️
superset/charts/schemas.py 99.35% <100.00%> (ø)
superset/utils/pandas_postprocessing/__init__.py 100.00% <100.00%> (ø)
superset/utils/pandas_postprocessing/flatten.py 100.00% <100.00%> (ø)
superset/views/core.py 77.02% <100.00%> (+0.01%) ⬆️
superset/db_engines/hive.py 0.00% <0.00%> (-85.19%) ⬇️
... and 7 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 231716c...2e4753e. Read the comment docs.

@zhaoyongjie zhaoyongjie marked this pull request as ready for review April 20, 2022 07:49
for series in df.columns.to_flat_index():
_cells = []
for cell in series if is_sequence(series) else [series]:
if pd.notnull(cell):
Copy link
Member Author

Choose a reason for hiding this comment

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

The top-level columns are might set to None in the rename operator. Flatten skip the None level.

@zhaoyongjie zhaoyongjie requested a review from a team April 20, 2022 09:18
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 and tested to work well. Thanks so much for working on this! I think we're starting to approach the limits of what we can do with the current post processing functionality. To be able to move some of this functionality into the column/metric controls we will probably have to design a new API for these operations to make sure we're future proofed for any future use cases.

@mistercrunch mistercrunch added 🍒 1.5.3 🏷️ 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 lts-v1 size/XL 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants