6)//range queries may only be performed against an order-preserving partitioner
//如果系统试用的节点定位的RandomPartitioner的话那么这个方法将不能试用,好处是跟均衡的存储
//此方法尚在研究中
public void test_get_key_range()
{
try {
cli.get_key_range("Table1", "??", "??", 1);
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
}
7) //术语解释:每个key都对应一个Row的信息这个Row的信息又按照columnFamliy 分成了很多slice
//每一个columnFamily都存在一个排序,或按照name或按照time
//该方法将取出对应某个key的一定区间段内的column元素
public void test_get_slice()
{
tableName = "Table1";
keyName = "testKey2";
columnFamily = "Standard1"; //想要从哪个columnFamily中获取column
int start = 0;//起始位置
int count = 10;//获取数量
try {
List cmts = cli.get_slice(tableName, keyName, columnFamily, start, count);
.out.println("cmts size : "+cmts.size());
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch ( e) {
e.printStackTrace();
}
}
//通过一个column的名字数组来查找相对应的属于给定key的slice(一组column 元素)
public void test_get_slice_by_names()
{
tableName = "Table1";
keyName = "testKey";
columnFamily = "Standard1";
List columnNameList = new ArrayList();
columnNameList.add("testColumn");
try{
List cmts = cli.get_slice_by_names(tableName, keyName, columnFamily, columnNameList);
}catch( e){
e.printStackTrace();
}
}
9)//描述一个table中的各个columnFamily的基本信息
public void test_describe_table()
{
try {
.out.println(cli.describeTable("Table1"));
} catch (TException e) {
e.printStackTrace();
}
}
10)//批量的针对一个key插入数据
public void test_batch_insert()
{
try{
tableName = "Table1";
keyName = "testkey2";
//当下的Map保存了ColumnFamily到他内部的column元素列表的一个映射
//所以String 应该保存 对应columnFamily的名字。
//column_t(column元素)包含:columnName , value , timestamp 三要素
Map> CFmap = new HashMap>();
//制作两个column_t实例
column_t cmt1 = new column_t("test_column_name_1" ,"test_column_value_1".getBytes() , .currentTimeMillis());
column_t cmt2 = new column_t("test_column_name_2" ,"test_column_value_2".getBytes() , .currentTimeMillis());
//制作一个column_t的list
List cList = new ArrayList();
cList.add(cmt1);
cList.add(cmt2);
//制作一个将其写入CFmap中
columnFamilyName = "Standard1";
CFmap.put(columnFamilyName, cList);//这样在以后的插入操作中,相应的column_t将插入"Docin"这个family中
batch_mutation_t bmt = new batch_mutation_t(tableName , keyName , CFmap);//完成插入的key的定位
//执行这个针对相应key和colmunFamily的batch_insert
cli.batch_insert(bmt, true);
}catch( e){
e.printStackTrace();
}
}
11)//同insert()相对的反向操作
//当我们试图查询一个不存在的column_t元素的时候,会有”NotFoundException”异常被抛出
public void test_remove()
{
tableName = "Table1";
columnFamily = "Standard1";
columnName = "removetest";
keyName = "removetestkey";
value = "removetestvalue";
path = columnFamily+":"+columnName;
try{
//先将相应的column元素写入
cli.insert(tableName, keyName, path, value.getBytes(),.currentTimeMillis(), true);
//尝试读出信息
column_t cmt = cli.get_column(tableName, keyName, path);
displayColumn(cmt);
//删除这条信息
cli.remove(tableName, keyName, path, .currentTimeMillis(),true);
}catch( e){
e.printStackTrace();
}
//尝试读出信息
column_t cmt2;
try {
cmt2 = cli.get_column(tableName, keyName, path);
displayColumn(cmt2);
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (NotFoundException e) {
.out.println("NotFoundException 异常抛出,column_元素已经被删除");
} catch (TException e) {
e.printStackTrace();
} catch ( e) {
e.printStackTrace();
}
}
阅读(628) | 评论(0) | 转发(0) |