@Test public void testSelectionOrderBy() { List<SegmentDataManager> segmentDataManagers = Arrays.asList( getSegmentDataManager(0L, 10L, 10), getSegmentDataManager(-5L, 5L, 15), getSegmentDataManager(15L, 50L, 30), getSegmentDataManager(5L, 15L, 20), getSegmentDataManager(20L, 30L, 5), getSegmentDataManager(null, null, 5), getSegmentDataManager(5L, 10L, 10), getSegmentDataManager(15L, 30L, 15)); ServerQueryRequest queryRequest = getQueryRequest("SELECT * FROM testTable ORDER BY testColumn LIMIT 5"); List<SegmentDataManager> result = _segmentPruner.prune(_tableDataManager, segmentDataManagers, queryRequest); assertEquals(result.size(), 3); assertSame(result.get(0), segmentDataManagers.get(5)); assertSame(result.get(1), segmentDataManagers.get(1)); assertSame(result.get(2), segmentDataManagers.get(0)); queryRequest = getQueryRequest("SELECT * FROM testTable ORDER BY testColumn LIMIT 15, 20"); result = _segmentPruner.prune(_tableDataManager, segmentDataManagers, queryRequest); assertEquals(result.size(), 5); assertSame(result.get(0), segmentDataManagers.get(5)); assertSame(result.get(1), segmentDataManagers.get(1)); assertTrue(result.get(2) == segmentDataManagers.get(0) || result.get(2) == segmentDataManagers.get(6)); assertTrue(result.get(3) == segmentDataManagers.get(0) || result.get(3) == segmentDataManagers.get(6)); assertSame(result.get(4), segmentDataManagers.get(3)); queryRequest = getQueryRequest("SELECT * FROM testTable ORDER BY testColumn, foo LIMIT 40"); result = _segmentPruner.prune(_tableDataManager, segmentDataManagers, queryRequest); assertEquals(result.size(), 7); assertSame(result.get(0), segmentDataManagers.get(5)); assertSame(result.get(1), segmentDataManagers.get(1)); assertTrue(result.get(2) == segmentDataManagers.get(0) || result.get(2) == segmentDataManagers.get(6)); assertTrue(result.get(3) == segmentDataManagers.get(0) || result.get(3) == segmentDataManagers.get(6)); assertSame(result.get(4), segmentDataManagers.get(3)); assertSame(result.get(5), segmentDataManagers.get(7)); assertSame(result.get(6), segmentDataManagers.get(2)); queryRequest = getQueryRequest("SELECT * FROM testTable ORDER BY testColumn DESC LIMIT 5"); result = _segmentPruner.prune(_tableDataManager, segmentDataManagers, queryRequest); assertEquals(result.size(), 4); assertSame(result.get(0), segmentDataManagers.get(5)); assertSame(result.get(1), segmentDataManagers.get(4)); assertTrue(result.get(2) == segmentDataManagers.get(2) || result.get(2) == segmentDataManagers.get(7)); assertTrue(result.get(3) == segmentDataManagers.get(2) || result.get(3) == segmentDataManagers.get(7)); queryRequest = getQueryRequest("SELECT * FROM testTable ORDER BY testColumn DESC LIMIT 5, 30"); result = _segmentPruner.prune(_tableDataManager, segmentDataManagers, queryRequest); assertEquals(result.size(), 4); assertSame(result.get(0), segmentDataManagers.get(5)); assertSame(result.get(1), segmentDataManagers.get(4)); assertTrue(result.get(2) == segmentDataManagers.get(2) || result.get(2) == segmentDataManagers.get(7)); assertTrue(result.get(3) == segmentDataManagers.get(2) || result.get(3) == segmentDataManagers.get(7)); queryRequest = getQueryRequest("SELECT * FROM testTable ORDER BY testColumn DESC, foo LIMIT 60"); result = _segmentPruner.prune(_tableDataManager, segmentDataManagers, queryRequest); assertEquals(result.size(), 8); assertSame(result.get(0), segmentDataManagers.get(5)); assertSame(result.get(1), segmentDataManagers.get(4)); assertTrue(result.get(2) == segmentDataManagers.get(2) || result.get(2) == segmentDataManagers.get(7)); assertTrue(result.get(3) == segmentDataManagers.get(2) || result.get(3) == segmentDataManagers.get(7)); assertTrue(result.get(4) == segmentDataManagers.get(3) || result.get(4) == segmentDataManagers.get(6)); assertTrue(result.get(5) == segmentDataManagers.get(3) || result.get(5) == segmentDataManagers.get(6)); assertSame(result.get(6), segmentDataManagers.get(0)); assertSame(result.get(7), segmentDataManagers.get(1)); }
@Override public List<SegmentDataManager> prune(TableDataManager tableDataManager, List<SegmentDataManager> segmentDataManagers, ServerQueryRequest queryRequest) { int numSegments = segmentDataManagers.size(); if (numSegments == 0) { return Collections.emptyList(); } QueryContext queryContext = queryRequest.getQueryContext(); if (QueryContextUtils.isAggregationQuery(queryContext)) { return segmentDataManagers; } int limit = queryContext.getLimit(); if (limit == 0) { for (int i = 1; i < numSegments; i++) { tableDataManager.releaseSegment(segmentDataManagers.get(i)); } return Collections.singletonList(segmentDataManagers.get(0)); } FilterContext filter = queryContext.getFilter(); if (filter != null) { return segmentDataManagers; } if (queryContext.getOrderByExpressions() == null) { return pruneSelectionOnly(tableDataManager, segmentDataManagers, queryContext); } else { return pruneSelectionOrderBy(tableDataManager, segmentDataManagers, queryContext); } }
SelectionQuerySegmentPruner implements SegmentPruner { @Override public List<SegmentDataManager> prune(TableDataManager tableDataManager, List<SegmentDataManager> segmentDataManagers, ServerQueryRequest queryRequest) { int numSegments = segmentDataManagers.size(); if (numSegments == 0) { return Collections.emptyList(); } QueryContext queryContext = queryRequest.getQueryContext(); if (QueryContextUtils.isAggregationQuery(queryContext)) { return segmentDataManagers; } int limit = queryContext.getLimit(); if (limit == 0) { for (int i = 1; i < numSegments; i++) { tableDataManager.releaseSegment(segmentDataManagers.get(i)); } return Collections.singletonList(segmentDataManagers.get(0)); } FilterContext filter = queryContext.getFilter(); if (filter != null) { return segmentDataManagers; } if (queryContext.getOrderByExpressions() == null) { return pruneSelectionOnly(tableDataManager, segmentDataManagers, queryContext); } else { return pruneSelectionOrderBy(tableDataManager, segmentDataManagers, queryContext); } } }
SelectionQuerySegmentPruner implements SegmentPruner { @Override public List<SegmentDataManager> prune(TableDataManager tableDataManager, List<SegmentDataManager> segmentDataManagers, ServerQueryRequest queryRequest) { int numSegments = segmentDataManagers.size(); if (numSegments == 0) { return Collections.emptyList(); } QueryContext queryContext = queryRequest.getQueryContext(); if (QueryContextUtils.isAggregationQuery(queryContext)) { return segmentDataManagers; } int limit = queryContext.getLimit(); if (limit == 0) { for (int i = 1; i < numSegments; i++) { tableDataManager.releaseSegment(segmentDataManagers.get(i)); } return Collections.singletonList(segmentDataManagers.get(0)); } FilterContext filter = queryContext.getFilter(); if (filter != null) { return segmentDataManagers; } if (queryContext.getOrderByExpressions() == null) { return pruneSelectionOnly(tableDataManager, segmentDataManagers, queryContext); } else { return pruneSelectionOrderBy(tableDataManager, segmentDataManagers, queryContext); } }  }
SelectionQuerySegmentPruner implements SegmentPruner { @Override public List<SegmentDataManager> prune(TableDataManager tableDataManager, List<SegmentDataManager> segmentDataManagers, ServerQueryRequest queryRequest) { int numSegments = segmentDataManagers.size(); if (numSegments == 0) { return Collections.emptyList(); } QueryContext queryContext = queryRequest.getQueryContext(); if (QueryContextUtils.isAggregationQuery(queryContext)) { return segmentDataManagers; } int limit = queryContext.getLimit(); if (limit == 0) { for (int i = 1; i < numSegments; i++) { tableDataManager.releaseSegment(segmentDataManagers.get(i)); } return Collections.singletonList(segmentDataManagers.get(0)); } FilterContext filter = queryContext.getFilter(); if (filter != null) { return segmentDataManagers; } if (queryContext.getOrderByExpressions() == null) { return pruneSelectionOnly(tableDataManager, segmentDataManagers, queryContext); } else { return pruneSelectionOrderBy(tableDataManager, segmentDataManagers, queryContext); } }  @Override void init(PinotConfiguration config); @Override List<SegmentDataManager> prune(TableDataManager tableDataManager, List<SegmentDataManager> segmentDataManagers,
      ServerQueryRequest queryRequest); }
SelectionQuerySegmentPruner implements SegmentPruner { @Override public List<SegmentDataManager> prune(TableDataManager tableDataManager, List<SegmentDataManager> segmentDataManagers, ServerQueryRequest queryRequest) { int numSegments = segmentDataManagers.size(); if (numSegments == 0) { return Collections.emptyList(); } QueryContext queryContext = queryRequest.getQueryContext(); if (QueryContextUtils.isAggregationQuery(queryContext)) { return segmentDataManagers; } int limit = queryContext.getLimit(); if (limit == 0) { for (int i = 1; i < numSegments; i++) { tableDataManager.releaseSegment(segmentDataManagers.get(i)); } return Collections.singletonList(segmentDataManagers.get(0)); } FilterContext filter = queryContext.getFilter(); if (filter != null) { return segmentDataManagers; } if (queryContext.getOrderByExpressions() == null) { return pruneSelectionOnly(tableDataManager, segmentDataManagers, queryContext); } else { return pruneSelectionOrderBy(tableDataManager, segmentDataManagers, queryContext); } }  @Override void init(PinotConfiguration config); @Override List<SegmentDataManager> prune(TableDataManager tableDataManager, List<SegmentDataManager> segmentDataManagers,
      ServerQueryRequest queryRequest);  }