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(dashboard): Return columns and verbose_map for groupby values of Pivot Table v2 [ID-7] #17287

Merged
merged 6 commits into from
Nov 5, 2021

Conversation

kgabryje
Copy link
Member

SUMMARY

Columns used by Pivot Table v2 were not processed correctly by /dashboard/{id}/datasets endpoint, resulting in chart not displaying custom column labels when added to dashboard. This PR fixes the issue.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:
image

After:
image

TESTING INSTRUCTIONS

  1. Create a pivot table v2 chart using columns with custom labels
  2. Add the chart to dashboard
  3. Verify that custom labels are used instead of column_names

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

CC @junlincc

@codecov
Copy link

codecov bot commented Oct 29, 2021

Codecov Report

Merging #17287 (6695113) into master (f0c0ef7) will decrease coverage by 0.24%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17287      +/-   ##
==========================================
- Coverage   77.04%   76.80%   -0.25%     
==========================================
  Files        1037     1037              
  Lines       55635    55718      +83     
  Branches     7594     7594              
==========================================
- Hits        42863    42792      -71     
- Misses      12522    12676     +154     
  Partials      250      250              
Flag Coverage Δ
hive ?
mysql 81.90% <75.00%> (-0.07%) ⬇️
postgres 81.91% <75.00%> (-0.07%) ⬇️
presto ?
python 82.00% <75.00%> (-0.49%) ⬇️
sqlite 81.59% <75.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/models/slice.py 85.05% <60.00%> (-1.37%) ⬇️
superset/connectors/base/models.py 88.36% <100.00%> (+0.11%) ⬆️
superset/examples/birth_names.py 71.02% <100.00%> (-2.76%) ⬇️
superset/db_engines/hive.py 0.00% <0.00%> (-85.19%) ⬇️
superset/db_engine_specs/hive.py 69.76% <0.00%> (-17.06%) ⬇️
superset/db_engine_specs/presto.py 83.47% <0.00%> (-6.91%) ⬇️
superset/views/dashboard/views.py 68.91% <0.00%> (-4.06%) ⬇️
superset/datasets/dao.py 93.70% <0.00%> (-2.80%) ⬇️
superset/examples/paris.py 25.00% <0.00%> (-1.93%) ⬇️
... and 32 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 f0c0ef7...6695113. Read the comment docs.

@pull-request-size pull-request-size bot added size/M and removed size/XS labels Nov 4, 2021
@kgabryje kgabryje changed the title fix(dashboard): Return columns and verbose_map for groupby values of Pivot Table v2 fix(dashboard): Return columns and verbose_map for groupby values of Pivot Table v2 [ID-7] Nov 4, 2021
superset/connectors/base/models.py Outdated Show resolved Hide resolved
Comment on lines 250 to 260
def get_query_context(self) -> Dict[str, Any]:
query_context: Dict[str, Any] = {}
if not self.query_context:
return query_context
try:
query_context = json.loads(self.query_context)
except json.decoder.JSONDecodeError as ex:
logger.error("Malformed json in slice's query context", exc_info=True)
logger.exception(ex)
return query_context

Copy link
Member

Choose a reason for hiding this comment

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

We can make this function more generic. like this:

    def get_query_context(self) -> QueryContext:
        if self.query_context:
            try:
                return self.query_context(**json.loads(self.query_context))
            except json.decoder.JSONDecodeError as ex:
                logger.error("Malformed json in slice's query context", exc_info=True)
                logger.exception(ex)
        return QueryContext(
                       datasource={"type": self.datasource_type, "id": self.datasource_id},
                       queries=[self.viz.query_obj()],)

Copy link
Member

Choose a reason for hiding this comment

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

@zhaoyongjie on the first return statement I believe we could instantiate the QueryContext. Also, for non v1 charts or in the case there isn't a query context payload, we probably should just return None, as the legacy charts aren't really compatible with QueryContext. Could this work?

    def get_query_context(self) -> Optional[QueryContext]:
        if self.query_context:
            try:
                return QueryContext(**json.loads(self.query_context))
            except json.decoder.JSONDecodeError as ex:
                logger.error("Malformed json in slice's query context", exc_info=True)
                logger.exception(ex)
        return None

Copy link
Member

Choose a reason for hiding this comment

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

Nice! It makes sense return None in legacy chart.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for suggestions! I made the change, would appreciate another look 🙂

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

Looking good! get_query_context may still need some iterations, would be interested in hearing @zhaoyongjie's thoughts

Comment on lines 250 to 260
def get_query_context(self) -> Dict[str, Any]:
query_context: Dict[str, Any] = {}
if not self.query_context:
return query_context
try:
query_context = json.loads(self.query_context)
except json.decoder.JSONDecodeError as ex:
logger.error("Malformed json in slice's query context", exc_info=True)
logger.exception(ex)
return query_context

Copy link
Member

Choose a reason for hiding this comment

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

@zhaoyongjie on the first return statement I believe we could instantiate the QueryContext. Also, for non v1 charts or in the case there isn't a query context payload, we probably should just return None, as the legacy charts aren't really compatible with QueryContext. Could this work?

    def get_query_context(self) -> Optional[QueryContext]:
        if self.query_context:
            try:
                return QueryContext(**json.loads(self.query_context))
            except json.decoder.JSONDecodeError as ex:
                logger.error("Malformed json in slice's query context", exc_info=True)
                logger.exception(ex)
        return None

@pull-request-size pull-request-size bot added size/L and removed size/M labels Nov 5, 2021
@kgabryje
Copy link
Member Author

kgabryje commented Nov 5, 2021

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2021

@kgabryje Ephemeral environment spinning up at http://54.213.130.117:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM, solid work @kgabryje ! 🎉

@zhaoyongjie zhaoyongjie self-requested a review November 5, 2021 15:03
Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

LGTM.

@kgabryje kgabryje merged commit fa51b32 into apache:master Nov 5, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2021

Ephemeral environment shutdown and build artifacts deleted.

@sadpandajoe
Copy link
Member

🏷️ 2021.46

AAfghahi pushed a commit that referenced this pull request Jan 10, 2022
…Pivot Table v2 [ID-7] (#17287)

* fix(dashboard): Return columns and verbose_map for groupby values of Pivot Table v2

* Refactor

* Fix test and lint

* Fix test

* Refactor

* Fix lint
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Mar 13, 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 lts-v1 preset:2021.46 size/L 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants