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

fix: migrate all slices off the old time grain format #9684

Merged
merged 1 commit into from Apr 30, 2020

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented Apr 29, 2020

CATEGORY

Choose one

  • 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 #4755 (comment)).

I've replicated/updated @jeffreythewang's work (thanks Jeffrey!) from #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

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

to: @john-bodley @villebro @mistercrunch @jeffreythewang

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's nix the indent as it unnecessarily bloats the database.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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



@utils.memoized
def name_to_duration(time_grains):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, updated



@utils.memoized
def duration_to_name(time_grains):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks!



@utils.memoized
def name_to_duration(time_grains):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit could we call this duration_by_name for consistency when naming dictionary mappings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@etr2460 etr2460 force-pushed the erik-ritter--migrate-time-grain-sqla branch from 0269e58 to 120fc86 Compare April 29, 2020 20:44
@codecov-io
Copy link

codecov-io commented Apr 29, 2020

Codecov Report

Merging #9684 into master will increase coverage by 4.81%.
The diff coverage is n/a.

Impacted file tree graph

@@            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%) ⬇️
#python 70.68% <ø> (+0.03%) ⬆️
Impacted Files Coverage Δ
superset/db_engine_specs/sqlite.py 63.33% <0.00%> (-10.01%) ⬇️
superset/result_set.py 96.63% <0.00%> (-1.69%) ⬇️
superset/sql_lab.py 77.63% <0.00%> (-0.44%) ⬇️
superset/connectors/sqla/models.py 88.53% <0.00%> (+0.01%) ⬆️
superset/views/core.py 75.11% <0.00%> (+0.03%) ⬆️
superset/views/utils.py 82.91% <0.00%> (+0.21%) ⬆️
...rontend/src/SqlLab/components/AceEditorWrapper.tsx 56.98% <0.00%> (+1.07%) ⬆️
superset-frontend/src/components/EditableTitle.jsx 81.69% <0.00%> (+1.40%) ⬆️
...perset-frontend/src/components/CopyToClipboard.jsx 36.36% <0.00%> (+1.51%) ⬆️
...hboard/components/resizable/ResizableContainer.jsx 71.87% <0.00%> (+1.56%) ⬆️
... and 142 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f13ba25...120fc86. Read the comment docs.


@utils.memoized
def duration_by_name(database: Database):
time_grains = database.grains()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Not required but,

return {grain.name: grain.duration for grain in database.grains()}

is more condensed and easier to grok.

@etr2460 etr2460 force-pushed the erik-ritter--migrate-time-grain-sqla branch from 120fc86 to 107c5ae Compare April 30, 2020 00:23
@etr2460 etr2460 merged commit e95af7f into apache:master Apr 30, 2020
john-bodley pushed a commit to airbnb/superset-fork that referenced this pull request Apr 30, 2020
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants