官方教程有几个问题:不能直接运行;key和value为16进制值;因为副本数量为2,单机无法运行
下面代码基于cassandra 1.2
import static junit.framework.Assert.assertEquals; import java.util.Arrays; import me.prettyprint.cassandra.serializers.LongSerializer; import me.prettyprint.cassandra.serializers.StringSerializer; import me.prettyprint.cassandra.service.ColumnSliceIterator; import me.prettyprint.cassandra.service.ThriftKsDef; import me.prettyprint.cassandra.service.template.ColumnFamilyResult; import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate; import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater; import me.prettyprint.cassandra.service.template.ThriftColumnFamilyTemplate; import me.prettyprint.hector.api.Cluster; import me.prettyprint.hector.api.Keyspace; import me.prettyprint.hector.api.beans.HColumn; import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition; import me.prettyprint.hector.api.ddl.ComparatorType; import me.prettyprint.hector.api.ddl.KeyspaceDefinition; import me.prettyprint.hector.api.exceptions.HectorException; import me.prettyprint.hector.api.factory.HFactory; import me.prettyprint.hector.api.query.SliceQuery; import org.junit.Test; public class Hector5Min { String clusterName = "test-cluster"; String keyspace = "ks1"; String cfName = "cf1"; Cluster cluster = HFactory.getOrCreateCluster(clusterName, "localhost:9160"); Keyspace ksp = HFactory.createKeyspace(keyspace, cluster); ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(ksp, cfName, StringSerializer.get(), StringSerializer.get()); @Test public void createKeySpaceAndCf() { ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspace, cfName, ComparatorType.UTF8TYPE); // 下面两行我加的,为了让key和value以UTF8格式保存 cfDef.setKeyValidationClass(ComparatorType.UTF8TYPE.getClassName()); cfDef.setDefaultValidationClass(ComparatorType.UTF8TYPE.getClassName()); // 副本数我修改为1,官方为2,单机无法测试使用 KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(keyspace, ThriftKsDef.DEF_STRATEGY_CLASS, 1, Arrays.asList(cfDef)); cluster.addKeyspace(newKeyspace, true); } @Test public void insert() { ColumnFamilyUpdater<String, String> updater = template.createUpdater("rowkey1"); updater.setString("name", "heipark"); try { template.update(updater); } catch (HectorException e) { System.out.println(e); } } @Test public void read() { try { ColumnFamilyResult<String, String> res = template.queryColumns("rowkey1"); assertEquals("heipark", res.getString("name")); } catch (HectorException e) { System.out.println(e); } } @Test public void delete() { try { template.deleteColumn("rowkey1", "name"); } catch (HectorException e) { // do something } } @Test // 根据单个key查询所有columns public void testSliceQuery2() { SliceQuery<String, String, Long> query = HFactory.createSliceQuery(ksp, StringSerializer.get(), StringSerializer.get(), LongSerializer.get()); query.setColumnFamily(cf1); query.setKey(yourRowkey); ColumnSliceIterator<String, String, Long> iterator = new ColumnSliceIterator<String, String, Long>(query, null, "\uFFFF", false); while (iterator.hasNext()) { HColumn<String, Long> element = iterator.next(); System.out.println(element.getName() + ":" + element.getValue()); } } }
参考:
Getting started (5 minutes)
https://github.com/hector-client/hector/wiki/Getting-started-%285-minutes%29
--end
相关推荐
3、熟练GAMIT/GLOBK软件的安装流程与使用方法; 4、熟练GLOBK平差流程和处理策略; 5、掌握应用GAMIT/GLOBK软件进行高精度GNSS工程控制网数据处理与精度评估; 6、掌握应用GAMIT/GLOBK软件进行CORS站网坐标时间序列...
rplidar使用hector_slam的hector_mapping geotiff创建地图方法
数据包:Team_Hector_MappingBox_RoboCup_2011_Rescue_Arena.bag
hector slam源码hector_slam See the ROS Wiki for documentation: http://wiki.ros.org/hector_slam
关于Hector SLAM的ppt,介绍了hector slam的功能和框架。
Hector slam利用高斯牛顿方法解决scan-matching问题,对传感器要求较高。
简单的介绍了hector的使用方法,有一些调用的实例,有参考价值,适合初学者使用,英文版。
A Flexible and Scalable SLAM System with FullStefan Kohlbrecher and Oskar von St
hector_quadrotor_tutorial修改后源码,可以在Gazebo7上运行,ubuntu 16.04+ROS kinetic上编译可通过
实时定位与建图(SLAM),用激光传感器采集周围环境信息,建立环境地图,并计算当前机器人的位姿。
hector_slam源码
hector_gazebo hector_gazebo提供与使用凉亭模拟机器人相关的软件包(凉亭插件,世界文件等)。
java NoSql Cassandra hector 做的实例,拿出来分享
基于Hector SLAM算法的全场景自动驾驶护士床设计.pdf
在包hector_slam仓库被释放到noetic运行发行版/usr/local/bin/bloom-release hector_slam --ros-distro noetic上Mon, 12 Apr 2021 17:51:56 -0000 这些软件包已发布: hector_compressed_map_transport hector_...
HECTOR 9000最低要求- RaspberryPi 3- Debian bases Linux (to use installscript)在RaspberryPi上安装首先,您必须克隆Hector的github回购git clone https://github.com/H3c702/Hector9000.git该存储库不包含前端。...
hector-urquijo.github.io 信息存储库
ROS_Hector 在进行下一步之前,先检查FSM中赫克托尔的状态,然后由主设备控制STATE并将目标设置为(粉红色点) ############################## hector_master ################## #########################发布...
北大研一数据库原理与应用大作业,主要是实现在分布式环境下多表查询优化。
updates-r-simple.zip,Java自动更新系统,无框架和签名;Java自动更新系统,无框架和签名