gianm commented on a change in pull request #9893:
URL: https://github.com/apache/druid/pull/9893#discussion_r428782087



##########
File path: 
sql/src/main/java/org/apache/druid/sql/calcite/expression/OperatorConversions.java
##########
@@ -430,36 +434,64 @@ public void inferOperandTypes(
 
   /**
    * Operand type checker that is used in 'simple' situations: there are a 
particular number of operands, with
-   * particular types, some of which may be optional or nullable.
+   * particular types, some of which may be optional or nullable, and some of 
which may be required to be literals.
    */
   private static class DefaultOperandTypeChecker implements 
SqlOperandTypeChecker
   {
     private final List<SqlTypeFamily> operandTypes;
     private final int requiredOperands;
     private final IntSet nullableOperands;
+    private final IntSet literalOperands;
 
     DefaultOperandTypeChecker(
         final List<SqlTypeFamily> operandTypes,
         final int requiredOperands,
-        final IntSet nullableOperands
+        final IntSet nullableOperands,
+        @Nullable final int[] literalOperands
     )
     {
       Preconditions.checkArgument(requiredOperands <= operandTypes.size() && 
requiredOperands >= 0);
       this.operandTypes = Preconditions.checkNotNull(operandTypes, 
"operandTypes");
       this.requiredOperands = requiredOperands;
       this.nullableOperands = Preconditions.checkNotNull(nullableOperands, 
"nullableOperands");
+
+      if (literalOperands == null) {
+        this.literalOperands = IntSets.EMPTY_SET;
+      } else {
+        this.literalOperands = new IntArraySet();
+        Arrays.stream(literalOperands).forEach(this.literalOperands::add);
+      }
     }
 
     @Override
     public boolean checkOperandTypes(SqlCallBinding callBinding, boolean 
throwOnFailure)
     {
-      if (operandTypes.size() != callBinding.getOperandCount()) {
-        // Just like FamilyOperandTypeChecker: assume this is an inapplicable 
sub-rule of a composite rule; don't throw
-        return false;
-      }
-
       for (int i = 0; i < callBinding.operands().size(); i++) {
         final SqlNode operand = callBinding.operands().get(i);
+
+        if (literalOperands.contains(i)) {
+          // Verify that 'operand' is a literal.
+          if (!SqlUtil.isLiteral(operand)) {
+            return throwOrReturn(
+                throwOnFailure,
+                callBinding,
+                cb -> cb.getValidator()
+                        .newValidationError(
+                            operand,
+                            
Static.RESOURCE.argumentMustBeLiteral(callBinding.getOperator().getName())
+                        )
+            );
+          }
+
+          if (!nullableOperands.contains(i) && SqlUtil.isNullLiteral(operand, 
true)) {

Review comment:
       Sure, I think this makes sense. I changed it.




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

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



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

Reply via email to