Skip to content

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

Merged
betodealmeida merged 2 commits intoapache:masterfrom
betodealmeida:get_chart_data_api_2
Jul 22, 2021
Merged

feat: add GET /api/v1/chart/{chart_id}/data/?format{format} API#15827
betodealmeida merged 2 commits intoapache:masterfrom
betodealmeida:get_chart_data_api_2

Conversation

@betodealmeida
Copy link
Copy Markdown
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

@betodealmeida betodealmeida force-pushed the get_chart_data_api_2 branch from 420ecef to 221ec86 Compare July 21, 2021 23:08
rv = self.post_assert_metric(CHART_DATA_URI, request_payload, "post_data")
self.assertEqual(rv.status_code, 200)
data = json.loads(rv.data.decode("utf-8"))
print(data)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

debug?

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

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 First shipped in 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 First shipped in 1.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants