本文整理汇总了Java中org.apache.cassandra.thrift.SliceRange类的典型用法代码示例。如果您正苦于以下问题:Java SliceRange类的具体用法?Java SliceRange怎么用?Java SliceRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SliceRange类属于org.apache.cassandra.thrift包,在下文中一共展示了SliceRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: slicePredicate
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
protected SlicePredicate slicePredicate()
{
final SlicePredicate predicate = new SlicePredicate();
if (state.settings.columns.slice)
{
int count = state.rowGen.count(index);
int start = sliceStart(count);
predicate.setSlice_range(new SliceRange()
.setStart(state.settings.columns.names.get(start))
.setFinish(new byte[] {})
.setReversed(false)
.setCount(count)
);
}
else
predicate.setColumn_names(randomNames());
return predicate;
}
示例2: getSlicePredicate
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
private SlicePredicate getSlicePredicate(String[] columnNameList) {
SlicePredicate slicePredicate = new SlicePredicate();
try {
if (columnNameList != null) {
List<ByteBuffer> columnNameByteBufferList = new ArrayList<ByteBuffer>();
for (String columnName: columnNameList) {
byte[] columnNameBytes = columnName.getBytes("UTF-8");
columnNameByteBufferList.add(ByteBuffer.wrap(columnNameBytes));
}
slicePredicate.setColumn_names(columnNameByteBufferList);
} else {
SliceRange sliceRange = new SliceRange();
sliceRange.setStart(new byte[0]);
sliceRange.setFinish(new byte[0]);
// FIXME: The default column count is 100. We should tune the value.
sliceRange.setCount(100000);
slicePredicate.setSlice_range(sliceRange);
}
}
catch (UnsupportedEncodingException exc) {
throw new StorageException("Character encoding exception with key range", exc);
}
return slicePredicate;
}
示例3: CasTimeReader
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
public CasTimeReader() {
try {
TTransport tr = new TFramedTransport(new TSocket("10.15.61.111",
9160));
TProtocol proto = new TBinaryProtocol(tr);
client = new Cassandra.Client(proto);
tr.open();
client.set_keyspace("CadalSecTest");
predicate = new SlicePredicate();
SliceRange range = new SliceRange();
range.setStart(new byte[0]);
range.setFinish(new byte[0]);
range.setCount(10000);
predicate.setSlice_range(range);
columnParent = new ColumnParent();
columnParent.setColumn_family("RecordMinute");
} catch (Exception e) {
System.out.println(e);
}
}
示例4: CasTimeBook
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
public CasTimeBook() {
try {
TTransport tr = new TFramedTransport(new TSocket("10.15.61.111",
9160));
TProtocol proto = new TBinaryProtocol(tr);
client = new Cassandra.Client(proto);
tr.open();
client.set_keyspace("CadalSecTest");
predicate = new SlicePredicate();
SliceRange range = new SliceRange();
range.setStart(new byte[0]);
range.setFinish(new byte[0]);
range.setCount(10000);
predicate.setSlice_range(range);
columnParent = new ColumnParent();
columnParent.setColumn_family("RecordMinute");
} catch (Exception e) {
System.out.println(e);
}
}
示例5: getSliceRange
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
private SliceRange getSliceRange(final SliceQuery slice, final int limit) {
final SliceRange sliceRange = new SliceRange();
sliceRange.setStart(slice.getSliceStart().asByteBuffer());
sliceRange.setFinish(slice.getSliceEnd().asByteBuffer());
sliceRange.setCount(Math.min(limit, slice.getLimit()));
return sliceRange;
}
示例6: getKeySlice
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
/**
* Create a RangeSliceCommand and run it against the StorageProxy.
* <p>
* To match the behavior of the standard Cassandra thrift API endpoint, the
* {@code nowMillis} argument should be the number of milliseconds since the
* UNIX Epoch (e.g. System.currentTimeMillis() or equivalent obtained
* through a {@link TimestampProvider}). This is per
* {@link org.apache.cassandra.thrift.CassandraServer#get_range_slices(ColumnParent, SlicePredicate, KeyRange, ConsistencyLevel)},
* which passes the server's System.currentTimeMillis() to the
* {@code RangeSliceCommand} constructor.
*/
private List<Row> getKeySlice(Token start,
Token end,
@Nullable SliceQuery sliceQuery,
int pageSize,
long nowMillis) throws BackendException {
IPartitioner partitioner = StorageService.getPartitioner();
SliceRange columnSlice = new SliceRange();
if (sliceQuery == null) {
columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY)
.setFinish(ArrayUtils.EMPTY_BYTE_ARRAY)
.setCount(5);
} else {
columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer())
.setFinish(sliceQuery.getSliceEnd().asByteBuffer())
.setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE);
}
/* Note: we need to fetch columns for each row as well to remove "range ghosts" */
SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
RowPosition startPosition = start.minKeyBound(partitioner);
RowPosition endPosition = end.minKeyBound(partitioner);
List<Row> rows;
try {
CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily);
IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null);
RangeSliceCommand cmd = new RangeSliceCommand(keyspace, columnFamily, nowMillis, filter, new Bounds<RowPosition>(startPosition, endPosition), pageSize);
rows = StorageProxy.getRangeSlice(cmd, ConsistencyLevel.QUORUM);
} catch (Exception e) {
throw new PermanentBackendException(e);
}
return rows;
}
示例7: get2
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
/**
* get 讀取所有column
*
* @throws Exception
*/
@Test
public void get2() throws Exception {
String KEYSPACE = "mock";
client.set_keyspace(KEYSPACE);
// 讀取所有column
String COLUMN_FAMILY = "student";
ColumnParent columnParent = new ColumnParent(COLUMN_FAMILY);
// 術語
SlicePredicate predicate = new SlicePredicate();
// 範圍
SliceRange sliceRange = new SliceRange();
// sliceRange.setStart(ByteBufferHelper.toByteBuffer(new byte[0]));//開始
sliceRange.setStart(new byte[0]);// 開始
sliceRange.setFinish(new byte[0]);// 結束
sliceRange.setCount(100);// 筆數
//
predicate.setSlice_range(sliceRange);
String ROW_KEY = "Jack";
// 結果
// key, column_parent, predicate, consistency_level
List<ColumnOrSuperColumn> results = client.get_slice(
ByteBufferHelper.toByteBuffer(ROW_KEY), columnParent,
predicate, ConsistencyLevel.ONE);
for (ColumnOrSuperColumn cos : results) {
Column column = cos.getColumn();
System.out.println(ROW_KEY + ", "
+ ByteHelper.toString(column.getName()) + ": "
+ ByteHelper.toString(column.getValue()) + ", "
+ column.getTimestamp());
// Jack, art, 87, 1380788003220
// Jack, grad, 5, 1380788003203
// Jack, math, 97, 1380788003214
}
}
示例8: getKeySlice
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
/**
* Create a RangeSliceCommand and run it against the StorageProxy.
* <p>
* To match the behavior of the standard Cassandra thrift API endpoint, the
* {@code nowMillis} argument should be the number of milliseconds since the
* UNIX Epoch (e.g. System.currentTimeMillis() or equivalent obtained
* through a {@link TimestampProvider}). This is per
* {@link org.apache.cassandra.thrift.CassandraServer#get_range_slices(ColumnParent, SlicePredicate, KeyRange, ConsistencyLevel)},
* which passes the server's System.currentTimeMillis() to the
* {@code RangeSliceCommand} constructor.
*/
private List<Row> getKeySlice(Token start,
Token end,
@Nullable SliceQuery sliceQuery,
int pageSize,
long nowMillis) throws BackendException {
IPartitioner<?> partitioner = StorageService.getPartitioner();
SliceRange columnSlice = new SliceRange();
if (sliceQuery == null) {
columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY)
.setFinish(ArrayUtils.EMPTY_BYTE_ARRAY)
.setCount(5);
} else {
columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer())
.setFinish(sliceQuery.getSliceEnd().asByteBuffer())
.setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE);
}
/* Note: we need to fetch columns for each row as well to remove "range ghosts" */
SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
RowPosition startPosition = start.minKeyBound(partitioner);
RowPosition endPosition = end.minKeyBound(partitioner);
List<Row> rows;
try {
CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily);
IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null);
RangeSliceCommand cmd = new RangeSliceCommand(keyspace, columnFamily, nowMillis, filter, new Bounds<RowPosition>(startPosition, endPosition), pageSize);
rows = StorageProxy.getRangeSlice(cmd, ConsistencyLevel.QUORUM);
} catch (Exception e) {
throw new PermanentBackendException(e);
}
return rows;
}
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:50,代码来源:CassandraEmbeddedKeyColumnValueStore.java
示例9: asSlicePredicate
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
public static SlicePredicate asSlicePredicate(IDiskAtomFilter predicate)
{
SlicePredicate sp = new SlicePredicate();
if (predicate instanceof NamesQueryFilter)
{
sp.setColumn_names(new ArrayList<ByteBuffer>(((NamesQueryFilter)predicate).columns));
}
else
{
SliceQueryFilter sqf = (SliceQueryFilter)predicate;
sp.setSlice_range(new SliceRange(sqf.start(), sqf.finish(), sqf.reversed, sqf.count));
}
return sp;
}
示例10: run
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
SliceRange sliceRange = new SliceRange();
// start/finish
sliceRange.setStart(new byte[] {}).setFinish(new byte[] {});
// reversed/count
sliceRange.setReversed(false).setCount(state.settings.columns.maxColumnsPerKey);
// initialize SlicePredicate with existing SliceRange
final SlicePredicate predicate = new SlicePredicate().setSlice_range(sliceRange);
final ByteBuffer key = getKey();
for (final ColumnParent parent : state.columnParents)
{
timeWithRetry(new RunOp()
{
@Override
public boolean run() throws Exception
{
return client.get_slice(key, parent, predicate, state.settings.command.consistencyLevel).size() != 0;
}
@Override
public String key()
{
return new String(key.array());
}
@Override
public int keyCount()
{
return 1;
}
});
}
}
示例11: run
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
final SlicePredicate predicate = new SlicePredicate();
if (state.settings.columns.names == null)
predicate.setSlice_range(new SliceRange()
.setStart(new byte[] {})
.setFinish(new byte[] {})
.setReversed(false)
.setCount(state.settings.columns.maxColumnsPerKey)
);
else // see CASSANDRA-3064 about why this is useful
predicate.setColumn_names(state.settings.columns.names);
final ByteBuffer key = getKey();
for (final ColumnParent parent : state.columnParents)
{
timeWithRetry(new RunOp()
{
@Override
public boolean run() throws Exception
{
return client.get_slice(key, parent, predicate, state.settings.command.consistencyLevel).size() != 0;
}
@Override
public String key()
{
return new String(key.array());
}
@Override
public int keyCount()
{
return 1;
}
});
}
}
示例12: run
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
final SlicePredicate predicate = new SlicePredicate().setSlice_range(
new SliceRange(
ByteBufferUtil.EMPTY_BYTE_BUFFER,
ByteBufferUtil.EMPTY_BYTE_BUFFER,
false,
state.settings.columns.maxColumnsPerKey
)
);
final List<ByteBuffer> keys = getKeys(((SettingsCommandMulti) state.settings.command).keysAtOnce);
for (final ColumnParent parent : state.columnParents)
{
timeWithRetry(new RunOp()
{
int count;
@Override
public boolean run() throws Exception
{
return (count = client.multiget_slice(keys, parent, predicate, state.settings.command.consistencyLevel).size()) != 0;
}
@Override
public String key()
{
return keys.toString();
}
@Override
public int keyCount()
{
return count;
}
});
}
}
示例13: run
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
final SlicePredicate predicate = new SlicePredicate().setSlice_range(
new SliceRange(
ByteBufferUtil.EMPTY_BYTE_BUFFER,
ByteBufferUtil.EMPTY_BYTE_BUFFER,
false,
state.settings.columns.maxColumnsPerKey
)
);
final List<ByteBuffer> keys = getKeys(state.settings.command.keysAtOnce);
for (final ColumnParent parent : state.columnParents)
{
timeWithRetry(new RunOp()
{
int count;
@Override
public boolean run() throws Exception
{
return (count = client.multiget_slice(keys, parent, predicate, state.settings.command.consistencyLevel).size()) != 0;
}
@Override
public String key()
{
return keys.toString();
}
@Override
public int keyCount()
{
return count;
}
});
}
}
示例14: toString
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
private static String toString(SlicePredicate slicePred) {
StringBuilder buffer = new StringBuilder();
if (slicePred.isSetColumn_names()) {
buffer.append("Columns(");
buffer.append(slicePred.getColumn_names().size());
buffer.append(" total)");
} else if (slicePred.isSetSlice_range()) {
SliceRange sliceRange = slicePred.getSlice_range();
ByteBuffer startCol = sliceRange.start;
String startColStr = "<null>";
if (startCol != null) {
startColStr = Utils.toString(startCol.array(), startCol.arrayOffset(), startCol.limit());
}
if (startColStr.length() == 0) {
startColStr = "<first>";
}
ByteBuffer endCol = sliceRange.finish;
String endColStr = "<null>";
if (endCol != null) {
endColStr = Utils.toString(endCol.array(), endCol.arrayOffset(), endCol.limit());
}
if (endColStr.length() == 0) {
endColStr = "<last>";
}
if (startColStr.equals("<first>") && endColStr.equals("<last>")) {
buffer.append("Slice(<all>)");
} else {
buffer.append("Slice('");
buffer.append(startColStr);
buffer.append("' to '");
buffer.append(endColStr);
buffer.append("')");
}
}
return buffer.toString();
}
示例15: slicePredicateStartEndCol
import org.apache.cassandra.thrift.SliceRange; //导入依赖的package包/类
/**
* Create a SlicePredicate that starts at the given column name, selecting up to
* {@link #MAX_COLS_BATCH_SIZE} columns.
*
* @param startColName Starting column name as a byte[].
* @param endColName Ending column name as a byte[]
* @return SlicePredicate that starts at the given starting column name,
* ends at the given ending column name, selecting up to
* {@link #MAX_COLS_BATCH_SIZE} columns.
*/
static SlicePredicate slicePredicateStartEndCol(byte[] startColName, byte[] endColName, boolean reversed) {
if(startColName == null) startColName = EMPTY_BYTES;
if(endColName == null) endColName = EMPTY_BYTES;
SliceRange sliceRange =
new SliceRange(
ByteBuffer.wrap(startColName), ByteBuffer.wrap(endColName),
reversed, CassandraDefs.MAX_COLS_BATCH_SIZE);
SlicePredicate slicePred = new SlicePredicate();
slicePred.setSlice_range(sliceRange);
return slicePred;
}