Fix the memory issue for selection query with large limit
Fix the memory issue for selection query with large limit
@@ -404,12 +404,12 @@ public class SelectionOperatorUtils {
* Reduces a collection of {@link DataTable}s to selection rows for selection queries without <code>ORDER BY</code>.
* (Broker side)
*/
- public static List<Object[]> reduceWithoutOrdering(Collection<DataTable> dataTables, int selectionSize) {
- List<Object[]> rows = new ArrayList<>(selectionSize);
+ public static List<Object[]> reduceWithoutOrdering(Collection<DataTable> dataTables, int limit) {
+ List<Object[]> rows = new ArrayList<>(Math.min(limit, SelectionOperatorUtils.MAX_ROW_HOLDER_INITIAL_CAPACITY));
for (DataTable dataTable : dataTables) {
int numRows = dataTable.getNumberOfRows();
for (int rowId = 0; rowId < numRows; rowId++) {
- if (rows.size() < selectionSize) {
+ if (rows.size() < limit) {
rows.add(extractRowFromDataTable(dataTable, rowId));
} else {
return rows;
@@ -467,7 +467,8 @@ public class SelectionOperatorUtils {
* @param selectionColumns selection columns.
* @return {@link ResultTable} object results.
*/
- public static ResultTable renderResultTableWithoutOrdering(List<Object[]> rows, DataSchema dataSchema, List<String> selectionColumns) {
+ public static ResultTable renderResultTableWithoutOrdering(List<Object[]> rows, DataSchema dataSchema,
+ List<String> selectionColumns) {
int numRows = rows.size();
List<Object[]> resultRows = new ArrayList<>(numRows);
