You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "LakshSingla (via GitHub)" <gi...@apache.org> on 2023/10/30 22:50:16 UTC

[PR] Allow casted literal values in SQL functions accepting literals (druid)

LakshSingla opened a new pull request, #15282:
URL: https://github.com/apache/druid/pull/15282

   ### Description
   
   For SQL functions accepting literals, casting might be allowed or disallowed, depending on whether the `OperandTypes.LITERAL` checker is used. Using it disallows casted literals like - `CAST(100 AS INTEGER`.
   While this is acceptable, the issue arises due to Calcite upgrade, where the new JDBC client can't allow wildcards without an explicit cast. Therefore for a function with a signature like `FUNC(column, literal)`, we can't do the following in JDBC.
   ```sql
   SELECT FUNC(column, literal) FROM foo
   ```
   Instead, we'd have to work around it using
   ```sql
   SELECT FUNC(column, CAST(literal AS TYPE)) FROM foo
   ```
   This PR allows cast in such functions by modifying the signature to not rely on `OperandTypes.LITERAL`   
   
   Remaining work:
   1. Mark the `OperandTypes.LITERAL` in forbidden-apis. 
   2. Merge DefaultOperandTypeChecker & BasicOperandTypeChecker
   
   
   #### Release note
   To be added
   
   <hr>
   
   This PR has:
   
   - [ ] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [ ] 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.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1378195677


##########
extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestGenerateSketchSqlAggregator.java:
##########
@@ -145,14 +145,19 @@ private static class TDigestGenerateSketchSqlAggFunction extends SqlAggFunction
           null,
           OperandTypes.or(
               OperandTypes.ANY,
-              OperandTypes.and(
-                  OperandTypes.sequence(SIGNATURE_WITH_COMPRESSION, OperandTypes.ANY, OperandTypes.LITERAL),
-                  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.NUMERIC)
-              )
+              // Validation for signatures like 'TDIGEST_GENERATE_SKETCH(column, compression)'

Review Comment:
   Resolved! Thanks for the 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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 merged PR #15282:
URL: https://github.com/apache/druid/pull/15282


-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377365653


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   * There's an `APPROX_COUNT_DISTINCT_DS_HLL` that takes 3 parameters, out of which the first one is required and the rest are optional.
   * There's `BLOOM_FILTER` that takes 2 parameters and both are required
   * And then there's `APPROX_QUANTILE_FIXED_BUCKETS` which takes in 6 parameters out of which first 5 are required.



-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377561193


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   ah yes. Now I get it. thanks for explaining the flow 😄 



##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   ah yes. Now I get it. thanks for explaining the flow 😄 



-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377365653


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   * There's an `APPROX_COUNT_DISTINCT_DS_HLL` that takes 3 parameters, out of which the first one is required and the rest two are optional.
   * There's `BLOOM_FILTER` that takes 2 parameters and both are required
   * And then there's `APPROX_QUANTILE_FIXED_BUCKETS` which takes in 6 parameters out of which first 5 are required.



-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "gianm (via GitHub)" <gi...@apache.org>.
gianm commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377846129


##########
extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestGenerateSketchSqlAggregator.java:
##########
@@ -145,14 +145,19 @@ private static class TDigestGenerateSketchSqlAggFunction extends SqlAggFunction
           null,
           OperandTypes.or(
               OperandTypes.ANY,
-              OperandTypes.and(
-                  OperandTypes.sequence(SIGNATURE_WITH_COMPRESSION, OperandTypes.ANY, OperandTypes.LITERAL),
-                  OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.NUMERIC)
-              )
+              // Validation for signatures like 'TDIGEST_GENERATE_SKETCH(column, compression)'

Review Comment:
   There's no need to have the `OperandTypes.or` anymore. Just use the default checker with `requiredOperandCount(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: 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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377289443


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   this doesn't seem right. is there a test case to verify signature when there are multiple required operands? 



##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchListArgBaseOperatorConversion.java:
##########
@@ -144,7 +143,7 @@ public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFail
 
         // Verify that 'operand' is a literal number.
         if (!SqlUtil.isLiteral(operand)) {

Review Comment:
   doesn't this need to allow cast? 



-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377359977


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   Hmm, git diff shows that I moved `BasicOperandTypeChecker` -> `DefaultOperandTypeChecker`. However `DefaultOperandTypeChecker` was already present in `OperatorConversions` that I pulled out.
   
   I think it creates a signature like:
   ```
   'functionName(requiredOperand1, requiredOperand2, [optionalOperand1, [optionalOperand2]])'
   ```
   
   1. We append `'functionName(`
   2. Loop begins
   3. For each operand, if it's not the first operand, we append `, `
   4. For each operand, if its an optional operand, we append `[`. At the end of the loop, we'd have open square brackets equal to the number of the optional operands
   5. For each operand, we append the operand name
   6. Loop ends
   7. For the total number of optional operands, we append `]` at the end, therefore closing them out.



-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377365653


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   There's an `APPROX_COUNT_DISTINCT_DS_HLL` that takes 3 parameters, out of which the first one is required and the rest are optional.
   There's `BLOOM_FILTER` that takes 2 parameters and both are required
   And then there's `APPROX_QUANTILE_FIXED_BUCKETS` which takes in 6 parameters out of which first 5 are required.



-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377359977


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   Hmm, git diff shows that I moved `BasicOperandTypeChecker` -> `DefaultOperandTypeChecker`. However `DefaultOperandTypeChecker` was already present in `OperatorConversions` that I pulled out.
   
   I think it creates a signature like:
   ```
   'functionName(requiredOperand1, requiredOperand2, [optionalOperand1, [optionalOperand2]])'
   ```
   
   1. We append `'functionName(`
   2. Loop begins
   3. For each operand, if it's not the first operand, we append `, `
   4. For each operand, if its an optional operand, we append `[`. At the end of the loop, we'd have open square brackets equal to the number of the optional operands
   5. For each operand, we append the operand name
   6. Loop ends
   7. For the total number of optional operands, we append `]` at the end, therefore closing them out.
   8. We append `)'`



-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1377355181


##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchListArgBaseOperatorConversion.java:
##########
@@ -144,7 +143,7 @@ public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFail
 
         // Verify that 'operand' is a literal number.
         if (!SqlUtil.isLiteral(operand)) {

Review Comment:
   Good catch, it does. I modified the call to allow casts and added test for the same 



##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/DefaultOperandTypeChecker.java:
##########
@@ -149,7 +147,25 @@ public SqlOperandCountRange getOperandCountRange()
   @Override
   public String getAllowedSignatures(SqlOperator op, String opName)
   {
-    return SqlUtil.getAliasedSignature(op, opName, operandTypes);
+    final List<?> operands = !operandNames.isEmpty() ? operandNames : operandTypes;
+    final StringBuilder ret = new StringBuilder();
+    ret.append("'");
+    ret.append(opName);
+    ret.append("(");
+    for (int i = 0; i < operands.size(); i++) {
+      if (i > 0) {
+        ret.append(", ");
+      }
+      if (i >= requiredOperands) {
+        ret.append("[");
+      }
+      ret.append("<").append(operands.get(i)).append(">");
+    }
+    for (int i = requiredOperands; i < operands.size(); i++) {
+      ret.append("]");
+    }

Review Comment:
   Hmm, git diff shows that I moved `BasicOperandTypeChecker` -> `DefaultOperandTypeChecker`. However `DefaultOperandTypeChecker` was already present in `OperatorConversions` that I pulled out.
   
   I think it creates a signature like:
   ```
   functionName(requiredOperand1, requiredOperand2, [optionalOperand1, [optionalOperand2]])
   ```



-- 
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


Re: [PR] Allow casted literal values in SQL functions accepting literals (druid)

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #15282:
URL: https://github.com/apache/druid/pull/15282#discussion_r1376900752


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/OperatorConversions.java:
##########
@@ -554,37 +543,26 @@
     @SuppressWarnings("unchecked")
     public T build()
     {
-      final IntSet nullableOperands = buildNullableOperands();
       return (T) new SqlFunction(
           name,
           kind,
           Preconditions.checkNotNull(returnTypeInference, "returnTypeInference"),
-          buildOperandTypeInference(nullableOperands),
-          buildOperandTypeChecker(nullableOperands),
+          buildOperandTypeInference(),
+          buildOperandTypeChecker(),
           functionCategory
       );
     }
 
-    protected IntSet buildNullableOperands()
-    {
-      // Create "nullableOperands" set including all optional arguments.
-      final IntSet nullableOperands = new IntArraySet();
-      if (requiredOperandCount != null) {
-        IntStream.range(requiredOperandCount, operandTypes.size()).forEach(nullableOperands::add);
-      }
-      return nullableOperands;
-    }
-
-    protected SqlOperandTypeChecker buildOperandTypeChecker(final IntSet nullableOperands)
+    protected SqlOperandTypeChecker buildOperandTypeChecker()
     {
       if (operandTypeChecker == null) {
-        return new DefaultOperandTypeChecker(
-            operandNames,
-            operandTypes,
-            requiredOperandCount == null ? operandTypes.size() : requiredOperandCount,
-            nullableOperands,
-            literalOperands
-        );
+        return DefaultOperandTypeChecker
+            .builder()
+            .operandNames(operandNames)
+            .operandTypes(operandTypes)
+            .requiredOperandCount(requiredOperandCount == null ? operandTypes.size() : requiredOperandCount)

Review Comment:
   ## Dereferenced variable may be null
   
   Variable [operandTypes](1) may be null at this access as suggested by [this](2) null guard.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5945)



-- 
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