Dwrite commented on code in PR #5232:
URL: https://github.com/apache/calcite/pull/5232#discussion_r3940834791


##########
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##########
@@ -1499,6 +1501,78 @@ private 
RecordTypeWithOneFieldChecker(Predicate<SqlTypeName> predicate) {
       return !validationError;
     }
   }
+  /**
+   * Wraps a {@link SqlSingleOperandTypeChecker}, overriding only its
+   * {@link SqlOperandTypeChecker#getAllowedSignatures}. Needed because
+   * {@link CompositeOperandTypeChecker#withGenerator} always returns a plain
+   * {@link CompositeOperandTypeChecker}, which loses single-operand checking
+   * (see CALCITE-7749).
+   */
+  private static SqlSingleOperandTypeChecker withSignatureGenerator(
+      SqlSingleOperandTypeChecker checker,
+      BiFunction<SqlOperator, String, String> signatureGenerator) {
+    return new SqlSingleOperandTypeChecker() {
+      @Override public boolean checkSingleOperandType(SqlCallBinding 
callBinding,
+          SqlNode operand, int iFormalOperand, boolean throwOnFailure) {
+        // STRING_SAME_SAME-style checkers evaluate family membership AND
+        // cross-operand comparability together; there's no meaningful way to
+        // validate a single operand in isolation, so fall back to the full
+        // multi-operand check.
+        return checker.checkOperandTypes(callBinding, throwOnFailure);
+      }
+
+      @Override public boolean checkOperandTypes(SqlCallBinding callBinding,
+          boolean throwOnFailure) {
+        // Explicitly override rather than relying on the interface default
+        // (which would route through checkSingleOperandType(operand(0), 0)
+        // and only ever check the first operand).
+        return checker.checkOperandTypes(callBinding, throwOnFailure);
+      }
+
+      @Override public SqlOperandCountRange getOperandCountRange() {
+        return checker.getOperandCountRange();
+      }
+
+      @Override public boolean isOptional(int i) {
+        return checker.isOptional(i);
+      }
+
+      @Override public Consistency getConsistency() {
+        return checker.getConsistency();
+      }
+
+      @Override public String getAllowedSignatures(SqlOperator op, String 
opName) {
+        return signatureGenerator.apply(op, opName);
+      }
+    };
+  }
+
+  /**
+   * Builds a signature generator for STRING_SAME_SAME-style checkers, which

Review Comment:
   Address review feedback: make signature generator sub-family agnostic
   
   Previously stringSameSameSignatureGenerator hardcoded SqlTypeFamily.CHARACTER
   and SqlTypeFamily.BINARY inside its loop body, even though the method already
   took a variadic SqlTypeFamily... parameter for trailing families. This made
   the generator STRING-specific by construction rather than by the caller's
   input.
   
   Renamed to sameSubFamilySignatureGenerator and changed it to accept the
   candidate sub-families as a List<SqlTypeFamily> parameter instead. The
   CHARACTER/BINARY knowledge now lives at the call site as a
   STRING_SUB_FAMILIES constant in OperandTypes, keeping the generator itself
   a general-purpose "one signature per given sub-family" utility.
   
   Also trimmed the Javadoc on both withSignatureGenerator and
   sameSubFamilySignatureGenerator to be more concise.
   
   No behavioral change — STRING_SAME_SAME, STRING_SAME_SAME_SAME, and
   STRING_SAME_SAME_INTEGER produce the same messages as before.



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

Reply via email to