mirror of https://github.com/apache/druid.git
Update doc for dynamic parameters supporting array (#16660)
Update dynamic parameter docs to provide how it can used to replace an Array
This commit is contained in:
parent
99313e9996
commit
1f6d2c41d2
|
@ -93,6 +93,10 @@ The request body takes the following properties:
|
||||||
{
|
{
|
||||||
"type": "VARCHAR",
|
"type": "VARCHAR",
|
||||||
"value": "bar"
|
"value": "bar"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ARRAY",
|
||||||
|
"value": [-25.7, null, 36.85]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
|
@ -121,6 +121,26 @@ statement.setString(2, "def");
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Sample code where dynamic parameters replace arrays using STRING_TO_ARRAY:
|
||||||
|
```java
|
||||||
|
PreparedStatement statement = connection.prepareStatement("select l1 from numfoo where SCALAR_IN_ARRAY(l1, STRING_TO_ARRAY(CAST(? as varchar),','))");
|
||||||
|
List<Integer> li = ImmutableList.of(0, 7);
|
||||||
|
String sqlArg = Joiner.on(",").join(li);
|
||||||
|
statement.setString(1, sqlArg);
|
||||||
|
statement.executeQuery();
|
||||||
|
```
|
||||||
|
|
||||||
|
Sample code using native array:
|
||||||
|
```java
|
||||||
|
PreparedStatement statement = connection.prepareStatement("select l1 from numfoo where SCALAR_IN_ARRAY(l1, ?)");
|
||||||
|
Iterable<Object> list = ImmutableList.of(0, 7);
|
||||||
|
ArrayFactoryImpl arrayFactoryImpl = new ArrayFactoryImpl(TimeZone.getDefault());
|
||||||
|
AvaticaType type = ColumnMetaData.scalar(Types.INTEGER, SqlType.INTEGER.name(), Rep.INTEGER);
|
||||||
|
Array array = arrayFactoryImpl.createArray(type, list);
|
||||||
|
statement.setArray(1, array);
|
||||||
|
statement.executeQuery();
|
||||||
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
<!-- docs/tutorial-jdbc.md redirects here -->
|
<!-- docs/tutorial-jdbc.md redirects here -->
|
||||||
|
|
|
@ -406,6 +406,20 @@ SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', ?, '%')
|
||||||
|
|
||||||
To solve this issue, explicitly provide the type of the dynamic parameter using the `CAST` keyword. Consider the fix for the preceding example:
|
To solve this issue, explicitly provide the type of the dynamic parameter using the `CAST` keyword. Consider the fix for the preceding example:
|
||||||
|
|
||||||
```
|
```sql
|
||||||
SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%')
|
SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT arrayColumn from druid.table where ARRAY_CONTAINS(?, arrayColumn)
|
||||||
|
```
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT count(city) from druid.table where SCALAR_IN_ARRAY(city, ?)
|
||||||
|
```
|
||||||
|
|
||||||
|
sample java code using dynamic parameters is provided [here](../api-reference/sql-jdbc.md#dynamic-parameters).
|
||||||
|
|
Loading…
Reference in New Issue