Nosql Cassandra 0.6 key值的区间查询
小记:
传入条件 如key区间a至c 一种有a-d的数据
List<KeySlice> sliceList = client.get_range_slice(keyspace, parent,
predicate, "a", "d", 1000, ConsistencyLevel.ONE);
package com.sh2999.cassandra.testapp;
import java.util.List;
import org.apache.cassandra.thrift.Cassandra;
import org.apache.cassandra.thrift.ColumnOrSuperColumn;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ColumnPath;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.KeySlice;
import org.apache.cassandra.thrift.NotFoundException;
import org.apache.cassandra.thrift.SlicePredicate;
import org.apache.cassandra.thrift.SliceRange;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
/**
* key值的区间查询 这里可以传入条件 如key区间a至c 一种有a-d的数据
*
* @since Cassandra 0.6
* @author db2admin
*
*/
public class Cassandra647TestApp {
/**
*
* OrderPreservingPartitioner should be used.
*/
public static void main(String[] args) throws Exception {
String keyspace = "Keyspace1";
String cf = "sh2999.com";
String key = "row1";
byte[] columnName = "colname".getBytes("UTF-8");
byte[] data = "testdata".getBytes("UTF-8");
TTransport transport = new TSocket("localhost", 9160);
TProtocol protocol = new TBinaryProtocol(transport);
Cassandra.Client client = new Cassandra.Client(protocol);
transport.open();
ColumnPath path = new ColumnPath(cf);
path.setColumn(columnName);
client.insert(keyspace, key, path, data, System.currentTimeMillis(),
ConsistencyLevel.ONE);
key = "testrow2";
byte[] data2 = "testdata".getBytes("UTF-8");
client.insert(keyspace, key, path, data2, System.currentTimeMillis(),
ConsistencyLevel.ONE);
key = "a";
byte[] data3 = "testdata".getBytes("UTF-8");
client.insert(keyspace, key, path, data3, System.currentTimeMillis(),
ConsistencyLevel.ONE);
key = "b";
byte[] data4 = "testdata".getBytes("UTF-8");
client.insert(keyspace, key, path, data4, System.currentTimeMillis(),
ConsistencyLevel.ONE);
key = "c";
byte[] data5 = "testdata".getBytes("UTF-8");
client.insert(keyspace, key, path, data5, System.currentTimeMillis(),
ConsistencyLevel.ONE);
key = "d";
byte[] data6 = "testdata".getBytes("UTF-8");
client.insert(keyspace, key, path, data6, System.currentTimeMillis(),
ConsistencyLevel.ONE);
Thread.sleep(1000);
ColumnPath rowpath = new ColumnPath(cf);
rowpath.setColumn(columnName);
// 删除通过
// client.remove(keyspace, key, rowpath, System.currentTimeMillis(),
// ConsistencyLevel.ONE);
// Thread.sleep(1000);
try {
ColumnOrSuperColumn cosc = client.get(keyspace, key, path,
ConsistencyLevel.ONE);
System.out.println("Whoops! NotFoundException not thrown!");
} catch (NotFoundException e) {
System.out.println("OK, we got a NotFoundException");
}
ColumnParent parent = new ColumnParent(cf);
SlicePredicate predicate = new SlicePredicate();
SliceRange range = new SliceRange();
range.start = new byte[0];
range.finish = new byte[10];
predicate.slice_range = range;
// 这里可以传入条件 如key区间a至c 一种有a-d的数据
List<KeySlice> sliceList = client.get_range_slice(keyspace, parent,
predicate, "a", "d", 1000, ConsistencyLevel.ONE);
for (KeySlice k : sliceList) {
System.err.println("Found key " + k.key);
if (key.equals(k.key)) {
System.out.println("but key " + k.key
+ " should have been removed");
}
}
}
}
其它关于Cassandra资料收集见:
http://www.sh2999.com/sh/posts/list/325.page
分享到:
相关推荐
其主要功能比Dynomite(分布式的Key-Value存储系统)更丰富,但支持度却不如文档存储MongoDB(介于关系数据库和非关系数据库之间的开源产品,是非关系数据库当中功能最丰富,最像关系数据库的。支持的数据结构非常...
java NoSql Cassandra hector 做的实例,拿出来分享
cassandra nosql why cassandra
NoSql Apache Cassandra 非关系型数据库
Cassandra 入门学习 Clauster 实例 Cassandra Log4j 下应用
[NOSQL] Cassandra 数据库系统简单介绍.doc
Cassandra是一套开源分布式NoSQL数据库系统。它最初由Facebook开发,用于储存收件箱等简单格式数据,集GoogleBigTable的数据模型与Amazon Dynamo的完全分布式的架构于一身Facebook于2008将 Cassandra 开源,此后,...
Apache Cassandra is the most commonly used NoSQL database written in Java and is renowned in the industry as the only NoSQL solution that can accommodate the complex requirements of today’s modern ...
Cassandra实战 java NoSql
探索 NoSQL 数据库 Cassandra。 此存储库包含学习如何使用 Cassandra 的示例。 为方便起见,将项目分为模块。 每个模块都展示了解决特定问题的方法。CheckCaster ##### cassandra 集群的基本健康检查。 部署集群后,...
mbit-m03-dc03-cassandra:MBIT大数据2019-2020 NoSQL Cassandra案例研究(DC-03 TP-01)
nosql数据库cassandra入门的一个例子。包括简单的插入、查询、建立keyspace等
NoSQL应用场景及Cassandra架构分析
NyaruDB, 在 Objective C 中,一个简单的NoSQL 数据库( key-value 对) 在iOS和 OS X 上,它运行 #NyaruDB ###\(・ω・\)SAN値(/・ω・)/ピンチ !這いよれニャル子さんW !MIT许可证NyaruDB是 objective-c 中的...
SSDB 是⼀ 一个 C++ 语⾔ 言开发的⾼ 高性能开源 NoSQL 数据库服务器, ⽀ 支持 Key-value, Key- hashmap, Key-zset(sorted set) 等数据结构, ⼗ 十分适合存储数亿条级别的列表, 排序表等...
介绍了NoSQL数据库的种类划分和各类型特点,阐述了RDF数据在各类NoSQL数据库中存储结构设计和并行查询算法的研究现状,分析比较了不同方法的优缺点。最后,讨论了利用NoSQL数据库管理RDF的优势,总结了现有研究的...
非关系数据库(经常被称为NoSQL)的特点是弹性和可伸缩性。另外,它们可以存储大数据并与云计算系统协同工作。这些因素导致非关系数据库非常流行。在2013年,NoSQL数据库的种类达到了150多个,并且一直在增长,多种...
可视化MongoDB数据库管理工具,NoSQL Manager for MongoDB,破解版,解压就可以用。