-
Notifications
You must be signed in to change notification settings - Fork 14k
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: migrate charts on import #24703
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
tests/unit_tests/charts/commands/importers/v1/utils_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
# 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. | ||
|
||
import json | ||
|
||
from superset.charts.commands.importers.v1.utils import migrate_chart | ||
|
||
|
||
def test_migrate_chart_area() -> None: | ||
""" | ||
Test the ``migrate_chart`` command when importing an area chart. | ||
|
||
This is currently a no-op since the migration is not complete. | ||
""" | ||
chart_config = { | ||
"slice_name": "Birth names by state", | ||
"description": None, | ||
"certified_by": None, | ||
"certification_details": None, | ||
"viz_type": "area", | ||
"params": json.dumps( | ||
{ | ||
"adhoc_filters": [], | ||
"annotation_layers": [], | ||
"bottom_margin": "auto", | ||
"color_scheme": "supersetColors", | ||
"comparison_type": "values", | ||
"dashboards": [], | ||
"datasource": "21__table", | ||
"extra_form_data": {}, | ||
"granularity_sqla": "ds", | ||
"groupby": ["state"], | ||
"line_interpolation": "linear", | ||
"metrics": ["count"], | ||
"order_desc": True, | ||
"rich_tooltip": True, | ||
"rolling_type": "None", | ||
"row_limit": 10000, | ||
"show_brush": "auto", | ||
"show_legend": True, | ||
"stacked_style": "stack", | ||
"time_grain_sqla": "P1D", | ||
"time_range": "No filter", | ||
"viz_type": "area", | ||
"x_axis_format": "smart_date", | ||
"x_ticks_layout": "auto", | ||
"y_axis_bounds": [None, None], | ||
"y_axis_format": "SMART_NUMBER", | ||
} | ||
), | ||
"cache_timeout": None, | ||
"uuid": "ffd15af2-2188-425c-b6b4-df28aac45872", | ||
"version": "1.0.0", | ||
"dataset_uuid": "a18b9cb0-b8d3-42ed-bd33-0f0fadbf0f6d", | ||
} | ||
|
||
new_config = migrate_chart(chart_config) | ||
assert new_config == chart_config | ||
|
||
|
||
def test_migrate_pivot_table() -> None: | ||
""" | ||
Test the ``migrate_chart`` command when importing an old pivot table. | ||
""" | ||
chart_config = { | ||
"slice_name": "Pivot Table", | ||
"description": None, | ||
"certified_by": None, | ||
"certification_details": None, | ||
"viz_type": "pivot_table", | ||
"params": json.dumps( | ||
{ | ||
"columns": ["state"], | ||
"compare_lag": "10", | ||
"compare_suffix": "o10Y", | ||
"granularity_sqla": "ds", | ||
"groupby": ["name"], | ||
"limit": "25", | ||
"markup_type": "markdown", | ||
"metrics": [ | ||
{ | ||
"aggregate": "SUM", | ||
"column": { | ||
"column_name": "num", | ||
"type": "BIGINT", | ||
}, | ||
"expressionType": "SIMPLE", | ||
"label": "Births", | ||
"optionName": "metric_11", | ||
}, | ||
], | ||
"row_limit": 50000, | ||
"since": "100 years ago", | ||
"time_range": "No filter", | ||
"time_range_endpoints": ["inclusive", "exclusive"], | ||
"until": "now", | ||
"viz_type": "pivot_table", | ||
}, | ||
), | ||
"cache_timeout": None, | ||
"uuid": "ffd15af2-2188-425c-b6b4-df28aac45872", | ||
"version": "1.0.0", | ||
"dataset_uuid": "a18b9cb0-b8d3-42ed-bd33-0f0fadbf0f6d", | ||
} | ||
|
||
new_config = migrate_chart(chart_config) | ||
assert new_config == { | ||
"slice_name": "Pivot Table", | ||
"description": None, | ||
"certified_by": None, | ||
"certification_details": None, | ||
"viz_type": "pivot_table_v2", | ||
"params": json.dumps( | ||
{ | ||
"groupbyColumns": ["state"], | ||
"compare_lag": "10", | ||
"compare_suffix": "o10Y", | ||
"groupbyRows": ["name"], | ||
"limit": "25", | ||
"markup_type": "markdown", | ||
"metrics": [ | ||
{ | ||
"aggregate": "SUM", | ||
"column": {"column_name": "num", "type": "BIGINT"}, | ||
"expressionType": "SIMPLE", | ||
"label": "Births", | ||
"optionName": "metric_11", | ||
} | ||
], | ||
"series_limit": 50000, | ||
"since": "100 years ago", | ||
"time_range_endpoints": ["inclusive", "exclusive"], | ||
"until": "now", | ||
"viz_type": "pivot_table_v2", | ||
"rowOrder": "value_z_to_a", | ||
"adhoc_filters": [ | ||
{ | ||
"clause": "WHERE", | ||
"subject": "ds", | ||
"operator": "TEMPORAL_RANGE", | ||
"comparator": "No filter", | ||
"expressionType": "SIMPLE", | ||
} | ||
], | ||
} | ||
), | ||
"cache_timeout": None, | ||
"uuid": "ffd15af2-2188-425c-b6b4-df28aac45872", | ||
"version": "1.0.0", | ||
"dataset_uuid": "a18b9cb0-b8d3-42ed-bd33-0f0fadbf0f6d", | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only the Area migration that is incomplete. I don't think it's a good idea to create this enum because we don't want to allow incomplete or not implemented migrations. Can we assume that all new migrations should be complete and just skip area for now when importing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I just worried that in the future someone's going to fix the area migration but will not change the import logic. I'll leave a comment in the area migrator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@betodealmeida I'm already working on the Area migration in #23870. Adding a comment to the code sounds great!