@@ -19,7 +19,6 @@ public final class PostgresWindowFunctionGenerator {
1919 private static final List <String > WINDOW_FUNCTIONS = Arrays .asList ("row_number" , "rank" , "dense_rank" ,
2020 "percent_rank" , "cume_dist" , "ntile" , "lag" , "lead" , "first_value" , "last_value" , "nth_value" );
2121
22- // Private constructor to prevent instantiation
2322 private PostgresWindowFunctionGenerator () {
2423 throw new AssertionError ("Utility class should not be instantiated" );
2524 }
@@ -72,10 +71,15 @@ private static List<PostgresExpression> generateFunctionArguments(String functio
7271 private static WindowSpecification generateWindowSpecification (PostgresGlobalState globalState ,
7372 List <PostgresExpression > availableExpr ) {
7473 List <PostgresExpression > partitionBy = generatePartitionByClause (availableExpr );
75- List <PostgresOrderByTerm > orderBy = generateOrderByClause (availableExpr );
76- WindowFrame frame = generateWindowFrame (globalState );
74+ PostgresExpressionGenerator exprGen = new PostgresExpressionGenerator (globalState );
75+ List <PostgresExpression > orderBys = exprGen .generateOrderBys ();
76+ List <PostgresOrderByTerm > orderByTerms = new ArrayList <>();
77+ for (PostgresExpression expr : orderBys ) {
78+ orderByTerms .add (new PostgresOrderByTerm (expr , Randomly .getBoolean ()));
79+ }
7780
78- return new WindowSpecification (partitionBy , orderBy , frame );
81+ WindowFrame frame = generateWindowFrame (globalState );
82+ return new WindowSpecification (partitionBy , orderByTerms , frame );
7983 }
8084
8185 private static List <PostgresExpression > generatePartitionByClause (List <PostgresExpression > availableExpr ) {
@@ -89,17 +93,6 @@ private static List<PostgresExpression> generatePartitionByClause(List<PostgresE
8993 return partitionBy ;
9094 }
9195
92- private static List <PostgresOrderByTerm > generateOrderByClause (List <PostgresExpression > availableExpr ) {
93- List <PostgresOrderByTerm > orderBy = new ArrayList <>();
94- if (Randomly .getBooleanWithRatherLowProbability ()) {
95- int count = Randomly .smallNumber ();
96- for (int i = 0 ; i < count ; i ++) {
97- orderBy .add (new PostgresOrderByTerm (Randomly .fromList (availableExpr ), Randomly .getBoolean ()));
98- }
99- }
100- return orderBy ;
101- }
102-
10396 private static WindowFrame generateWindowFrame (PostgresGlobalState globalState ) {
10497 if (Randomly .getBooleanWithRatherLowProbability ()) {
10598 WindowFrame .FrameType frameType = Randomly .fromOptions (WindowFrame .FrameType .values ());
0 commit comments