private void verifyWindowFunctionExpressions ( ) { // Check for windowed expressions. if ( m_windowFunctionExpressions . size ( ) > 0 ) { if ( m_windowFunctionExpressions . size ( ) > 1 ) { throw new PlanningErrorException ( "Only one windowed function call may appear in a selection list." ) ; } if ( m_hasAggregateExpression ) { throw new PlanningErrorException ( "Use of window functions (in an OVER clause) isn't supported with other aggregate functions on the SELECT list." ) ; } if ( m_windowFunctionExpressions . get ( 0 ) . hasSubqueryArgs ( ) ) { throw new PlanningErrorException ( "Window function calls with subquery expression arguments are not allowed." ) ; } WindowFunctionExpression windowFunctionExpression = m_windowFunctionExpressions . get ( 0 ) ; List < AbstractExpression > orderByExpressions = windowFunctionExpression . getOrderByExpressions ( ) ; ExpressionType exprType = windowFunctionExpression . getExpressionType ( ) ; String aggName = exprType . symbol ( ) . toUpperCase ( ) ; switch ( exprType ) { case AGGREGATE_WINDOWED_RANK : case AGGREGATE_WINDOWED_DENSE_RANK : if ( orderByExpressions . size ( ) == 0 ) { throw new PlanningErrorException ( "Windowed " + aggName + " function call expressions require an ORDER BY specification." ) ; } VoltType valType = orderByExpressions . get ( 0 ) . getValueType ( ) ; assert ( valType != null ) ; if ( ! valType . isAnyIntegerType ( ) && ( valType != VoltType . TIMESTAMP ) ) { throw new PlanningErrorException ( "Windowed function call expressions can have only integer or TIMESTAMP value types in the ORDER BY expression of their window." ) ; } break ; case AGGREGATE_WINDOWED_COUNT : if ( windowFunctionExpression . getAggregateArguments ( ) . size ( ) > 1 ) { throw new PlanningErrorException ( String . format ( "Windowed COUNT must have either exactly one argument or else a star for an argument" ) ) ; } // Any type is ok, so we won't inspect the type. break ; case AGGREGATE_WINDOWED_MAX : case AGGREGATE_WINDOWED_MIN : if ( windowFunctionExpression . getAggregateArguments ( ) . size ( ) != 1 ) { throw new PlanningErrorException ( String . format ( "Windowed %s must have exactly one argument" , aggName ) ) ; } // Any type is ok, so we won't inspect the type. break ; case AGGREGATE_WINDOWED_SUM : if ( windowFunctionExpression . getAggregateArguments ( ) . size ( ) != 1 ) { throw new PlanningErrorException ( String . format ( "Windowed SUM must have exactly one numeric argument" ) ) ; } AbstractExpression arg = windowFunctionExpression . getAggregateArguments ( ) . get ( 0 ) ; VoltType vt = arg . getValueType ( ) ; assert ( vt != null ) ; if ( ! vt . isNumber ( ) ) { throw new PlanningErrorException ( "Windowed SUM must have exactly one numeric argument" ) ; } break ; case AGGREGATE_WINDOWED_ROW_NUMBER : break ; default : { String opName = ( exprType == null ) ? "NULL" : exprType . symbol ( ) ; throw new PlanningErrorException ( "Unknown windowed aggregate function type: " + opName ) ; } } } }
Verify the validity of the windowed expressions .