GitHub user dosubot[bot] added a comment to the discussion: Warm up charts cache via API
<!-- Answer --> You can construct the `query_context` JSON directly in your client. The [conversion from form_data happens server-side](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/charts/data/api.py#L450-L464), but you can also build the query_context structure manually. **query_context JSON structure:** ```json { "datasource": {"id": 1, "type": "table"}, "queries": [ { "columns": ["column_name"], "metrics": [{"label": "sum__value", "expressionType": "SIMPLE", "column": {"column_name": "value"}, "aggregate": "SUM"}], "filters": [{"col": "status", "op": "==", "val": "active"}], "granularity": "ds", "time_range": "Last 7 days", "row_limit": 1000, "orderby": [["sum__value", false]], "extras": {"time_grain_sqla": "P1D"} } ], "result_type": "full", "form_data": { /* your original form_data here */ } } ``` **Key fields from your form_data to map:** - `datasource` → split into `{"id": <id>, "type": "table"}` - `viz_type` → determines which `metrics`/`columns`/`groupby` fields to use - `metrics`, `groupby`, `columns` → go into `queries[0].metrics` and `queries[0].columns` - `adhoc_filters` → convert to `queries[0].filters` format - `time_range`, `granularity_sqla` → map to `queries[0].time_range` and `queries[0].granularity` - `row_limit` → `queries[0].row_limit` **Simplest approach for your client:** POST your form_data directly to `/api/v1/chart/data` and [Superset will handle the conversion](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/charts/schemas.py#L1363-L1399): ```bash POST /api/v1/chart/data { "datasource": {"id": 1, "type": "table"}, "queries": [...], # or just send form_data and let server convert "form_data": { ...your form_data... } } ``` You can reference the [test fixtures](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/tests/common/query_context_generator.py#L244-L268) for complete examples of valid query_context structures. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/d03793d0-d19b-4c9e-a974-c2d1d5c10423?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/d03793d0-d19b-4c9e-a974-c2d1d5c10423?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/d03793d0-d19b-4c9e-a974-c2d1d5c10423?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/d03793d0-d19b-4c9e-a974-c2d1d5c10423?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d03793d0-d19b-4c 9e-a974-c2d1d5c10423?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/d03793d0-d19b-4c9e-a974-c2d1d5c10423?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/d03793d0-d19b-4c9e-a974-c2d1d5c10423?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge) [](https://cursor.com/link/prompt?text=You%20can%20construct%20the%20%60query_context%60%20JSON%20directly%20in%20your%20client.%20The%20%5Bconversion%20from%20form_data%20happens%20server-side%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/charts/data/api.py%23L450-L464%29%2C%20but%20you%20can%20also%20build%20the%20query_context%20structure%20manually.%0A%0A%2A%2Aquery_context%20JSON%20structure%3A%2A%2A%0A%0A%60%60%60json%0A%7B%0A%20%20%22datasource%22%3A%20%7B%22id%22%3A%201%2C%20%22type%22%3A%20%22table%22%7D%2C%0A%20%20%22queries%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22columns%22%3A%20%5B%22column_name%22%5D%2C%0A%20%20%20%20%20%20%22metrics%22%3A %20%5B%7B%22label%22%3A%20%22sum__value%22%2C%20%22expressionType%22%3A%20%22SIMPLE%22%2C%20%22column%22%3A%20%7B%22column_name%22%3A%20%22value%22%7D%2C%20%22aggregate%22%3A%20%22SUM%22%7D%5D%2C%0A%20%20%20%20%20%20%22filters%22%3A%20%5B%7B%22col%22%3A%20%22status%22%2C%20%22op%22%3A%20%22%3D%3D%22%2C%20%22val%22%3A%20%22active%22%7D%5D%2C%0A%20%20%20%20%20%20%22granularity%22%3A%20%22ds%22%2C%0A%20%20%20%20%20%20%22time_range%22%3A%20%22Last%207%20days%22%2C%0A%20%20%20%20%20%20%22row_limit%22%3A%201000%2C%0A%20%20%20%20%20%20%22orderby%22%3A%20%5B%5B%22sum__value%22%2C%20false%5D%5D%2C%0A%20%20%20%20%20%20%22extras%22%3A%20%7B%22time_grain_sqla%22%3A%20%22P1D%22%7D%0A%20%20%20%20%7D%0A%20%20%5D%2C%0A%20%20%22result_type%22%3A%20%22full%22%2C%0A%20%20%22form_data%22%3A%20%7B%20/%2A%20your%20original%20form_data%20here%20%2A/%20%7D%0A%7D%0A%60%60%60%0A%0A%2A%2AKey%20fields%20from%20your%20form_data%20to%20map%3A%2A%2A%0A-%20%60datasource%60%20%E2%86%92%20split%20into%20%60%7B%22id% 22%3A%20%3Cid%3E%2C%20%22type%22%3A%20%22table%22%7D%60%0A-%20%60viz_type%60%20%E2%86%92%20determines%20which%20%60metrics%60/%60columns%60/%60groupby%60%20fields%20to%20use%0A-%20%60metrics%60%2C%20%60groupby%60%2C%20%60columns%60%20%E2%86%92%20go%20into%20%60queries%5B0%5D.metrics%60%20and%20%60queries%5B0%5D.columns%60%0A-%20%60adhoc_filters%60%20%E2%86%92%20convert%20to%20%60queries%5B0%5D.filters%60%20format%0A-%20%60time_range%60%2C%20%60granularity_sqla%60%20%E2%86%92%20map%20to%20%60queries%5B0%5D.time_range%60%20and%20%60queries%5B0%5D.granularity%60%0A-%20%60row_limit%60%20%E2%86%92%20%60queries%5B0%5D.row_limit%60%0A%0A%2A%2ASimplest%20approach%20for%20your%20client%3A%2A%2A%0A%0APOST%20your%20form_data%20directly%20to%20%60/api/v1/chart/data%60%20and%20%5BSuperset%20will%20handle%20the%20conversion%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/charts/schemas.py%23L1363-L1399%29%3A%0A%0A%60%60%60bash%0APOST%20/api/v1/char t/data%0A%7B%0A%20%20%22datasource%22%3A%20%7B%22id%22%3A%201%2C%20%22type%22%3A%20%22table%22%7D%2C%0A%20%20%22queries%22%3A%20%5B...%5D%2C%20%20%23%20or%20just%20send%20form_data%20and%20let%20server%20convert%0A%20%20%22form_data%22%3A%20%7B%20...your%20form_data...%20%7D%0A%7D%0A%60%60%60%0A%0AYou%20can%20reference%20the%20%5Btest%20fixtures%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/tests/common/query_context_generator.py%23L244-L268%29%20for%20complete%20examples%20of%20valid%20query_context%20structures.) [](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions /38718) GitHub link: https://github.com/apache/superset/discussions/38718#discussioncomment-16192853 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
