com.netflix.astyanax.query
Interface AllRowsQuery<K,C>
- Type Parameters:
K
- C
-
- All Superinterfaces:
- Execution<Rows<K,C>>
- All Known Implementing Classes:
- AbstractThriftAllRowsQueryImpl
public interface AllRowsQuery<K,C>
- extends Execution<Rows<K,C>>
Specialized query to iterate the contents of a column family.
ColumnFamily CF_STANDARD1 =
new ColumnFamily("Standard1",
StringSerializer.get(),
StringSerializer.get());
Iterator> iter = keyspace.prepareQuery(MockConstants.CF_STANDARD1).iterator();
while (iter.hasNext()) {
Row row = iter.next();
LOG.info("ROW: " + row.getKey());
}
The iterator is implemented by making 'paginated' queries to Cassandra with
each query returning up to a the block size set by setBlockSize (default is 10).
The incremental query is hidden from the caller thereby providing a virtual
view into the column family.
There are a few important implementation details that need to be considered.
This implementation assumes the random partitioner is used. Consequently
the KeyRange query is done using tokens and not row keys. This is done because
when using the random partitioner tokens are sorted while keys are not. However,
because multiple keys could potentially map to the same token each incremental
query to Cassandra will repeat the last token from the previous response. This
will ensure that no keys are skipped. This does however have to very important
implications. First, the last and potentially more (if they have the
same token) row keys from the previous response will repeat. Second,
if a range of repeating tokens is larger than the block size then the code
will enter an infinite loop. This can be mitigated by selecting a block size
that is large enough so that the likelyhood of this happening is very low.
Also, if your application can tolerate the potential for skipped row keys
then call setRepeatLastToken(false) to turn off this features.
- Author:
- elandau
Method Summary |
void |
executeWithCallback(RowCallback<K,C> callback)
Execute the operation in a separate thread for each token range and provide the results
in a callback. |
AllRowsQuery<K,C> |
setBlockSize(int blockSize)
Deprecated. Use setRowLimit instead |
AllRowsQuery<K,C> |
setExceptionCallback(ExceptionCallback cb)
Sets the exception handler to use when handling exceptions inside
Iterator.next(). |
AllRowsQuery<K,C> |
setRepeatLastToken(boolean repeatLastToken)
If true will repeat the last token in the previous block. |
AllRowsQuery<K,C> |
setRowLimit(int rowLimit)
Maximum number of rows to return for each incremental query to Cassandra. |
AllRowsQuery<K,C> |
withColumnRange(ByteBuffer startColumn,
ByteBuffer endColumn,
boolean reversed,
int count)
Specify a range and provide pre-constructed start and end columns. |
AllRowsQuery<K,C> |
withColumnRange(ByteBufferRange range)
Specify a range of composite columns. |
AllRowsQuery<K,C> |
withColumnRange(C startColumn,
C endColumn,
boolean reversed,
int count)
Specify a range of columns to return. |
AllRowsQuery<K,C> |
withColumnSlice(C... columns)
Specify a non-contiguous set of columns to retrieve. |
AllRowsQuery<K,C> |
withColumnSlice(Collection<C> columns)
Specify a non-contiguous set of columns to retrieve. |
AllRowsQuery<K,C> |
withColumnSlice(ColumnSlice<C> columns)
Use this when your application caches the column slice. |
setBlockSize
AllRowsQuery<K,C> setBlockSize(int blockSize)
- Deprecated. Use setRowLimit instead
setRowLimit
AllRowsQuery<K,C> setRowLimit(int rowLimit)
- Maximum number of rows to return for each incremental query to Cassandra.
This limit also represents the page size when paginating.
- Parameters:
blockSize
-
- Returns:
setExceptionCallback
AllRowsQuery<K,C> setExceptionCallback(ExceptionCallback cb)
- Sets the exception handler to use when handling exceptions inside
Iterator.next(). This gives the caller a chance to implement
a backoff strategy or stop the iteration.
- Parameters:
cb
-
- Returns:
setRepeatLastToken
AllRowsQuery<K,C> setRepeatLastToken(boolean repeatLastToken)
- If true will repeat the last token in the previous block.
- Parameters:
repeatLastToken
-
- Returns:
withColumnSlice
AllRowsQuery<K,C> withColumnSlice(C... columns)
- Specify a non-contiguous set of columns to retrieve.
- Parameters:
columns
-
- Returns:
withColumnSlice
AllRowsQuery<K,C> withColumnSlice(Collection<C> columns)
- Specify a non-contiguous set of columns to retrieve.
- Parameters:
columns
-
- Returns:
withColumnSlice
AllRowsQuery<K,C> withColumnSlice(ColumnSlice<C> columns)
- Use this when your application caches the column slice.
- Parameters:
slice
-
- Returns:
withColumnRange
AllRowsQuery<K,C> withColumnRange(C startColumn,
C endColumn,
boolean reversed,
int count)
- Specify a range of columns to return.
- Parameters:
startColumn
- First column in the rangeendColumn
- Last column in the rangereversed
- True if the order should be reversed. Note that for
reversed, startColumn should be greater than endColumn.count
- Maximum number of columns to return (similar to SQL LIMIT)
- Returns:
withColumnRange
AllRowsQuery<K,C> withColumnRange(ByteBuffer startColumn,
ByteBuffer endColumn,
boolean reversed,
int count)
- Specify a range and provide pre-constructed start and end columns.
Use this with Composite columns
- Parameters:
startColumn
- endColumn
- reversed
- count
-
- Returns:
withColumnRange
AllRowsQuery<K,C> withColumnRange(ByteBufferRange range)
- Specify a range of composite columns. Use this in conjunction with the
AnnotatedCompositeSerializer.buildRange().
- Parameters:
range
-
- Returns:
executeWithCallback
void executeWithCallback(RowCallback<K,C> callback)
throws ConnectionException
- Execute the operation in a separate thread for each token range and provide the results
in a callback.
- Parameters:
predicate
-
- Throws:
ConnectionException
Copyright © 2012. All Rights Reserved.