kgyrtkirk commented on code in PR #16660:
URL: https://github.com/apache/druid/pull/16660#discussion_r1673549858


##########
docs/querying/sql.md:
##########
@@ -409,3 +409,26 @@ 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 also replace arrays, reducing the parsing time.
+
+for example:
+```json
+{
+    "query": "SELECT doubleArrayColumn from druid.table where 
ARRAY_CONTAINS(?, doubleArrayColumn)",
+    "parameters": [
+      {"type":"ARRAY", "value":[-25.7, null, 36.85]}
+    ]
+}
+```

Review Comment:
   I feel like this is `sql-api` specific so it shouldn't it be inside 
`../api-reference/sql-api.md` ?



##########
docs/querying/sql.md:
##########
@@ -409,3 +409,26 @@ 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 also replace arrays, reducing the parsing time.
+
+for example:
+```json
+{
+    "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-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"]}
+    ]
+}
+```

Review Comment:
   I've played with similar things for jdbc api earlier; it seemed a bit harder 
to use it from there
   should we include those in `sql-api.md`?
   
   ```java
   
   import com.google.common.base.Joiner;
   import com.google.common.collect.ImmutableList;
   import org.apache.calcite.avatica.ColumnMetaData;
   import org.apache.calcite.avatica.SqlType;
   import org.apache.calcite.avatica.ColumnMetaData.AvaticaType;
   import org.apache.calcite.avatica.ColumnMetaData.Rep;
   import org.apache.calcite.avatica.util.ArrayFactoryImpl;
   import org.junit.jupiter.api.Test;
   
   import java.sql.Array;
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Types;
   import java.util.List;
   import java.util.TimeZone;
   
   public class Asd
   {
     @Test
     public void scalarInArrayWithStringToArray() throws SQLException
     {
       String connectionURL = "druidtest:///";
       Connection connection = DriverManager.getConnection(connectionURL);
       PreparedStatement stmt = 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);
       stmt.setString(1, sqlArg);
       stmt.executeQuery();
       ResultSet rs = stmt.getResultSet();
       while (rs.next()) {
         System.out.println(rs.getObject(1));
       }
     }
   
     @Test
     public void scalarInArrayNativeArray() throws SQLException
     {
       String connectionURL = "druidtest:///";
       Connection connection = DriverManager.getConnection(connectionURL);
       PreparedStatement stmt = connection.prepareStatement("select l1 from 
numfoo where SCALAR_IN_ARRAY(l1, ?)");
       Iterable<Object> li = ImmutableList.of(0, 7);
       ArrayFactoryImpl a = new ArrayFactoryImpl(TimeZone.getDefault());
       org.apache.calcite.avatica.proto.Common.AvaticaType proto;
       AvaticaType type = ColumnMetaData.scalar(Types.INTEGER, 
SqlType.INTEGER.name(), Rep.INTEGER);
       Array arr = a.createArray(type, li);
       stmt.setArray(1, arr);
       stmt.executeQuery();
       ResultSet rs = stmt.getResultSet();
       while (rs.next()) {
         System.out.println(rs.getObject(1));
       }
     }
   }
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to