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 2020/04/29 18:03:15 UTC

[GitHub] [incubator-superset] etr2460 opened a new pull request #9684: fix: migrate all slices off the old time grain format

etr2460 opened a new pull request #9684:
URL: https://github.com/apache/incubator-superset/pull/9684


   ### CATEGORY
   
   Choose one
   
   - [x] Bug Fix
   - [ ] Enhancement (new features, refinement)
   - [ ] Refactor
   - [ ] Add tests
   - [ ] Build / Development Environment
   - [ ] Documentation
   
   ### SUMMARY
   At Airbnb, we see a decent number of errors like `No grain spec for day for database presto`. It appears that this is because we never merged a migration to move slices from the old type to the new one (see https://github.com/apache/incubator-superset/pull/4755#issuecomment-401981272).
   
   I've replicated/updated @jeffreythewang's work (thanks Jeffrey!) from https://github.com/apache/incubator-superset/pull/5485 in this PR to migrate slices to the proper time grain format
   
   ### TEST PLAN
   set `time_grain_sqla` for a chart to "day", run the migration and see it converted to "P1D"
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Changes UI
   - [x] Requires DB Migration.
   - [x] Confirm DB Migration upgrade and downgrade tested.
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   ### REVIEWERS
   to: @john-bodley @villebro @mistercrunch @jeffreythewang 


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


[GitHub] [incubator-superset] john-bodley commented on a change in pull request #9684: fix: migrate all slices off the old time grain format

Posted by GitBox <gi...@apache.org>.
john-bodley commented on a change in pull request #9684:
URL: https://github.com/apache/incubator-superset/pull/9684#discussion_r417545746



##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):
+    return {grain.name: grain.duration for grain in time_grains}
+
+
+@utils.memoized
+def duration_to_name(time_grains):
+    return {grain.duration: grain.name for grain in time_grains}
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    query = (
+        session.query(Slice, Database)
+        .filter(Slice.datasource_type == "table")
+        .filter(Slice.datasource_id == Table.id)
+        .filter(Table.database_id == Database.id)
+        .all()
+    )
+
+    for slc, database in query:
+        try:
+            params = json.loads(slc.params)
+            duration_dict = name_to_duration(database.grains())
+            granularity = params.get("time_grain_sqla")
+            if granularity in duration_dict:
+                params["time_grain_sqla"] = duration_dict.get(granularity)

Review comment:
       Nit. No need to use `get()` since you checked for the presence of the key on line #101.

##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):
+    return {grain.name: grain.duration for grain in time_grains}
+
+
+@utils.memoized
+def duration_to_name(time_grains):
+    return {grain.duration: grain.name for grain in time_grains}
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    query = (
+        session.query(Slice, Database)
+        .filter(Slice.datasource_type == "table")
+        .filter(Slice.datasource_id == Table.id)
+        .filter(Table.database_id == Database.id)
+        .all()
+    )
+
+    for slc, database in query:
+        try:
+            params = json.loads(slc.params)
+            duration_dict = name_to_duration(database.grains())
+            granularity = params.get("time_grain_sqla")
+            if granularity in duration_dict:
+                params["time_grain_sqla"] = duration_dict.get(granularity)
+                slc.params = json.dumps(params, sort_keys=True, indent=4)

Review comment:
       Let's nix the `indent` as it unnecessarily bloats the database. 

##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):

Review comment:
       I don't think you want to memoize this signature as different databases may have different mappings for the same `time_grains`. It seems: 
   
   ```
   @utils.memoized
   def name_to_duration(database):
       time_grains = database.grains()
       ...
   ```
   
   seems safer.

##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):

Review comment:
       Nit could we call this `duration_by_name` for consistency when naming dictionary mappings.

##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):
+    return {grain.name: grain.duration for grain in time_grains}
+
+
+@utils.memoized
+def duration_to_name(time_grains):

Review comment:
       This is unused.




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


[GitHub] [incubator-superset] codecov-io commented on pull request #9684: fix: migrate all slices off the old time grain format

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #9684:
URL: https://github.com/apache/incubator-superset/pull/9684#issuecomment-621457401


   # [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=h1) Report
   > Merging [#9684](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=desc) into [master](https://codecov.io/gh/apache/incubator-superset/commit/f13ba2561cd325c4bd4dc3c4700b618f195b89ed&el=desc) will **decrease** coverage by `6.97%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-superset/pull/9684/graphs/tree.svg?width=650&height=150&src=pr&token=KsB0fHcx6l)](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #9684      +/-   ##
   ==========================================
   - Coverage   65.75%   58.77%   -6.98%     
   ==========================================
     Files         581      399     -182     
     Lines       30319    12508   -17811     
     Branches     3096     3095       -1     
   ==========================================
   - Hits        19937     7352   -12585     
   + Misses      10201     4975    -5226     
     Partials      181      181              
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | #javascript | `58.77% <ø> (-0.02%)` | :arrow_down: |
   | #python | `?` | |
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [...explore/components/controls/AdhocFilterControl.jsx](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2V4cGxvcmUvY29tcG9uZW50cy9jb250cm9scy9BZGhvY0ZpbHRlckNvbnRyb2wuanN4) | `59.22% <0.00%> (-1.57%)` | :arrow_down: |
   | [superset/utils/import\_datasource.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdXRpbHMvaW1wb3J0X2RhdGFzb3VyY2UucHk=) | | |
   | [superset/db\_engine\_specs/kylin.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2t5bGluLnB5) | | |
   | [superset/views/filters.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvZmlsdGVycy5weQ==) | | |
   | [superset/dashboards/filters.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGFzaGJvYXJkcy9maWx0ZXJzLnB5) | | |
   | [superset/models/slice.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvbW9kZWxzL3NsaWNlLnB5) | | |
   | [superset/models/datasource\_access\_request.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvbW9kZWxzL2RhdGFzb3VyY2VfYWNjZXNzX3JlcXVlc3QucHk=) | | |
   | [superset/views/database/filters.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvZGF0YWJhc2UvZmlsdGVycy5weQ==) | | |
   | [superset/charts/commands/bulk\_delete.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvY2hhcnRzL2NvbW1hbmRzL2J1bGtfZGVsZXRlLnB5) | | |
   | [superset/utils/pandas\_postprocessing.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdXRpbHMvcGFuZGFzX3Bvc3Rwcm9jZXNzaW5nLnB5) | | |
   | ... and [173 more](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=footer). Last update [f13ba25...120fc86](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


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


[GitHub] [incubator-superset] etr2460 commented on a change in pull request #9684: fix: migrate all slices off the old time grain format

Posted by GitBox <gi...@apache.org>.
etr2460 commented on a change in pull request #9684:
URL: https://github.com/apache/incubator-superset/pull/9684#discussion_r417594749



##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):
+    return {grain.name: grain.duration for grain in time_grains}
+
+
+@utils.memoized
+def duration_to_name(time_grains):
+    return {grain.duration: grain.name for grain in time_grains}
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    query = (
+        session.query(Slice, Database)
+        .filter(Slice.datasource_type == "table")
+        .filter(Slice.datasource_id == Table.id)
+        .filter(Table.database_id == Database.id)
+        .all()
+    )
+
+    for slc, database in query:
+        try:
+            params = json.loads(slc.params)
+            duration_dict = name_to_duration(database.grains())
+            granularity = params.get("time_grain_sqla")
+            if granularity in duration_dict:
+                params["time_grain_sqla"] = duration_dict.get(granularity)
+                slc.params = json.dumps(params, sort_keys=True, indent=4)

Review comment:
       i added the indent so the params could be more easily editable on the frontend. but we could do the prettifying client side and not put it in the db, so i'll remove it

##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):
+    return {grain.name: grain.duration for grain in time_grains}
+
+
+@utils.memoized
+def duration_to_name(time_grains):
+    return {grain.duration: grain.name for grain in time_grains}
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    query = (
+        session.query(Slice, Database)
+        .filter(Slice.datasource_type == "table")
+        .filter(Slice.datasource_id == Table.id)
+        .filter(Table.database_id == Database.id)
+        .all()
+    )
+
+    for slc, database in query:
+        try:
+            params = json.loads(slc.params)
+            duration_dict = name_to_duration(database.grains())
+            granularity = params.get("time_grain_sqla")
+            if granularity in duration_dict:
+                params["time_grain_sqla"] = duration_dict.get(granularity)

Review comment:
       done

##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):
+    return {grain.name: grain.duration for grain in time_grains}
+
+
+@utils.memoized
+def duration_to_name(time_grains):

Review comment:
       good catch, thanks!

##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):

Review comment:
       done

##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):

Review comment:
       good catch, updated




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


[GitHub] [incubator-superset] codecov-io edited a comment on pull request #9684: fix: migrate all slices off the old time grain format

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #9684:
URL: https://github.com/apache/incubator-superset/pull/9684#issuecomment-621457401


   # [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=h1) Report
   > Merging [#9684](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=desc) into [master](https://codecov.io/gh/apache/incubator-superset/commit/f13ba2561cd325c4bd4dc3c4700b618f195b89ed&el=desc) will **decrease** coverage by `0.02%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-superset/pull/9684/graphs/tree.svg?width=650&height=150&src=pr&token=KsB0fHcx6l)](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #9684      +/-   ##
   ==========================================
   - Coverage   65.75%   65.73%   -0.03%     
   ==========================================
     Files         581      581              
     Lines       30319    30320       +1     
     Branches     3096     3095       -1     
   ==========================================
   - Hits        19937    19930       -7     
   - Misses      10201    10209       +8     
     Partials      181      181              
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | #javascript | `58.77% <ø> (-0.02%)` | :arrow_down: |
   | #python | `70.61% <ø> (-0.04%)` | :arrow_down: |
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [superset/db\_engine\_specs/mysql.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL215c3FsLnB5) | `78.26% <0.00%> (-13.05%)` | :arrow_down: |
   | [superset/db\_engine\_specs/sqlite.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL3NxbGl0ZS5weQ==) | `63.33% <0.00%> (-10.01%)` | :arrow_down: |
   | [superset/result\_set.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvcmVzdWx0X3NldC5weQ==) | `96.63% <0.00%> (-1.69%)` | :arrow_down: |
   | [...explore/components/controls/AdhocFilterControl.jsx](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2V4cGxvcmUvY29tcG9uZW50cy9jb250cm9scy9BZGhvY0ZpbHRlckNvbnRyb2wuanN4) | `59.22% <0.00%> (-1.57%)` | :arrow_down: |
   | [superset/models/core.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvbW9kZWxzL2NvcmUucHk=) | `85.97% <0.00%> (-0.90%)` | :arrow_down: |
   | [superset/sql\_lab.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvc3FsX2xhYi5weQ==) | `77.63% <0.00%> (-0.44%)` | :arrow_down: |
   | [superset/db\_engine\_specs/base.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2Jhc2UucHk=) | `87.50% <0.00%> (-0.30%)` | :arrow_down: |
   | [superset/views/core.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvY29yZS5weQ==) | `74.88% <0.00%> (-0.19%)` | :arrow_down: |
   | [superset/connectors/sqla/models.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvY29ubmVjdG9ycy9zcWxhL21vZGVscy5weQ==) | `88.53% <0.00%> (+0.01%)` | :arrow_up: |
   | [superset/views/utils.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvdXRpbHMucHk=) | `82.91% <0.00%> (+0.21%)` | :arrow_up: |
   | ... and [2 more](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=footer). Last update [f13ba25...120fc86](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


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


[GitHub] [incubator-superset] codecov-io edited a comment on pull request #9684: fix: migrate all slices off the old time grain format

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #9684:
URL: https://github.com/apache/incubator-superset/pull/9684#issuecomment-621457401


   # [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=h1) Report
   > Merging [#9684](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=desc) into [master](https://codecov.io/gh/apache/incubator-superset/commit/f13ba2561cd325c4bd4dc3c4700b618f195b89ed&el=desc) will **increase** coverage by `4.81%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-superset/pull/9684/graphs/tree.svg?width=650&height=150&src=pr&token=KsB0fHcx6l)](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #9684      +/-   ##
   ==========================================
   + Coverage   65.75%   70.57%   +4.81%     
   ==========================================
     Files         581      581              
     Lines       30319    30320       +1     
     Branches     3096     3095       -1     
   ==========================================
   + Hits        19937    21397    +1460     
   + Misses      10201     8812    -1389     
   + Partials      181      111      -70     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | #cypress | `53.57% <ø> (?)` | |
   | #javascript | `58.77% <ø> (-0.02%)` | :arrow_down: |
   | #python | `70.68% <ø> (+0.03%)` | :arrow_up: |
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [superset/db\_engine\_specs/sqlite.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL3NxbGl0ZS5weQ==) | `63.33% <0.00%> (-10.01%)` | :arrow_down: |
   | [superset/result\_set.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvcmVzdWx0X3NldC5weQ==) | `96.63% <0.00%> (-1.69%)` | :arrow_down: |
   | [superset/sql\_lab.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvc3FsX2xhYi5weQ==) | `77.63% <0.00%> (-0.44%)` | :arrow_down: |
   | [superset/connectors/sqla/models.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvY29ubmVjdG9ycy9zcWxhL21vZGVscy5weQ==) | `88.53% <0.00%> (+0.01%)` | :arrow_up: |
   | [superset/views/core.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvY29yZS5weQ==) | `75.11% <0.00%> (+0.03%)` | :arrow_up: |
   | [superset/views/utils.py](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvdXRpbHMucHk=) | `82.91% <0.00%> (+0.21%)` | :arrow_up: |
   | [...rontend/src/SqlLab/components/AceEditorWrapper.tsx](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL1NxbExhYi9jb21wb25lbnRzL0FjZUVkaXRvcldyYXBwZXIudHN4) | `56.98% <0.00%> (+1.07%)` | :arrow_up: |
   | [superset-frontend/src/components/EditableTitle.jsx](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2NvbXBvbmVudHMvRWRpdGFibGVUaXRsZS5qc3g=) | `81.69% <0.00%> (+1.40%)` | :arrow_up: |
   | [...perset-frontend/src/components/CopyToClipboard.jsx](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2NvbXBvbmVudHMvQ29weVRvQ2xpcGJvYXJkLmpzeA==) | `36.36% <0.00%> (+1.51%)` | :arrow_up: |
   | [...hboard/components/resizable/ResizableContainer.jsx](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2Rhc2hib2FyZC9jb21wb25lbnRzL3Jlc2l6YWJsZS9SZXNpemFibGVDb250YWluZXIuanN4) | `71.87% <0.00%> (+1.56%)` | :arrow_up: |
   | ... and [142 more](https://codecov.io/gh/apache/incubator-superset/pull/9684/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=footer). Last update [f13ba25...120fc86](https://codecov.io/gh/apache/incubator-superset/pull/9684?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


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


[GitHub] [incubator-superset] john-bodley commented on a change in pull request #9684: fix: migrate all slices off the old time grain format

Posted by GitBox <gi...@apache.org>.
john-bodley commented on a change in pull request #9684:
URL: https://github.com/apache/incubator-superset/pull/9684#discussion_r417549551



##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,112 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def name_to_duration(time_grains):

Review comment:
       I don't think you want to memoize this signature as different databases may have different mappings for the same `time_grains`. It seems that,
   
   ```
   @utils.memoized
   def name_to_duration(database):
       time_grains = database.grains()
       ...
   ```
   
   would be safer.




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


[GitHub] [incubator-superset] john-bodley commented on a change in pull request #9684: fix: migrate all slices off the old time grain format

Posted by GitBox <gi...@apache.org>.
john-bodley commented on a change in pull request #9684:
URL: https://github.com/apache/incubator-superset/pull/9684#discussion_r417608891



##########
File path: superset/migrations/versions/620241d1153f_update_time_grain_sqla.py
##########
@@ -0,0 +1,108 @@
+# 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.
+"""update time_grain_sqla
+
+Revision ID: 620241d1153f
+Revises: f9a30386bd74
+Create Date: 2020-04-29 09:24:04.952368
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "620241d1153f"
+down_revision = "f9a30386bd74"
+
+import json
+
+from alembic import op
+from sqlalchemy import Column, ForeignKey, Integer, Text
+from sqlalchemy.engine.url import make_url
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db, db_engine_specs
+from superset.utils import core as utils
+
+Base = declarative_base()
+
+
+class Database(Base):
+    __tablename__ = "dbs"
+
+    id = Column(Integer, primary_key=True)
+    sqlalchemy_uri = Column(Text)
+
+    def grains(self):
+        url = make_url(self.sqlalchemy_uri)
+        backend = url.get_backend_name()
+        db_engine_spec = db_engine_specs.engines.get(
+            backend, db_engine_specs.BaseEngineSpec
+        )
+        return db_engine_spec.get_time_grains()
+
+
+class Table(Base):
+    __tablename__ = "tables"
+
+    id = Column(Integer, primary_key=True)
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+
+
+class Slice(Base):
+    __tablename__ = "slices"
+
+    id = Column(Integer, primary_key=True)
+    params = Column(Text)
+    datasource_type = Column(Text)
+    datasource_id = Column(Integer)
+
+
+@utils.memoized
+def duration_by_name(database: Database):
+    time_grains = database.grains()

Review comment:
       Nit. Not required but, 
   
   ```
   return {grain.name: grain.duration for grain in database.grains()}
   ```
   
   is more condensed and easier to grok. 




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