Skip to content

Commit 9f6d489

Browse files
mintlify[bot]igorlukaninovr
authored
docs: Add /v1/convert-query endpoint to REST API reference (cube-js#10689)
--------- Co-Authored-By: Igor Lukanin <igor@cube.dev> Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> Co-authored-by: Dmitry Patsura <talk@dmtry.me>
1 parent 9ba2897 commit 9f6d489

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

  • docs-mintlify/reference/core-data-apis/rest-api
  • docs/content/product/apis-integrations/core-data-apis/rest-api

docs-mintlify/reference/core-data-apis/rest-api/reference.mdx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,71 @@ Response:
243243
}
244244
```
245245

246+
## `{base_path}/v1/convert-query`
247+
248+
Takes an API query in the specified input format and converts it to the specified
249+
output format. Currently, only conversion from [SQL API](/reference/core-data-apis/sql-api) queries to
250+
[REST API](/reference/core-data-apis/rest-api) queries is supported.
251+
252+
This endpoint is useful for translating SQL API queries into equivalent REST API
253+
queries that can be used with the [`/v1/load`](#base_path%2Fv1%2Fload) endpoint.
254+
255+
Request parameters (JSON body):
256+
257+
| Parameter, type | Description | Required |
258+
| --- | --- | --- |
259+
| `input`, `string` | Input query format. Use `sql` for [SQL API](/reference/core-data-apis/sql-api) queries | ✅ Yes |
260+
| `output`, `string` | Output query format. Use `rest` for [REST API](/reference/core-data-apis/rest-api) queries | ✅ Yes |
261+
| `query`, `string` | Input query in the specified format | ✅ Yes |
262+
263+
The response will contain a JSON object with the following properties:
264+
265+
| Property, type | Description |
266+
| --- | --- |
267+
| `status`, `string` | Query conversion status, `ok` or `error` |
268+
| `query`, `object` | Converted query in the [REST API query format](/reference/core-data-apis/rest-api/query-format) (only present when `status` is `ok`) |
269+
| `error`, `string` | Error message (only present when `status` is `error`) |
270+
271+
An error will be returned if the input query can't be converted to the specified
272+
output format, e.g., if the SQL API query requires post-processing on top of
273+
REST API capabilities or if the SQL API query results in multiple REST API queries.
274+
275+
### Example
276+
277+
Request to convert a SQL API query with a filter:
278+
279+
```bash
280+
curl \
281+
-X POST \
282+
-H "Authorization: TOKEN" \
283+
-H "Content-Type: application/json" \
284+
-d '{"input": "sql", "output": "rest", "query": "SELECT MEASURE(total_amount) FROM orders WHERE status = '\''foo'\''"}' \
285+
http://localhost:4000/cubejs-api/v1/convert-query
286+
```
287+
288+
Successful response:
289+
290+
```json
291+
{
292+
"status": "ok",
293+
"query": {
294+
"measures": [
295+
"orders.total_amount"
296+
],
297+
"dimensions": [],
298+
"filters": [
299+
{
300+
"member": "orders.status",
301+
"operator": "equals",
302+
"values": ["foo"]
303+
}
304+
],
305+
"segments": [],
306+
"order": []
307+
}
308+
}
309+
```
310+
246311
## `{base_path}/v1/meta`
247312

248313
<Info>

docs/content/product/apis-integrations/core-data-apis/rest-api/reference.mdx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,71 @@ Response:
242242
}
243243
```
244244

245+
## `{base_path}/v1/convert-query`
246+
247+
Takes an API query in the specified input format and converts it to the specified
248+
output format. Currently, only conversion from [SQL API][ref-sql-api] queries to
249+
[REST API][ref-rest-api] queries is supported.
250+
251+
This endpoint is useful for translating SQL API queries into equivalent REST API
252+
queries that can be used with the [`/v1/load`](#base_pathv1load) endpoint.
253+
254+
Request parameters (JSON body):
255+
256+
| Parameter, type | Description | Required |
257+
| --- | --- | --- |
258+
| `input`, `string` | Input query format. Use `sql` for [SQL API][ref-sql-api] queries | ✅ Yes |
259+
| `output`, `string` | Output query format. Use `rest` for [REST API][ref-rest-api] queries | ✅ Yes |
260+
| `query`, `string` | Input query in the specified format | ✅ Yes |
261+
262+
The response will contain a JSON object with the following properties:
263+
264+
| Property, type | Description |
265+
| --- | --- |
266+
| `status`, `string` | Query conversion status, `ok` or `error` |
267+
| `query`, `object` | Converted query in the [REST API query format][ref-rest-api-query-format] (only present when `status` is `ok`) |
268+
| `error`, `string` | Error message (only present when `status` is `error`) |
269+
270+
An error will be returned if the input query can't be converted to the specified
271+
output format, e.g., if the SQL API query requires post-processing on top of
272+
REST API capabilities or if the SQL API query results in multiple REST API queries.
273+
274+
### Example
275+
276+
Request to convert a SQL API query with a filter:
277+
278+
```bash
279+
curl \
280+
-X POST \
281+
-H "Authorization: TOKEN" \
282+
-H "Content-Type: application/json" \
283+
-d '{"input": "sql", "output": "rest", "query": "SELECT MEASURE(total_amount) FROM orders WHERE status = '\''foo'\''"}' \
284+
http://localhost:4000/cubejs-api/v1/convert-query
285+
```
286+
287+
Successful response:
288+
289+
```json
290+
{
291+
"status": "ok",
292+
"query": {
293+
"measures": [
294+
"orders.total_amount"
295+
],
296+
"dimensions": [],
297+
"filters": [
298+
{
299+
"member": "orders.status",
300+
"operator": "equals",
301+
"values": ["foo"]
302+
}
303+
],
304+
"segments": [],
305+
"order": []
306+
}
307+
}
308+
```
309+
245310
## `{base_path}/v1/meta`
246311

247312
<InfoBox>
@@ -889,6 +954,7 @@ Keep-Alive: timeout=5
889954
[ref-datasources]: /product/configuration/advanced/multiple-data-sources
890955
[ref-sql-api]: /product/apis-integrations/sql-api
891956
[ref-rest-api]: /product/apis-integrations/rest-api
957+
[ref-rest-api-query-format]: /product/apis-integrations/rest-api/query-format
892958
[ref-regular-queries]: /product/apis-integrations/queries#regular-query
893959
[ref-query-wpp]: /product/apis-integrations/queries#query-with-post-processing
894960
[ref-query-wpd]: /product/apis-integrations/queries#query-with-pushdown

0 commit comments

Comments
 (0)