You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/07/07 17:32:32 UTC

[GitHub] [superset] michael-s-molina commented on a diff in pull request #20359: feat: Area viz migration

michael-s-molina commented on code in PR #20359:
URL: https://github.com/apache/superset/pull/20359#discussion_r916093567


##########
superset/utils/migrate_viz.py:
##########
@@ -117,6 +111,38 @@ def _pre_action(self) -> None:
             self.data["metric"] = self.data["metrics"][0]
 
 
+class MigrateArea(MigrateViz):
+    source_viz_type = "area"
+    target_viz_type = "echarts_area"
+    remove_keys = {"contribution", "stacked_style", "x_axis_label"}
+
+    def _pre_action(self) -> None:
+        if self.data.get("contribution"):
+            self.data["contributionMode"] = "row"
+
+        stacked = self.data.get("stacked_style")
+        stacked_map = {
+            "expand": "Expand",
+            "stack": "Stack",
+        }
+        if stacked:
+            self.data["show_extra_controls"] = True
+            self.data["stack"] = stacked_map.get(stacked)

Review Comment:
   ```suggestion
           if stacked:
               stacked_map = {
                   "expand": "Expand",
                   "stack": "Stack",
               }
               self.data["show_extra_controls"] = True
               self.data["stack"] = stacked_map.get(stacked)
   ```



##########
superset/migrations/versions/2022-07-07_14-00_06e1e70058c7_migrating_legacy_area.py:
##########
@@ -0,0 +1,101 @@
+# 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.
+"""Migrating legacy Area
+
+Revision ID: 06e1e70058c7
+Revises: c747c78868b6
+Create Date: 2022-06-13 14:17:51.872706
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "06e1e70058c7"
+down_revision = "c747c78868b6"
+
+from alembic import op
+from sqlalchemy import and_, Column, Integer, String, Text
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+from superset.utils.migrate_viz import get_migrate_class, MigrateVizEnum
+
+area_processor = get_migrate_class[MigrateVizEnum.area]
+
+Base = declarative_base()
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    slice_name = Column(String(250))
+    viz_type = Column(String(250))
+    params = Column(Text)
+    query_context = Column(Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    slices = session.query(Slice).filter(
+        Slice.viz_type == area_processor.source_viz_type
+    )
+    total = slices.count()
+    idx = 0
+    for slc in slices.yield_per(1000):
+        try:
+            idx += 1
+            print(f"Upgrading ({idx}/{total}): {slc.slice_name}#{slc.id}")
+            new_viz = area_processor.upgrade(slc)
+            session.merge(new_viz)
+        except Exception as exc:
+            print(
+                "Error while processing migration: '{}'\nError: {}\n".format(
+                    slc.slice_name, str(exc)
+                )
+            )
+    session.commit()

Review Comment:
   Wouldn't this commit only after all the values have been merged as opposed to committing every thousand values? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org