From 668197431b638290388a8757808e578d9763732d Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Wed, 26 Jun 2024 16:26:54 +0530 Subject: [PATCH 01/11] update dynamic parameters doc --- docs/querying/sql.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index 25de2adec421..9250d3e1e2e4 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -409,3 +409,27 @@ To solve this issue, explicitly provide the type of the dynamic parameter using ``` SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%') ``` + +With the support of dynamic parameters being extended to arrays, an array with a huge number of entries can be +programatically supplied through a parameter. + +for example +``` +{ + "query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(?, doubleArrayColumn)", + "Parameters":[ + {"type":"ARRAY", "value":[-25.7, null, 36.85]} + ] +} +``` + +Also, an IN filter being supplied with a lot of values, can be replaced by a dynamic parameter passed inside [SCALAR_IN_ARRAY](sql-array-functions.md) +``` +{ + "query": "SELECT count(city) from druid.table where SCALAR_IN_ARRAY(city, ?)", + "Parameters":[ + {"type":"ARRAY", "value":["Vienna", "Seoul", "San Francisco"]} + ] +} +``` + From 3fa0ec49a67f6ae6767d699d27243c693718eda9 Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Wed, 26 Jun 2024 17:16:25 +0530 Subject: [PATCH 02/11] dix checkj --- docs/querying/sql.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index 9250d3e1e2e4..72c984c803cf 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -410,8 +410,8 @@ To solve this issue, explicitly provide the type of the dynamic parameter using SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%') ``` -With the support of dynamic parameters being extended to arrays, an array with a huge number of entries can be -programatically supplied through a parameter. +With the support of dynamic parameters being extended to arrays, an array with a huge number of entries can be +programmatically supplied through a parameter. for example ``` From 1b9b85c27d6c3e4d80a035b7cab5f9e98e928fce Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Thu, 27 Jun 2024 06:57:03 +0530 Subject: [PATCH 03/11] review comments --- docs/querying/sql.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index 72c984c803cf..420a68da06c3 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -410,11 +410,11 @@ To solve this issue, explicitly provide the type of the dynamic parameter using SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%') ``` -With the support of dynamic parameters being extended to arrays, an array with a huge number of entries can be +With the support of dynamic parameters extended to arrays, an array with a huge number of entries can be programmatically supplied through a parameter. for example -``` +```json { "query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(?, doubleArrayColumn)", "Parameters":[ @@ -424,7 +424,7 @@ for example ``` Also, an IN filter being supplied with a lot of values, can be replaced by a dynamic parameter passed inside [SCALAR_IN_ARRAY](sql-array-functions.md) -``` +```json { "query": "SELECT count(city) from druid.table where SCALAR_IN_ARRAY(city, ?)", "Parameters":[ From 461449db6cb9f80b34fd7705117cf43fdf844ac1 Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Thu, 27 Jun 2024 12:00:00 +0530 Subject: [PATCH 04/11] comments --- docs/querying/sql.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index 420a68da06c3..bad17e20cac8 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -410,10 +410,9 @@ To solve this issue, explicitly provide the type of the dynamic parameter using SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%') ``` -With the support of dynamic parameters extended to arrays, an array with a huge number of entries can be -programmatically supplied through a parameter. +Arrays can also be passed as dynamic parameters. -for example +for example: ```json { "query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(?, doubleArrayColumn)", From 38e230f89c52bcdfac4f539cb3a20d5048bd49c9 Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Thu, 27 Jun 2024 19:47:58 +0530 Subject: [PATCH 05/11] comments --- docs/querying/sql.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index bad17e20cac8..ed7745d1a28a 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -416,17 +416,17 @@ for example: ```json { "query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(?, doubleArrayColumn)", - "Parameters":[ + "parameters":[ {"type":"ARRAY", "value":[-25.7, null, 36.85]} ] } ``` -Also, an IN filter being supplied with a lot of values, can be replaced by a dynamic parameter passed inside [SCALAR_IN_ARRAY](sql-array-functions.md) +Also, 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) ```json { "query": "SELECT count(city) from druid.table where SCALAR_IN_ARRAY(city, ?)", - "Parameters":[ + "parameters":[ {"type":"ARRAY", "value":["Vienna", "Seoul", "San Francisco"]} ] } From 60067f1397ab0b5dff4596e944036aefca2915a1 Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Fri, 5 Jul 2024 11:55:30 +0530 Subject: [PATCH 06/11] rephrase --- docs/querying/sql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index ed7745d1a28a..c1474ee620ac 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -410,7 +410,7 @@ To solve this issue, explicitly provide the type of the dynamic parameter using SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%') ``` -Arrays can also be passed as dynamic parameters. +Dynamic parameters can also replace arrays, reducing the parsing time. for example: ```json From 2f88c3d24b26c170f35dcbdfa36ab2bf4b6c31b8 Mon Sep 17 00:00:00 2001 From: Benedict Jin Date: Mon, 8 Jul 2024 15:44:07 +0800 Subject: [PATCH 07/11] Update docs/querying/sql.md --- docs/querying/sql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index c1474ee620ac..38b05e176514 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -416,7 +416,7 @@ for example: ```json { "query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(?, doubleArrayColumn)", - "parameters":[ + "parameters": [ {"type":"ARRAY", "value":[-25.7, null, 36.85]} ] } From 532163218997537abf4afde3d9743bc792811edc Mon Sep 17 00:00:00 2001 From: Benedict Jin Date: Mon, 8 Jul 2024 15:44:24 +0800 Subject: [PATCH 08/11] Update docs/querying/sql.md --- docs/querying/sql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index 38b05e176514..c371ef167d0d 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -426,7 +426,7 @@ Also, an IN filter being supplied with a lot of values, can be replaced by a dyn ```json { "query": "SELECT count(city) from druid.table where SCALAR_IN_ARRAY(city, ?)", - "parameters":[ + "parameters": [ {"type":"ARRAY", "value":["Vienna", "Seoul", "San Francisco"]} ] } From 0956b85e91764f924c10c68447b7d5b1d72c9120 Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Tue, 6 Aug 2024 13:40:22 +0530 Subject: [PATCH 09/11] link to api-reference --- docs/api-reference/sql-api.md | 4 ++++ docs/querying/sql.md | 26 ++++++++------------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/docs/api-reference/sql-api.md b/docs/api-reference/sql-api.md index e1fb53bc6eba..3a6234256188 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/querying/sql.md b/docs/querying/sql.md index c1474ee620ac..dcb73867232c 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -406,29 +406,19 @@ 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 also replace arrays, reducing the parsing time. +Dynamic parameters can even replace arrays, reducing the parsing time. Refer to parameters in [api request-body](../api-reference/sql-api.md#request-body) for usage. -for example: -```json -{ - "query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(?, doubleArrayColumn)", - "parameters":[ - {"type":"ARRAY", "value":[-25.7, null, 36.85]} - ] -} +```sql +SELECT arrayColumn from druid.table where ARRAY_CONTAINS(?, arrayColumn) ``` -Also, 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) -```json -{ - "query": "SELECT count(city) from druid.table where SCALAR_IN_ARRAY(city, ?)", - "parameters":[ - {"type":"ARRAY", "value":["Vienna", "Seoul", "San Francisco"]} - ] -} +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, ?) ``` From c8d4a73331f3b891808541f29ebfcf6d84e5b298 Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Tue, 6 Aug 2024 15:18:18 +0530 Subject: [PATCH 10/11] sample java code --- docs/api-reference/sql-jdbc.md | 20 ++++++++++++++++++++ docs/querying/sql.md | 1 + 2 files changed, 21 insertions(+) diff --git a/docs/api-reference/sql-jdbc.md b/docs/api-reference/sql-jdbc.md index 8223e764ed49..affe9ea738b5 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 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 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 diff --git a/docs/querying/sql.md b/docs/querying/sql.md index dcb73867232c..21349163b089 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -422,3 +422,4 @@ With this, an IN filter being supplied with a lot of values, can be replaced by 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). From da735ed4a9069e478d24fab828cbe34a8946e3a8 Mon Sep 17 00:00:00 2001 From: sreemanamala Date: Tue, 6 Aug 2024 15:27:29 +0530 Subject: [PATCH 11/11] checks --- docs/querying/sql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/querying/sql.md b/docs/querying/sql.md index 21349163b089..056ea9119b62 100644 --- a/docs/querying/sql.md +++ b/docs/querying/sql.md @@ -410,7 +410,7 @@ To solve this issue, explicitly provide the type of the dynamic parameter using SELECT * FROM druid.foo WHERE dim1 like CONCAT('%', CAST (? AS VARCHAR), '%') ``` -Dynamic parameters can even replace arrays, reducing the parsing time. Refer to parameters in [api request-body](../api-reference/sql-api.md#request-body) for usage. +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)