@@ -361,50 +361,6 @@ public TSDataType visitFunctionExpression(
361361 }
362362
363363 if (functionExpression .isBuiltInAggregationFunctionExpression ()) {
364- // Additional type check for multi-input aggregation functions
365- String funcName = functionExpression .getFunctionName ().toLowerCase ();
366- if (funcName .equals (SqlConstant .CORR )
367- || funcName .equals (SqlConstant .COVAR_POP )
368- || funcName .equals (SqlConstant .COVAR_SAMP )
369- || funcName .equals (SqlConstant .REGR_SLOPE )
370- || funcName .equals (SqlConstant .REGR_INTERCEPT )) {
371- // Check both input parameters are numeric or timestamp
372- if (inputExpressions .size () >= 1 ) {
373- TSDataType firstInputType = expressionTypes .get (NodeRef .of (inputExpressions .get (0 )));
374- if (firstInputType != null
375- && !firstInputType .isNumeric ()
376- && firstInputType != TSDataType .TIMESTAMP ) {
377- throw new SemanticException (
378- String .format (
379- "Aggregate functions [%s] only support numeric data types [INT32, INT64, FLOAT, DOUBLE, TIMESTAMP]" ,
380- functionExpression .getFunctionName ().toUpperCase ()));
381- }
382- }
383- if (inputExpressions .size () >= 2 ) {
384- TSDataType secondInputType = expressionTypes .get (NodeRef .of (inputExpressions .get (1 )));
385- if (secondInputType != null
386- && !secondInputType .isNumeric ()
387- && secondInputType != TSDataType .TIMESTAMP ) {
388- throw new SemanticException (
389- String .format (
390- "Aggregate functions [%s] only support numeric data types [INT32, INT64, FLOAT, DOUBLE, TIMESTAMP]" ,
391- functionExpression .getFunctionName ().toUpperCase ()));
392- }
393- }
394- }
395- if (funcName .equals (SqlConstant .SKEWNESS ) || funcName .equals (SqlConstant .KURTOSIS )) {
396- if (!inputExpressions .isEmpty ()) {
397- TSDataType firstInputType = expressionTypes .get (NodeRef .of (inputExpressions .get (0 )));
398- if (firstInputType != null
399- && !firstInputType .isNumeric ()
400- && firstInputType != TSDataType .TIMESTAMP ) {
401- throw new SemanticException (
402- String .format (
403- "Aggregate functions [%s] only support numeric data types [INT32, INT64, FLOAT, DOUBLE, TIMESTAMP]" ,
404- functionExpression .getFunctionName ().toUpperCase ()));
405- }
406- }
407- }
408364
409365 return setExpressionType (
410366 functionExpression ,
@@ -587,15 +543,20 @@ private TSDataType getInputExpressionTypeForAggregation(
587543 case SqlConstant .VARIANCE :
588544 case SqlConstant .VAR_POP :
589545 case SqlConstant .VAR_SAMP :
546+ case SqlConstant .SKEWNESS :
547+ case SqlConstant .KURTOSIS :
548+ case SqlConstant .MAX_BY :
549+ case SqlConstant .MIN_BY :
550+ return expressionTypes .get (NodeRef .of (inputExpressions .get (0 )));
590551 case SqlConstant .CORR :
591552 case SqlConstant .COVAR_POP :
592553 case SqlConstant .COVAR_SAMP :
593554 case SqlConstant .REGR_SLOPE :
594555 case SqlConstant .REGR_INTERCEPT :
595- case SqlConstant . SKEWNESS :
596- case SqlConstant . KURTOSIS :
597- case SqlConstant . MAX_BY :
598- case SqlConstant . MIN_BY :
556+ TypeInferenceUtils . verifyIsAggregationDataTypeMatchedForBothInputs (
557+ aggregateFunctionName ,
558+ expressionTypes . get ( NodeRef . of ( inputExpressions . get ( 0 ))),
559+ expressionTypes . get ( NodeRef . of ( inputExpressions . get ( 1 ))));
599560 return expressionTypes .get (NodeRef .of (inputExpressions .get (0 )));
600561 default :
601562 throw new IllegalArgumentException (
0 commit comments