kishoreg commented on a change in pull request #4602: First pass of GROUP BY with ORDER BY support URL: https://github.com/apache/incubator-pinot/pull/4602#discussion_r324411567
########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/table/ConcurrentIndexedTable.java ########## @@ -101,31 +108,51 @@ public int size() { @Override public Iterator<Record> iterator() { + if (_sort && CollectionUtils.isNotEmpty(_orderBy)) { + List<Record> sortedList = new ArrayList<>(_lookupMap.values()); + sortedList.sort(_orderByComparator); + return sortedList.iterator(); + } return _lookupMap.values().iterator(); } private void resize(int trimToSize) { if (_lookupMap.size() > trimToSize) { - // make min heap of elements to evict - int heapSize = _lookupMap.size() - trimToSize; - PriorityQueue<Record> minHeap = new PriorityQueue<>(heapSize, _minHeapComparator); - - for (Record record : _lookupMap.values()) { - if (minHeap.size() < heapSize) { - minHeap.offer(record); - } else { - Record peek = minHeap.peek(); - if (minHeap.comparator().compare(record, peek) < 0) { - minHeap.poll(); + if (CollectionUtils.isNotEmpty(_orderBy)) { + // drop bottom + + // make min heap of elements to evict + int heapSize = _lookupMap.size() - trimToSize; + PriorityQueue<Record> minHeap = new PriorityQueue<>(heapSize, _minHeapComparator); + + for (Record record : _lookupMap.values()) { + if (minHeap.size() < heapSize) { minHeap.offer(record); + } else { + Record peek = minHeap.peek(); + if (minHeap.comparator().compare(record, peek) < 0) { + minHeap.poll(); + minHeap.offer(record); + } } } - } - for (Record evictRecord : minHeap) { - _lookupMap.remove(evictRecord.getKey()); + for (Record evictRecord : minHeap) { + _lookupMap.remove(evictRecord.getKey()); + } + } else { + // drop randomly + + int numRecordsToDrop = _lookupMap.size() - trimToSize; Review comment: its better to not add new keys if there is no orderby rt ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org