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: Adds Heatmap chart migration logic #27771

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions requirements/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# via
# -r requirements/base.in
# -r requirements/development.in
appnope==0.1.4
# via ipython
astroid==2.15.8
# via pylint
asttokens==2.2.1
Expand Down Expand Up @@ -193,6 +195,10 @@ ptyprocess==0.7.0
# via pexpect
pure-eval==0.2.2
# via stack-data
pure-sasl==0.6.2
# via
# pyhive
# thrift-sasl
pydata-google-auth==1.7.0
# via pandas-gbq
pydruid==0.6.6
Expand All @@ -201,7 +207,7 @@ pyee==11.0.1
# via playwright
pyfakefs==5.2.2
# via -r requirements/development.in
pyhive[presto]==0.7.0
pyhive[hive_pure_sasl]==0.7.0
# via apache-superset
pyinstrument==4.4.0
# via -r requirements/development.in
Expand Down Expand Up @@ -243,7 +249,12 @@ statsd==4.0.1
tableschema==1.20.10
# via apache-superset
thrift==0.20.0
# via apache-superset
# via
# apache-superset
# pyhive
# thrift-sasl
thrift-sasl==0.4.3
# via pyhive
tomli==2.0.1
# via
# build
Expand Down
3 changes: 3 additions & 0 deletions superset/cli/viz_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
AREA = "area"
BUBBLE = "bubble"
DUAL_LINE = "dual_line"
HEATMAP = "heatmap"

Check warning on line 30 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L30

Added line #L30 was not covered by tests
LINE = "line"
PIVOT_TABLE = "pivot_table"
SUNBURST = "sunburst"
Expand Down Expand Up @@ -79,6 +80,7 @@
MigrateAreaChart,
MigrateBubbleChart,
MigrateDualLine,
MigrateHeatmapChart,
MigrateLineChart,
MigratePivotTable,
MigrateSunburst,
Expand All @@ -89,6 +91,7 @@
VizType.AREA: MigrateAreaChart,
VizType.BUBBLE: MigrateBubbleChart,
VizType.DUAL_LINE: MigrateDualLine,
VizType.HEATMAP: MigrateHeatmapChart,
VizType.LINE: MigrateLineChart,
VizType.PIVOT_TABLE: MigratePivotTable,
VizType.SUNBURST: MigrateSunburst,
Expand Down
15 changes: 15 additions & 0 deletions superset/migrations/shared/migrate_viz/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,18 @@ def _pre_action(self) -> None:

# Truncate y-axis by default to preserve layout
self.data["y_axis_showminmax"] = True


class MigrateHeatmapChart(MigrateViz):
source_viz_type = "heatmap"
target_viz_type = "heatmap_v2"
rename_keys = {
"all_columns_x": "x_axis",
"all_columns_y": "groupby",
"y_axis_bounds": "value_bounds",
"show_perc": "show_percentage",
}
remove_keys = {"sort_by_metric", "canvas_image_rendering"}

def _pre_action(self) -> None:
self.data["legend_type"] = "continuous"
78 changes: 78 additions & 0 deletions tests/unit_tests/migrations/viz/heatmap_v1_v2_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Any

from superset.migrations.shared.migrate_viz import MigrateHeatmapChart
from tests.unit_tests.migrations.viz.utils import migrate_and_assert

SOURCE_FORM_DATA: dict[str, Any] = {
"any_other_key": "untouched",
"all_columns_x": ["category"],
"all_columns_y": ["product"],
"metric": ["sales"],
"adhoc_filters": [],
"row_limit": 100,
"sort_by_metric": True,
"linear_color_scheme": "blue",
"xscale_interval": 2,
"yscale_interval": 2,
"canvas_image_rendering": "auto",
"normalize_across": "x",
"left_margin": 50,
"bottom_margin": 50,
"y_axis_bounds": [0, 100],
"y_axis_format": "SMART_NUMBER",
"currency_format": "USD",
"sort_x_axis": "alpha_asc",
"sort_y_axis": "alpha_asc",
"show_legend": True,
"show_perc": True,
"show_values": True,
"normalized": True,
"viz_type": "heatmap",
}

TARGET_FORM_DATA: dict[str, Any] = {
"any_other_key": "untouched",
"x_axis": ["category"],
"groupby": ["product"],
"metric": ["sales"],
"adhoc_filters": [],
"row_limit": 100,
"legend_type": "continuous",
"linear_color_scheme": "blue",
"xscale_interval": 2,
"yscale_interval": 2,
"normalize_across": "x",
"left_margin": 50,
"bottom_margin": 50,
"value_bounds": [0, 100],
"y_axis_format": "SMART_NUMBER",
"currency_format": "USD",
"sort_x_axis": "alpha_asc",
"sort_y_axis": "alpha_asc",
"show_legend": True,
"show_percentage": True,
"show_values": True,
"normalized": True,
"viz_type": "heatmap_v2",
"form_data_bak": SOURCE_FORM_DATA,
}


def test_migration() -> None:
migrate_and_assert(MigrateHeatmapChart, SOURCE_FORM_DATA, TARGET_FORM_DATA)
Loading