This is an automated email from the ASF dual-hosted git repository.
abhishek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 1f6d2c41d29 Update doc for dynamic parameters supporting array (#16660)
1f6d2c41d29 is described below
commit 1f6d2c41d29662033c82c730ad8d0b18213ffe26
Author: Sree Charan Manamala <[email protected]>
AuthorDate: Wed Aug 7 12:33:37 2024 +0530
Update doc for dynamic parameters supporting array (#16660)
Update dynamic parameter docs to provide how it can used to replace an Array
---
docs/api-reference/sql-api.md | 4 ++++
docs/api-reference/sql-jdbc.md | 20 ++++++++++++++++++++
docs/querying/sql.md | 16 +++++++++++++++-
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/docs/api-reference/sql-api.md b/docs/api-reference/sql-api.md
index e1fb53bc6eb..3a623425618 100644
--- a/docs/api-reference/sql-api.md
+++ b/docs/api-reference/sql-api.md
@@ -93,6 +93,10 @@ The request body takes the following properties:
{
"type": "VARCHAR",
"value": "bar"
+ },
+ {
+ "type": "ARRAY",
+ "value": [-25.7, null, 36.85]
}
]
```
diff --git a/docs/api-reference/sql-jdbc.md b/docs/api-reference/sql-jdbc.md
index 8223e764ed4..affe9ea738b 100644
--- a/docs/api-reference/sql-jdbc.md
+++ b/docs/api-reference/sql-jdbc.md
@@ -121,6 +121,26 @@ statement.setString(2, "def");
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
<!-- docs/tutorial-jdbc.md redirects here -->
diff --git a/docs/querying/sql.md b/docs/querying/sql.md
index 25de2adec42..056ea9119b6 100644
--- a/docs/querying/sql.md
+++ b/docs/querying/sql.md
@@ -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:
-```
+```sql
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).
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]