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

feat: add GET /api/v1/chart/{chart_id}/data/?format{format} API #15827

Merged
merged 2 commits into from
Jul 22, 2021

Conversation

betodealmeida
Copy link
Member

@betodealmeida betodealmeida commented Jul 21, 2021

SUMMARY

This PR adds a new API for retrieving data associated with a saved chart via a GET request.

The API uses the stored query_context (#15824) to run the query and fetch the data.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

I accessed the endpoint manually by hitting http://localhost:9000/api/v1/chart/56/data/:

{
  "result": [
    {
      "cache_key": "bf6383e65e2d57b646778b8b0bbb875b",
      "cached_dttm": null,
      "cache_timeout": 86400,
      "annotation_data": {},
      "error": null,
      "is_cached": false,
      "query": "SELECT gender AS gender,\n       SUM(num) AS sum__num\nFROM birth_names\nWHERE ds >= TO_TIMESTAMP('1900-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')\n  AND ds < TO_TIMESTAMP('2000-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')\nGROUP BY gender\nORDER BY sum__num DESC\nLIMIT 50000",
      "status": "success",
      "stacktrace": null,
      "rowcount": 2,
      "colnames": [
        "gender",
        "sum__num"
      ],
      "coltypes": [
        1,
        0
      ],
      "data": [
        {
          "gender": "boy",
          "sum__num": 40276116
        },
        {
          "gender": "girl",
          "sum__num": 28055783
        }
      ],
      "applied_filters": [],
      "rejected_filters": []
    }
  ]
}

And http://localhost:9000/api/v1/chart/56/data/?format=csv:

gender,sum__num
boy,40276116
girl,28055783

I also added unit tests covering the case where query_context is null, and the case where it's present and data is returned.

ADDITIONAL INFORMATION

  • Has associated issue:
  • 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

self.assertEqual(rv.status_code, 200)
data = json.loads(rv.data.decode("utf-8"))
print(data)
Copy link
Member

Choose a reason for hiding this comment

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

debug?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh, thanks! :)

Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

LGTM pending one small debug leftover

@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #15827 (22e1b3d) into master (9a79a57) will increase coverage by 0.00%.
The diff coverage is 81.39%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #15827   +/-   ##
=======================================
  Coverage   76.90%   76.90%           
=======================================
  Files         984      984           
  Lines       51670    51698   +28     
  Branches     6991     6991           
=======================================
+ Hits        39736    39758   +22     
- Misses      11710    11716    +6     
  Partials      224      224           
Flag Coverage Δ
mysql 81.53% <81.39%> (-0.01%) ⬇️
postgres 81.56% <81.39%> (-0.01%) ⬇️
python 81.65% <81.39%> (-0.01%) ⬇️
sqlite 81.19% <81.39%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
superset/charts/api.py 86.17% <81.39%> (-0.63%) ⬇️

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 9a79a57...22e1b3d. Read the comment docs.

@betodealmeida betodealmeida merged commit f104fba into apache:master Jul 22, 2021
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
…ache#15827)

* feat: add `GET /api/v1/chart/{chart_id}/data/?format{format}` API

* Fix test
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
…ache#15827)

* feat: add `GET /api/v1/chart/{chart_id}/data/?format{format}` API

* Fix test
@santiblanko
Copy link

I need this data paginated. It's possible?

cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
…ache#15827)

* feat: add `GET /api/v1/chart/{chart_id}/data/?format{format}` API

* Fix test
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.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 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants