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 Area chart migration and tweaks the Timeseries chart migration #25952

Merged
merged 6 commits into from
Nov 16, 2023

Conversation

michael-s-molina
Copy link
Member

@michael-s-molina michael-s-molina commented Nov 10, 2023

SUMMARY

This PR adds the Area chart migration logic (NVD3 ➡️ ECharts) and tweaks the base class used by timeseries migrations. Users can execute this migration using the #25304 CLI command and disable the legacy version with the VIZ_TYPE_DENYLIST configuration.

@sadpandajoe @jinghua-qa

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screenshot 2023-11-10 at 14 28 21 Screenshot 2023-11-10 at 14 28 46

TESTING INSTRUCTIONS

1 - Upgrade a Area chart using the CLI command
2 - Check the new chart
3 - Downgrade a Area chart using the CLI command
4 - Check the legacy chart

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

@michael-s-molina michael-s-molina mentioned this pull request Nov 10, 2023
9 tasks
@john-bodley john-bodley added the review:checkpoint Last PR reviewed during the daily review standup label Nov 10, 2023
@@ -17,4 +17,4 @@
[pytest]
testpaths =
tests
python_files = *_test.py test_*.py *_tests.py
python_files = *_test.py test_*.py *_tests.py *viz/utils.py
Copy link
Member Author

Choose a reason for hiding this comment

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

Makes pytest display full assertion errors defined in that file.

@john-bodley john-bodley removed the review:checkpoint Last PR reviewed during the daily review standup label Nov 13, 2023
@michael-s-molina michael-s-molina marked this pull request as ready for review November 15, 2023 13:22
@michael-s-molina michael-s-molina requested a review from a team as a code owner November 15, 2023 13:22
Copy link
Member

@john-bodley john-bodley left a comment

Choose a reason for hiding this comment

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

Given there's also a refactor in combination with the are chart migration it might be helpful to annotate (via comments) which parts represent new logic.

I'm a tad complexed, given that the PR title states we're adding an area chart migration yet there was an existing "MigrateAreaChart" class.

@@ -68,30 +69,4 @@ def test_migration() -> None:


def upgrade_downgrade(source, target) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

This is legacy, but this method name is somewhat confusing, i.e., I'm not entirely sure what it does.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed 👍🏼

slc = MigrateDualLine.downgrade_slice(slc)
assert slc.viz_type == MigrateDualLine.source_viz_type
assert json.loads(slc.params) == source
migrate_and_assert(MigrateDualLine, source, target)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the refactor.

lambda current, total: print(
f" Updating {current}/{total} charts", end="\r"
),
lambda current, total: print(f"Upgraded {current}/{total} charts"),
Copy link
Member Author

Choose a reason for hiding this comment

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

Display a log entry for each block creating a log history.

@michael-s-molina
Copy link
Member Author

I'm a tad complexed, given that the PR title states we're adding an area chart migration yet there was an existing "MigrateAreaChart" class.

Even though we had a previous migration, it was incomplete and wasn't being used.

@@ -36,40 +36,6 @@ def _pre_action(self) -> None:
self.data["metric"] = self.data["metrics"][0]


class MigrateAreaChart(MigrateViz):
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the incomplete and unused migration.

@@ -137,10 +103,22 @@ class MigrateSunburst(MigrateViz):

class TimeseriesChart(MigrateViz):
has_x_axis_control = True
rename_keys = {
Copy link
Member Author

@michael-s-molina michael-s-molina Nov 16, 2023

Choose a reason for hiding this comment

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

This is not new. Just moved from MigrateLineChart.


class MigrateLineChart(TimeseriesChart):
source_viz_type = "line"
target_viz_type = "echarts_timeseries_line"
rename_keys = {
Copy link
Member Author

@michael-s-molina michael-s-molina Nov 16, 2023

Choose a reason for hiding this comment

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

Moved to TimeseriesChart.

"any_other_key": "untouched",
"columns": ["state"],
"combine_metric": True,
"granularity_sqla": "ds",
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved the time parts to a separate test file called time_related_fields_test.py



@with_feature_flags(GENERIC_CHART_AXES=False)
def test_migration_without_generic_chart_axes() -> None:
Copy link
Member Author

Choose a reason for hiding this comment

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

All this came from the pivot_table_v1_v2_test.py

@michael-s-molina
Copy link
Member Author

michael-s-molina commented Nov 16, 2023

Given there's also a refactor in combination with the are chart migration it might be helpful to annotate (via comments) which parts represent new logic.

@john-bodley Added comments

@@ -75,7 +75,6 @@ def migrate_chart(config: dict[str, Any]) -> dict[str, Any]:
if isclass(class_)
and issubclass(class_, MigrateViz)
and hasattr(class_, "source_viz_type")
and class_ != processors.MigrateAreaChart # incomplete
Copy link
Member Author

Choose a reason for hiding this comment

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

Added the migration back to import function now that it's complete.


def _pre_action(self) -> None:
self.data["contributionMode"] = "row" if self.data.get("contribution") else None
self.data["zoomable"] = self.data.get("show_brush") != "no"
self.data["zoomable"] = self.data.get("show_brush") == "yes"
Copy link
Member

Choose a reason for hiding this comment

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

@michael-s-molina I see this is an update to the existing TimeseriesChart migration where the zoomable used to be True if show_brush was None whereas now it's False.

I'm not privy to knowing whether this logic (and that on lines 144–146) is correct, but maybe it make more sense to have said logic in a separate PR. Additionally is there anyway to proactively fix previously migrated charts which were wrong? I gather the x_ticks_layout field could be remedied (as it's persisted), but the show_brush was removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

@john-bodley These PRs only add the migration logic but there's no migration invoking them directly. We'll have that in 4.0 when we forcefully remove the legacy versions. Right now, these migrations can only be invoked by the viz_migrations command which was not released yet. The command will be available in 3.1.

Copy link
Member

@john-bodley john-bodley Nov 16, 2023

Choose a reason for hiding this comment

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

@michael-s-molina could we change to PR description to be something of the form,

Add Area chart migration and tweaks the Timeseries chart migration

which will aid developers if they're trying to bisect when/where a possible change occurred.


self.remove_keys.add("stacked_style")

self.data["stack"] = self.stacked_map.get(
Copy link
Member

Choose a reason for hiding this comment

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

Should the stack key be None or undefined if the resulting key isn't in self.stacked_map?

Copy link
Member Author

@michael-s-molina michael-s-molina Nov 16, 2023

Choose a reason for hiding this comment

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

Yes. It can be None or undefined as it's optional.

Copy link
Member

Choose a reason for hiding this comment

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

Do we have a preference or whether we explicitly define None? I guess there's likely so many inconsistencies on both the front- and back-end with regards to when/where to persist values that even if we make it undefined (and thus minimizing the payload) there's no guarantee that the field wont materialize with a value of None on save.

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly 😆

@michael-s-molina michael-s-molina merged commit 97d89d7 into apache:master Nov 16, 2023
31 checks passed
@john-bodley john-bodley changed the title feat: Adds Area chart migration logic feat: Add Area chart migration and tweaks the Timeseries chart migration Nov 16, 2023
josedev-union pushed a commit to Ortege-xyz/studio that referenced this pull request Jan 22, 2024
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 2024
sfirke pushed a commit to sfirke/superset that referenced this pull request Mar 22, 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/XL 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants