Skip to content

Commit 7182699

Browse files
ektravelvtlim
andauthored
Docs: Add SQL query example (#17593)
* Docs: Add query example * Update after review * Update query * Update docs/api-reference/sql-api.md --------- Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com>
1 parent f8fa3f7 commit 7182699

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

docs/api-reference/sql-api.md

+9-12
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,18 @@ The request body takes the following properties:
8585

8686
* `context`: JSON object containing optional [SQL query context parameters](../querying/sql-query-context.md), such as to set the query ID, time zone, and whether to use an approximation algorithm for distinct count.
8787

88-
* `parameters`: List of query parameters for parameterized queries. Each parameter in the array should be a JSON object containing the parameter's SQL data type and parameter value. For a list of supported SQL types, see [Data types](../querying/sql-data-types.md).
88+
* `parameters`: List of query parameters for parameterized queries. Each parameter in the array should be a JSON object containing the parameter's SQL data type and parameter value. For more information on using dynamic parameters, see [Dynamic parameters](../querying/sql.md#dynamic-parameters). For a list of supported SQL types, see [Data types](../querying/sql-data-types.md).
8989

9090
For example:
91+
9192
```json
92-
"parameters": [
93-
{
94-
"type": "VARCHAR",
95-
"value": "bar"
96-
},
97-
{
98-
"type": "ARRAY",
99-
"value": [-25.7, null, 36.85]
100-
}
101-
]
93+
{
94+
"query": "SELECT \"arrayDouble\", \"stringColumn\" FROM \"array_example\" WHERE ARRAY_CONTAINS(\"arrayDouble\", ?) AND \"stringColumn\" = ?",
95+
"parameters": [
96+
{"type": "ARRAY", "value": [999.0, null, 5.5]},
97+
{"type": "VARCHAR", "value": "bar"}
98+
]
99+
}
102100
```
103101

104102
#### Responses
@@ -155,7 +153,6 @@ If you detect a truncated response, treat it as an error.
155153

156154
---
157155

158-
159156
#### Sample request
160157

161158
The following example retrieves all rows in the `wikipedia` datasource where the `user` is `BlueMoon2662`. The query is assigned the ID `request01` using the `sqlQueryId` context parameter. The optional properties `header`, `typesHeader`, and `sqlTypesHeader` are set to `true` to include type information to the response.

docs/querying/sql.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ The following example query uses the [ARRAY_CONTAINS](./sql-functions.md#array_c
403403

404404
```sql
405405
{
406-
"query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(?, doubleArrayColumn)",
406+
"query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(doubleArrayColumn, ?)",
407407
"parameters": [
408408
{
409409
"type": "ARRAY",
@@ -428,17 +428,16 @@ SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%')
428428
Dynamic parameters can even replace arrays, reducing the parsing time. Refer to the parameters in the [API request body](../api-reference/sql-api.md#request-body) for usage.
429429

430430
```sql
431-
SELECT arrayColumn from druid.table where ARRAY_CONTAINS(?, arrayColumn)
431+
SELECT arrayColumn from druid.table where ARRAY_CONTAINS(arrayColumn, ?)
432432
```
433433

434-
With this, an IN filter being supplied with a lot of values, can be replaced by a dynamic parameter passed inside [SCALAR_IN_ARRAY](sql-functions.md#scalar_in_array)
434+
You can replace an IN filter with many values by dynamically passing a parameter into [SCALAR_IN_ARRAY](sql-functions.md#scalar_in_array).
435+
For example Java queries, see [Dynamic parameters](../api-reference/sql-jdbc.md#dynamic-parameters).
435436

436437
```sql
437438
SELECT count(city) from druid.table where SCALAR_IN_ARRAY(city, ?)
438439
```
439440

440-
sample java code using dynamic parameters is provided [here](../api-reference/sql-jdbc.md#dynamic-parameters).
441-
442441
## Reserved keywords
443442

444443
Druid SQL reserves certain keywords which are used in its query language. Apache Druid inherits all of the reserved keywords from [Apache Calcite](https://calcite.apache.org/docs/reference.html#keywords). In addition to these, the following reserved keywords are unique to Apache Druid:

0 commit comments

Comments
 (0)