You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/11/09 21:55:32 UTC

[GitHub] [druid] jihoonson opened a new pull request #11900: Fix NPE for SQL queries when a query parameter is missing in the mid

jihoonson opened a new pull request #11900:
URL: https://github.com/apache/druid/pull/11900


   ### Description
   
   NPE can be thrown when there is a query parameter missing in the mid. Here is a stack trace.
   
   ```
   Caused by: java.lang.NullPointerException
   	at org.apache.druid.sql.calcite.planner.SqlParameterizerShuttle.visit(SqlParameterizerShuttle.java:54)
   	at org.apache.druid.sql.calcite.planner.SqlParameterizerShuttle.visit(SqlParameterizerShuttle.java:39)
   	at org.apache.calcite.sql.SqlDynamicParam.accept(SqlDynamicParam.java:76)
   ```
   
   This PR adds a null check for parameters and returns a more user-friendly error message.
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   - [x] been self-reviewed.
   - [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [x] added integration tests.
   


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on a change in pull request #11900: Fix NPE for SQL queries when a query parameter is missing in the mid

Posted by GitBox <gi...@apache.org>.
jihoonson commented on a change in pull request #11900:
URL: https://github.com/apache/druid/pull/11900#discussion_r746175671



##########
File path: sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
##########
@@ -36,7 +36,10 @@
   public static List<TypedValue> getParameterList(List<SqlParameter> parameters)
   {
     return parameters.stream()
-                     .map(SqlParameter::getTypedValue)
+                     // null params are not good!
+                     // we pass them to the planner, so that it can generate a proper error message.
+                     // see SqlParameterizerShuttle and RelParameterizerShuttle.
+                     .map(p -> p == null ? null : p.getTypedValue())

Review comment:
       The intention was passing null parameters as they are so that `SqlParameterizerShuttle` and `RelParameterizerShuttle` can handle them properly. They will throw `InvalidArgumentException` at https://github.com/apache/druid/pull/11900/files#diff-ae4b6e9293a80177b076ab1a7d6235931eb95619dcc759ae40027543ef35f4e1R215 or https://github.com/apache/druid/pull/11900/files#diff-9ea07312c8d034ebe3c983a4690dd3cb79a2aa190610b11583cf37947f919de9R75. Do you think it's better to throw an exception here too? I thought it would be better to put error handling logic in one place. 




-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 commented on a change in pull request #11900: Fix NPE for SQL queries when a query parameter is missing in the mid

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on a change in pull request #11900:
URL: https://github.com/apache/druid/pull/11900#discussion_r746168196



##########
File path: sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
##########
@@ -36,7 +36,10 @@
   public static List<TypedValue> getParameterList(List<SqlParameter> parameters)
   {
     return parameters.stream()
-                     .map(SqlParameter::getTypedValue)
+                     // null params are not good!
+                     // we pass them to the planner, so that it can generate a proper error message.
+                     // see SqlParameterizerShuttle and RelParameterizerShuttle.
+                     .map(p -> p == null ? null : p.getTypedValue())

Review comment:
       Can we throw exception from here?




-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson merged pull request #11900: Fix NPE for SQL queries when a query parameter is missing in the mid

Posted by GitBox <gi...@apache.org>.
jihoonson merged pull request #11900:
URL: https://github.com/apache/druid/pull/11900


   


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on a change in pull request #11900: Fix NPE for SQL queries when a query parameter is missing in the mid

Posted by GitBox <gi...@apache.org>.
jihoonson commented on a change in pull request #11900:
URL: https://github.com/apache/druid/pull/11900#discussion_r746176337



##########
File path: sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
##########
@@ -36,7 +36,10 @@
   public static List<TypedValue> getParameterList(List<SqlParameter> parameters)
   {
     return parameters.stream()
-                     .map(SqlParameter::getTypedValue)
+                     // null params are not good!
+                     // we pass them to the planner, so that it can generate a proper error message.
+                     // see SqlParameterizerShuttle and RelParameterizerShuttle.
+                     .map(p -> p == null ? null : p.getTypedValue())

Review comment:
       Actually, parameters cannot be null in production code path when you use SQL over HTTP. This bug exists only for JDBC which doesn't use this method. This change was for easily mimicking the error case in unit tests. 




-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] kfaraz commented on a change in pull request #11900: Fix NPE for SQL queries when a query parameter is missing in the mid

Posted by GitBox <gi...@apache.org>.
kfaraz commented on a change in pull request #11900:
URL: https://github.com/apache/druid/pull/11900#discussion_r746246454



##########
File path: sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
##########
@@ -49,7 +52,7 @@
   @JsonCreator
   public SqlQuery(
       @JsonProperty("query") final String query,
-      @JsonProperty("resultFormat") final ResultFormat resultFormat,
+      @JsonProperty("resultFormat") final ResultFormat   resultFormat,

Review comment:
       Nit: extra space




-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on pull request #11900: Fix NPE for SQL queries when a query parameter is missing in the mid

Posted by GitBox <gi...@apache.org>.
jihoonson commented on pull request #11900:
URL: https://github.com/apache/druid/pull/11900#issuecomment-965600655


   @FrankChen021 @kfaraz @clintropolis thank you for your review!


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org