@@ -68,19 +68,25 @@ static ObjectNode buildLimit(int limit) {
68
68
return newOperation ("limit" , args -> args .add (limit ));
69
69
}
70
70
71
- static ObjectNode buildOrderBy (SortOrder sortOrder ) {
72
- final String direction = SortDirection .ASCENDING .equals (sortOrder .direction ()) ? "asc" : "desc" ;
73
- final String columnName = expressionToColumnName (sortOrder .expression ());
71
+ static ObjectNode buildOrderBy (SortOrder [] sortOrders ) {
74
72
return newOperation ("order-by" , args -> {
75
- ArrayNode orderByArgs = args .addObject ().put ("ns" , "op" ).put ("fn" , direction ).putArray ("args" );
76
- // This may be a bad hack to account for when the user does a groupBy/count/orderBy/limit, which does not
77
- // seem like the correct approach - the Spark ScanBuilder javadocs indicate that it should be limit/orderBy
78
- // instead. In the former scenario, we get "COUNT(*)" as the expression to order by, and we know that's not
79
- // the column name.
80
- if (logger .isDebugEnabled ()) {
81
- logger .debug ("Adjusting `COUNT(*)` column to be `count`" );
73
+ ArrayNode innerArgs = args .addArray ();
74
+ for (SortOrder sortOrder : sortOrders ) {
75
+ final String direction = SortDirection .ASCENDING .equals (sortOrder .direction ()) ? "asc" : "desc" ;
76
+ ArrayNode orderByArgs = innerArgs .addObject ().put ("ns" , "op" ).put ("fn" , direction ).putArray ("args" );
77
+ String columnName = expressionToColumnName (sortOrder .expression ());
78
+ // This may be a bad hack to account for when the user does a groupBy/count/orderBy/limit, which does not
79
+ // seem like the correct approach - the Spark ScanBuilder javadocs indicate that it should be limit/orderBy
80
+ // instead. In the former scenario, we get "COUNT(*)" as the expression to order by, and we know that's not
81
+ // the column name.
82
+ if ("COUNT(*)" .equals (columnName )) {
83
+ if (logger .isDebugEnabled ()) {
84
+ logger .debug ("Adjusting `COUNT(*)` column to be `count`" );
85
+ }
86
+ columnName = "count" ;
87
+ }
88
+ populateSchemaCol (orderByArgs .addObject (), columnName );
82
89
}
83
- populateSchemaCol (orderByArgs .addObject (), "COUNT(*)" .equals (columnName ) ? "count" : columnName );
84
90
});
85
91
}
86
92
0 commit comments