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 2021/02/14 10:15:26 UTC

[GitHub] [superset] ktmud commented on a change in pull request #13111: feat: add Echarts Graph chart

ktmud commented on a change in pull request #13111:
URL: https://github.com/apache/superset/pull/13111#discussion_r575785076



##########
File path: superset/migrations/versions/1412ec1e5a7b_legacy_force_directed_to_echart.py
##########
@@ -0,0 +1,97 @@
+# 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.
+"""legacy force directed to echart
+
+Revision ID: 1412ec1e5a7b
+Revises: 070c043f2fdb
+Create Date: 2021-02-14 11:46:02.379832
+
+"""
+import json
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy import Column, Integer, or_, String, Text
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+# revision identifiers, used by Alembic.
+revision = "1412ec1e5a7b"
+down_revision = "070c043f2fdb"
+
+
+Base = declarative_base()
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+    id = Column(Integer, primary_key=True)
+    viz_type = Column(String(250))
+    params = Column(Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    for slc in session.query(Slice).filter(Slice.viz_type.like("directed_force")):
+        params = json.loads(slc.params)
+
+        groupby = params.get("groupby", [])
+        if groupby:
+            params["source"] = groupby[0]
+            params["target"] = groupby[1]

Review comment:
       `groupby` doesn't necessary always have two items. Maybe add a safe guard here:
   
   ```suggestion
               params["target"] = groupby[1] if len(groupby) > 1 else None
   ```




----------------------------------------------------------------
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.

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