@Override public PeekingResultIterator newIterator(StatementContext context, ResultIterator scanner, Scan scan, String tableName, QueryPlan plan) throws SQLException { Expression expression = RowKeyExpression.INSTANCE; boolean isNullsLast=false; boolean isAscending=true; if(this.orderBy==OrderBy.REV_ROW_KEY_ORDER_BY) { isNullsLast=true; //which is needed for the whole rowKey. isAscending=false; } OrderByExpression orderByExpression = new OrderByExpression(expression, isNullsLast, isAscending); int threshold = services.getProps().getInt(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_SPOOL_THRESHOLD_BYTES); return new OrderedResultIterator(scanner, Collections.<OrderByExpression>singletonList(orderByExpression), threshold); } }
@Test public void testNullIteratorOnClose() throws SQLException { ResultIterator delegate = ResultIterator.EMPTY_ITERATOR; List<OrderByExpression> orderByExpressions = Collections.singletonList(null); int thresholdBytes = Integer.MAX_VALUE; OrderedResultIterator iterator = new OrderedResultIterator(delegate, orderByExpressions, thresholdBytes); // Should not throw an exception iterator.close(); }
long estSize = iterator.getEstimatedByteSize(); final MemoryManager.MemoryChunk chunk = tenantCache.getMemoryManager().allocate(estSize); final Region region = getRegion(); firstTuple = iterator.next(); long actualSize = iterator.getByteSize(); chunk.resize(actualSize); } catch (Throwable t) {
@Override public void close() throws IOException { try { s.close(); } finally { try { if(iterator != null) { iterator.close(); } } catch (SQLException e) { ServerUtil.throwIOException(region.getRegionInfo().getRegionNameAsString(), e); } finally { chunk.close(); } } } };
@Override public Tuple next() throws SQLException { Tuple tuple = super.next(); if (tuple != null) { aggregate(tuple); } return tuple; }
@Override public Tuple next() throws SQLException { return getResultIterator().next(); }
@Override protected AggregatingResultIterator getDelegate() { return (AggregatingResultIterator)super.getDelegate(); }
/** * Builds a comparator from the list of columns in ORDER BY clause. * @param orderByExpressions the columns in ORDER BY clause. * @return the comparator built from the list of columns in ORDER BY clause. */ // ImmutableBytesWritable.Comparator doesn't implement generics @SuppressWarnings("unchecked") private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) { Ordering<ResultEntry> ordering = null; int pos = 0; for (OrderByExpression col : orderByExpressions) { Expression e = col.getExpression(); Comparator<ImmutableBytesWritable> comparator = e.getSortOrder() == SortOrder.DESC && !e.getDataType().isFixedWidth() ? buildDescVarLengthComparator() : new ImmutableBytesWritable.Comparator(); Ordering<ImmutableBytesWritable> o = Ordering.from(comparator); if(!col.isAscending()) o = o.reverse(); o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst(); Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++)); ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering); } return ordering; }
final Comparator<ResultEntry> comparator = buildComparator(orderByExpressions); try{ final MappedByteBufferSortedQueue queueEntries = new MappedByteBufferSortedQueue(comparator, limit,
@Override public void close() throws IOException { try { s.close(); } finally { try { if(iterator != null) { iterator.close(); } } catch (SQLException e) { ServerUtil.throwIOException(region.getRegionInfo().getRegionNameAsString(), e); } finally { chunk.close(); } } } };
@Override public boolean next(List<Cell> results) throws IOException { try { if (isFilterDone()) { return false; } for (int i = 0; i < tuple.size(); i++) { results.add(tuple.getValue(i)); } tuple = iterator.next(); return !isFilterDone(); } catch (Throwable t) { ServerUtil.throwIOException(region.getRegionInfo().getRegionNameAsString(), t); return false; } }
@Override public Tuple peek() throws SQLException { return getResultIterator().peek(); }
@Override protected AggregatingResultIterator getDelegate() { return (AggregatingResultIterator)super.getDelegate(); }
/** * Builds a comparator from the list of columns in ORDER BY clause. * @param orderByExpressions the columns in ORDER BY clause. * @return the comparator built from the list of columns in ORDER BY clause. */ // ImmutableBytesWritable.Comparator doesn't implement generics @SuppressWarnings("unchecked") private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) { Ordering<ResultEntry> ordering = null; int pos = 0; for (OrderByExpression col : orderByExpressions) { Expression e = col.getExpression(); Comparator<ImmutableBytesWritable> comparator = e.getSortOrder() == SortOrder.DESC && !e.getDataType().isFixedWidth() ? buildDescVarLengthComparator() : new ImmutableBytesWritable.Comparator(); Ordering<ImmutableBytesWritable> o = Ordering.from(comparator); if(!col.isAscending()) o = o.reverse(); o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst(); Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++)); ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering); } return ordering; }
final Comparator<ResultEntry> comparator = buildComparator(orderByExpressions); try{ final MappedByteBufferSortedQueue queueEntries = new MappedByteBufferSortedQueue(comparator, limit,
return new OrderedResultIterator(inner, orderByExpressions, thresholdBytes, limit >= 0 ? limit : null, null, estimatedRowSize); } catch (IOException e) {
long estSize = iterator.getEstimatedByteSize(); final MemoryManager.MemoryChunk chunk = tenantCache.getMemoryManager().allocate(estSize); final Region region = getRegion(); firstTuple = iterator.next(); long actualSize = iterator.getByteSize(); chunk.resize(actualSize); } catch (Throwable t) {
@Override public void close() throws IOException { try { s.close(); } finally { try { if(iterator != null) { iterator.close(); } } catch (SQLException e) { ServerUtil.throwIOException(region.getRegionInfo().getRegionNameAsString(), e); } finally { chunk.close(); } } } };
@Override public Tuple next() throws SQLException { Tuple tuple = super.next(); if (tuple != null) { aggregate(tuple); } return tuple; }
@Override public Tuple peek() throws SQLException { return getResultIterator().peek(); }