wuchong commented on code in PR #2323:
URL: https://github.com/apache/fluss/pull/2323#discussion_r2766828104


##########
fluss-common/src/main/java/org/apache/fluss/metadata/AggFunctionType.java:
##########
@@ -111,6 +117,60 @@ public void validateParameter(String parameterName, String 
parameterValue) {
         }
     }
 
+    /**
+     * Validates a data type for this aggregation function.
+     *
+     * @param fieldType the field data type
+     * @throws IllegalArgumentException if the data type is invalid
+     */
+    public void validateDataType(DataType fieldType) {
+        switch (this) {
+                // The bool_and and bool_or don't have specific DataFamily, 
validate them by
+                // dataType directly.
+            case BOOL_AND:
+            case BOOL_OR:
+                checkArgument(
+                        fieldType instanceof BooleanType,
+                        "Data type for %s column must be 'BooleanType' but was 
'%s'.",
+                        toString(),
+                        fieldType);
+                break;
+            default:
+                DataTypeFamily[] dataTypeFamilies = getSupportedDataFamilies();
+                checkArgument(
+                        fieldType.isAnyOf(dataTypeFamilies),
+                        "Data type for %s column must be part of %s but was 
'%s'.",
+                        toString(),
+                        Arrays.deepToString(dataTypeFamilies),
+                        fieldType);
+                break;
+        }
+    }
+
+    private DataTypeFamily[] getSupportedDataFamilies() {
+        switch (this) {
+            case SUM:
+            case PRODUCT:
+                return new DataTypeFamily[] {DataTypeFamily.NUMERIC};
+            case MAX:
+            case MIN:
+                return new DataTypeFamily[] {
+                    DataTypeFamily.CHARACTER_STRING, DataTypeFamily.NUMERIC, 
DataTypeFamily.DATETIME
+                };
+            case LAST_VALUE:
+            case LAST_VALUE_IGNORE_NULLS:
+            case FIRST_VALUE:
+            case FIRST_VALUE_IGNORE_NULLS:
+                return DataTypeFamily.values();
+            case LISTAGG:
+            case STRING_AGG:
+                return new DataTypeFamily[] {DataTypeFamily.CHARACTER_STRING};
+            default:

Review Comment:
   We can use data types directly here, so we don't need to introduce new data 
tyep family. 



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