1111import org .opensearch .sql .calcite .utils .OpenSearchTypeFactory ;
1212import org .opensearch .sql .exception .SemanticCheckException ;
1313
14- /**
15- * Represents a validated field that supports binning operations. The existence of this class
16- * guarantees that validation has been run - the field is either numeric or time-based.
17- *
18- * <p>This design encodes validation in the type system, preventing downstream code from forgetting
19- * to validate or running validation multiple times.
20- */
14+ /** Represents a field that supports binning operations. */
2115@ Getter
2216public class BinnableField {
2317 private final RexNode fieldExpr ;
@@ -27,13 +21,12 @@ public class BinnableField {
2721 private final boolean isNumeric ;
2822
2923 /**
30- * Creates a validated BinnableField. Throws SemanticCheckException if the field is neither
31- * numeric nor time-based.
24+ * Creates a BinnableField. Validates that the field type is compatible with binning operations.
3225 *
3326 * @param fieldExpr The Rex expression for the field
3427 * @param fieldType The relational data type of the field
3528 * @param fieldName The name of the field (for error messages)
36- * @throws SemanticCheckException if the field is neither numeric nor time-based
29+ * @throws SemanticCheckException if the field type is not supported for binning
3730 */
3831 public BinnableField (RexNode fieldExpr , RelDataType fieldType , String fieldName ) {
3932 this .fieldExpr = fieldExpr ;
@@ -43,13 +36,10 @@ public BinnableField(RexNode fieldExpr, RelDataType fieldType, String fieldName)
4336 this .isTimeBased = OpenSearchTypeFactory .isTimeBasedType (fieldType );
4437 this .isNumeric = OpenSearchTypeFactory .isNumericType (fieldType );
4538
46- // Validation: field must be either numeric or time-based
39+ // Reject truly unsupported types (e.g., BOOLEAN, ARRAY, MAP)
4740 if (!isNumeric && !isTimeBased ) {
4841 throw new SemanticCheckException (
49- String .format (
50- "Cannot apply binning: field '%s' is non-numeric and not time-related, expected"
51- + " numeric or time-related type" ,
52- fieldName ));
42+ String .format ("Cannot apply binning to field '%s': unsupported type" , fieldName ));
5343 }
5444 }
5545
0 commit comments