Skip to content

Commit 1a29f33

Browse files
authored
docs: Examples for the /v1/sql endpoint (#9367)
1 parent fff8af2 commit 1a29f33

File tree

14 files changed

+107
-52
lines changed

14 files changed

+107
-52
lines changed

docs/pages/guides/recipes/access-control/controlling-access-to-cubes-and-views.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ view(`total_revenue_per_customer`, {
109109
After generating a JWT with a `department` claim set to `finance`, we can send
110110
it as part of a cURL command:
111111

112-
```bash{outputLines: 2-3}
112+
```bash
113113
curl \
114114
-H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXBhcnRtZW50IjoiZmluYW5jZSIsImV4cCI6MTY2NzMzNzI1MH0.njfL7GMDNlzKaJDZA0OQ_b2u2JhuSm-WjnS0yVfB8NA" \
115115
http://localhost:4000/cubejs-api/v1/meta

docs/pages/guides/recipes/access-control/enforcing-mandatory-filters.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = {
4040

4141
To get the orders we will send two queries with filters by status:
4242

43-
```bash{outputLines: 1,3-13}
43+
```bash
4444
# Completed orders
4545
curl cube:4000/cubejs-api/v1/load \
4646
-H "Authorization: eeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoib3BlcmF0b3IiLCJpYXQiOjE2Mjg3NDUwNDUsImV4cCI6MTgwMTU0NTA0NX0.VErb2t7Bc43ryRwaOiEgXuU5KiolCT-69eI_i2pRq4o" \
@@ -56,7 +56,7 @@ curl cube:4000/cubejs-api/v1/load \
5656
}'
5757
```
5858

59-
```bash{outputLines: 1,3-13}
59+
```bash
6060
# Shipped orders
6161
curl cube:4000/cubejs-api/v1/load \
6262
-H "Authorization: eeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoib3BlcmF0b3IiLCJpYXQiOjE2Mjg3NDUwNDUsImV4cCI6MTgwMTU0NTA0NX0.VErb2t7Bc43ryRwaOiEgXuU5KiolCT-69eI_i2pRq4o" \

docs/pages/guides/recipes/analytics/active-users.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ cube(`active_users`, {
123123

124124
We should set a `timeDimensions` with the `dateRange`.
125125

126-
```bash{outputLines: 2-18}
126+
```bash
127127
curl cube:4000/cubejs-api/v1/load \
128128
'query={
129129
"measures": [

docs/pages/product/apis-integrations/ai-api/reference.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Response
3333

3434
Example request:
3535

36-
```bash{outputLines: 1,3-9,11-15}
36+
```bash
3737
curl \
3838
-X POST \
3939
-H "Content-Type: application/json" \
@@ -67,7 +67,7 @@ Example response:
6767

6868
#### With `runQuery`
6969

70-
```bash{outputLines: 1,3-9,11-15}
70+
```bash
7171
curl \
7272
-X POST \
7373
-H "Content-Type: application/json" \

docs/pages/product/apis-integrations/javascript-sdk.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ that you can always use a different charting library that suits your needs:
8484

8585
You can install Cube JavaScript Client with npm or Yarn:
8686

87-
```bash{outputLines: 1,3-4}
87+
```bash
8888
# npm
8989
npm install --save @cubejs-client/core
9090

docs/pages/product/apis-integrations/javascript-sdk/angular.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ can always use a different charting library that suits your needs:
9393

9494
You can install Cube JavaScript Client and the Angular package with npm or Yarn:
9595

96-
```bash{outputLines: 1,3-4}
96+
```bash
9797
# npm
9898
npm install --save @cubejs-client/core @cubejs-client/ngx
9999

docs/pages/product/apis-integrations/javascript-sdk/react.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ always use a different charting library that suits your needs:
102102

103103
You can install Cube JavaScript Client and the React package with npm or Yarn:
104104

105-
```bash{outputLines: 1,3-4}
105+
```bash
106106
# npm
107107
npm install --save @cubejs-client/core @cubejs-client/react
108108

docs/pages/product/apis-integrations/javascript-sdk/reference/cubejs-client-ngx.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Angular app.
77

88
First, install `@cubejs-client/ngx` using npm or yarn:
99

10-
```bash{outputLines: 2}
10+
```bash
1111
npm install --save @cubejs-client/ngx
1212
# or
1313
yarn add @cubejs-client/ngx

docs/pages/product/apis-integrations/javascript-sdk/vue.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ always use a different charting library that suits your needs:
9898

9999
You can install Cube JavaScript Client and the Vue package with npm or Yarn:
100100

101-
```bash{outputLines: 1,3-4}
101+
```bash
102102
# npm
103103
npm install --save @cubejs-client/core @cubejs-client/vue3
104104

docs/pages/product/apis-integrations/rest-api/reference.mdx

Lines changed: 92 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Response
3838

3939
Example request:
4040

41-
```bash{outputLines: 1,3-9,11-15}
41+
```bash
4242
# Request with http method GET
4343
curl \
4444
-H "Authorization: EXAMPLE-API-TOKEN" \
@@ -143,14 +143,14 @@ the query can't be run without post-processing.
143143

144144
### Example
145145

146-
Request:
146+
Request with a query in the REST API format:
147147

148-
```bash{outputLines: 2-6}
148+
```bash
149149
curl \
150-
-H "Authorization: EXAMPLE-API-TOKEN" \
150+
-H "Authorization: TOKEN" \
151151
-G \
152-
--data-urlencode 'query={"measures":["users.count"],
153-
"timeDimensions":[{"dimension": "users.createdAt","granularity":"day","dateRange":["2019-03-01","2019-03-31"]}]}' \
152+
--data-urlencode 'query={"measures":["orders.count"]}' \
153+
--data-urlencode 'format=rest' \
154154
http://localhost:4000/cubejs-api/v1/sql
155155
```
156156

@@ -160,34 +160,89 @@ Response:
160160
{
161161
"sql": {
162162
"sql": [
163-
"SELECT\n date_trunc('day', (users.created_at::timestamptz AT TIME ZONE 'UTC')) \"users.created_at_date\", count(users.id) \"users.count\"\n FROM\n public.users AS users\n WHERE (users.created_at >= $1::timestamptz AND users.created_at <= $2::timestamptz) GROUP BY 1 ORDER BY 1 ASC LIMIT 10000",
164-
["2019-03-01T00:00:00Z", "2019-03-31T23:59:59Z"]
165-
],
166-
"timeDimensionAlias": "users.created_at_date",
167-
"timeDimensionField": "users.createdAt",
168-
"order": [
169-
{
170-
"id": "users.createdAt",
171-
"desc": false
172-
}
163+
"SELECT sum(`base_orders__count`) `orders__count` FROM prod_pre_aggregations.base_orders_orders_by_month AS `base_orders__orders_by_month` LIMIT 10000",
164+
[]
165+
]
166+
}
167+
}
168+
```
169+
170+
Request with a query in the SQL API format:
171+
172+
```bash
173+
curl \
174+
-H "Authorization: TOKEN" \
175+
-G \
176+
--data-urlencode 'query=SELECT COUNT(*) FROM orders' \
177+
--data-urlencode 'format=sql' \
178+
http://localhost:4000/cubejs-api/v1/sql
179+
```
180+
181+
Response:
182+
183+
```json
184+
{
185+
"sql": {
186+
"status": "ok",
187+
"sql": [
188+
"SELECT\n count(\"base_orders\".id) \"count_uint8_1__\"\n FROM\n (SELECT * FROM 's3://cube-tutorial/orders.csv') AS \"base_orders\" LIMIT 50000",
189+
[]
173190
],
174-
"cacheKeyQueries": {
175-
"queries": [
176-
["select max(users.created_at) from public.users AS users", []]
177-
],
178-
"renewalThreshold": 21600
179-
},
180-
"preAggregations": []
191+
"query_type": "regular"
181192
}
182193
}
183194
```
184195

185-
<InfoBox>
196+
Request with a query in the SQL API format that is executed with post-processing:
186197

187-
Note that a generated query can contain placeholders, e.g., `?` or `$1`, for parameters
188-
that Cube passes to an underlying data source driver later when executing the query.
198+
```bash
199+
curl \
200+
-H "Authorization: TOKEN" \
201+
-G \
202+
--data-urlencode 'query=SELECT AVG(count) FROM (SELECT COUNT(*) AS count FROM orders) AS table' \
203+
--data-urlencode 'format=sql' \
204+
http://localhost:4000/cubejs-api/v1/sql
205+
```
189206

190-
</InfoBox>
207+
Response:
208+
209+
```json
210+
{
211+
"sql": {
212+
"status": "error",
213+
"error": "Provided query can not be executed without post-processing.",
214+
"query_type": "post_processing"
215+
}
216+
}
217+
```
218+
219+
Request with a query in the SQL API format that is forced to be executed without
220+
post-processing, i.e., as a query with pushdown:
221+
222+
```bash
223+
curl \
224+
-H "Authorization: TOKEN" \
225+
-G \
226+
--data-urlencode 'query=SELECT AVG(count) FROM (SELECT COUNT(*) AS count FROM orders) AS table' \
227+
--data-urlencode 'format=sql' \
228+
--data-urlencode 'disable_post_processing=true' \
229+
http://localhost:4000/cubejs-api/v1/sql
230+
```
231+
232+
Response:
233+
234+
```json
235+
{
236+
"sql": {
237+
"status": "ok",
238+
"sql": [
239+
"SELECT \"table\".\"avg_table_count_\" \"avg_table_count_\" \nFROM (\n SELECT AVG(\"table\".\"count\") \"avg_table_count_\" \n FROM (\n SELECT\n count(\"base_orders\".id) \"count\"\n FROM\n (SELECT * FROM 's3://cube-tutorial/orders.csv') AS \"base_orders\" \n ) AS \"table\"\n) AS \"table\"\nLIMIT 50000",
240+
[]
241+
],
242+
"query_type": "pushdown"
243+
}
244+
}
245+
```
191246

192247
## `{base_path}/v1/meta`
193248

@@ -210,7 +265,7 @@ Response
210265

211266
Example request:
212267

213-
```bash{outputLines: 2-4}
268+
```bash
214269
curl \
215270
-H "Authorization: EXAMPLE-API-TOKEN" \
216271
-G \
@@ -282,7 +337,7 @@ contain an array of `tokens` (identifiers) of triggered jobs.
282337
Example request triggering builds of all pre-aggregations defined in all cubes
283338
using an empty security context and a `UTC` timezone:
284339

285-
```bash{outputLines: 2-12}
340+
```bash
286341
curl \
287342
-d '{
288343
"action": "post",
@@ -300,7 +355,7 @@ curl \
300355
Example request triggering builds of all pre-aggregations defined in the
301356
`orders` cube using an empty security context and a `UTC` timezone:
302357

303-
```bash{outputLines: 2-13}
358+
```bash
304359
curl \
305360
-d '{
306361
"action": "post",
@@ -319,7 +374,7 @@ curl \
319374
Example request triggering builds of the `main` pre-aggregation defined in the
320375
`orders` cube using an empty security context and a `UTC` timezone:
321376

322-
```bash{outputLines: 2-13}
377+
```bash
323378
curl \
324379
-d '{
325380
"action": "post",
@@ -339,7 +394,7 @@ Example request triggering builds of the `main` pre-aggregation defined in the
339394
`orders` cube within date range with some security context data
340395
and an `America/Los_Angeles` timezone:
341396

342-
```bash{outputLines: 2-13}
397+
```bash
343398
curl \
344399
-d '{
345400
"action": "post",
@@ -389,7 +444,7 @@ In the `status` property of the payload, you can get the following statuses:
389444

390445
Example request:
391446

392-
```bash{outputLines: 2-14}
447+
```bash
393448
curl \
394449
-d '{
395450
"action": "get",
@@ -442,7 +497,7 @@ the connection to the _default_ [data source][ref-datasources].
442497

443498
Example of a successful request:
444499

445-
```bash{outputLines: 2-12}
500+
```bash
446501
curl -i http://localhost:4000/readyz
447502
HTTP/1.1 200 OK
448503
X-Powered-By: Express
@@ -459,7 +514,7 @@ Keep-Alive: timeout=5
459514

460515
Example of a failed response:
461516

462-
```bash{outputLines: 2-12}
517+
```bash
463518
curl -i http://localhost:4000/readyz
464519
HTTP/1.1 500 Internal Server Error
465520
X-Powered-By: Express
@@ -481,7 +536,7 @@ existing connections to data sources.
481536

482537
Example of a successful response:
483538

484-
```bash{outputLines: 2-12}
539+
```bash
485540
curl -i http://localhost:4000/livez
486541
HTTP/1.1 200 OK
487542
X-Powered-By: Express
@@ -498,7 +553,7 @@ Keep-Alive: timeout=5
498553

499554
Example of a failed response:
500555

501-
```bash{outputLines: 2-12}
556+
```bash
502557
curl -i http://localhost:4000/livez
503558
HTTP/1.1 500 Internal Server Error
504559
X-Powered-By: Express

0 commit comments

Comments
 (0)