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

refactor: get Axis from a helper function #21449

Merged
merged 3 commits into from
Sep 16, 2022

Conversation

zhaoyongjie
Copy link
Member

@zhaoyongjie zhaoyongjie commented Sep 13, 2022

SUMMARY

Currently, the new version of Charts especially Echart VIZs supported a Time or Categorical column as the X-Axis when the Feature Flag GENERIC_CHART_AXES was enabled. This feature would be disabled if FF was disabled, so the Pivot Index in some Post Processing operators would be set to __timestamp for backward compatibility.

This PR intends to move related codes into a helper function and removed unused property: is_timeseries in query_object. The is_timeseries only was used for the legacy Viz endpoint rather than the V1 Viz endpoint, so it's a safe refactor.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

  1. The AA should work as before.
  2. The CI should pass.

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 changed the title refactor: get Axis from an helper function refactor: get Axis from a helper function Sep 13, 2022
@pull-request-size pull-request-size bot added size/L and removed size/M labels Sep 13, 2022
@codecov
Copy link

codecov bot commented Sep 13, 2022

Codecov Report

Merging #21449 (89103bc) into master (6e8cad3) will decrease coverage by 0.05%.
The diff coverage is 90.90%.

❗ Current head 89103bc differs from pull request most recent head 6e8cc96. Consider uploading reports for the commit 6e8cc96 to get more accurate results

@@            Coverage Diff             @@
##           master   #21449      +/-   ##
==========================================
- Coverage   66.59%   66.53%   -0.06%     
==========================================
  Files        1791     1792       +1     
  Lines       68554    68602      +48     
  Branches     7319     7319              
==========================================
- Hits        45653    45647       -6     
- Misses      21008    21064      +56     
+ Partials     1893     1891       -2     
Flag Coverage Δ
javascript 52.75% <90.90%> (-0.02%) ⬇️
sqlite ?

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

Impacted Files Coverage Δ
.../superset-ui-core/src/query/normalizeTimeColumn.ts 100.00% <ø> (ø)
...gin-chart-echarts/src/Timeseries/transformProps.ts 52.38% <0.00%> (-1.20%) ⬇️
...t-ui-chart-controls/src/operators/pivotOperator.ts 100.00% <100.00%> (ø)
...ui-chart-controls/src/operators/prophetOperator.ts 100.00% <100.00%> (ø)
...controls/src/operators/timeComparePivotOperator.ts 100.00% <100.00%> (ø)
...t-ui-chart-controls/src/operators/utils/getAxis.ts 100.00% <100.00%> (ø)
...i-chart-controls/src/shared-controls/constants.tsx 18.75% <0.00%> (-14.59%) ⬇️
...d/src/views/CRUD/data/dataset/AddDataset/index.tsx 33.33% <0.00%> (-9.53%) ⬇️
superset/db_engine_specs/sqlite.py 91.89% <0.00%> (-4.54%) ⬇️
superset/utils/celery.py 86.20% <0.00%> (-3.45%) ⬇️
... and 33 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

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.

A few thoughts/questions, LMKWYT

Comment on lines +26 to +35
export const getAxis = (formData: QueryFormData): string | undefined => {
// The formData should be "raw form_data" -- the snake_case version of formData rather than camelCase.
if (!(formData.granularity_sqla || formData.x_axis)) {
return undefined;
}

return isDefined(formData.x_axis)
? getColumnLabel(formData.x_axis)
: DTTM_ALIAS;
};
Copy link
Member

Choose a reason for hiding this comment

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

To future proof this to n dimensions, I think it might make sense to call this helper getBaseAxes that returns an array (that way we also wouldn't need to wrap the return value in an array when passing it to the index prop). Also, I believe the return type should be based on QueryFormColumn, as it may also be an AdhocColumn. So maybe the sig should be

export const getBaseAxes = (formData: QueryFormData): QueryFormColumn[] | undefined => {...}

Also, shouldn't we assume that the return value should always be defined, i.e. we always fall back to DTTM_ALIAS (at least for now) unless formData.x_axis is defined?

Copy link
Member Author

Choose a reason for hiding this comment

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

This function returns a label of a column(the label of the columns, or alias clause for the SQL), so the return value might be a string rather than a structure data(QueryFormColumn).

another issue is that whether the return value is a string or a string array. both work for me, but the string array return value might not directly apply to the post processing function. I promise that if we will support the multiple axes, I am going to refactor this.

The undefined value represents a form_data that cannot apply a query with an axis. For example, if a form_data had granularity_sqla neither nor axis, this function would return an undefined value, then the caller should easily skip some logic.

const xAxisCol =
verboseMap[xAxisOrig] || getColumnLabel(xAxisOrig || DTTM_ALIAS);
verboseMap[xAxisOrig] || getAxis(chartProps.rawFormData) || DTTM_ALIAS;
Copy link
Member

Choose a reason for hiding this comment

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

If we make getAxis always return a non-undefined value, then we won't need to have the || DTTM_ALIAS here, right? It feels slightly redundant, as it feels like the getAxis helper should always return a value (or raise if it can't).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the DTTM_ALIAS is a redundant case. I consider that if a chart can't have an axis here, the chart should throw an error, but there wasn't an appropriate approach to throw an error in the Chart and TS throw a type error, so I added a redundant condition here. I think we need to catch this error in the separated PR.

Copy link
Member

@stephenLYZ stephenLYZ left a comment

Choose a reason for hiding this comment

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

Awesome work!

@zhaoyongjie zhaoyongjie merged commit 2d16100 into apache:master Sep 16, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 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 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants