1,本地Java API:最常规和高效的访问方式;
2, HBase壳:HBase的命令行工具,最简单的接口,适合HBase管理使用;
3,节俭网关:利用节俭序列化技术,支持c++、PHP、Python等多种语言,适合其他异构系统在线访问HBase表数据;
4,其他网关:支持其他风格的Http API访问HBase,解除了语言限制;
5, MapReduce:直接使用MapReduce作业处理Hbase数据;
6,使用猪/蜂巢处理Hbase数据。
<强> 1,加载配置强>
配置配置=HBaseConfiguration.create ();//可以自定义配置,也可以从自定义配置文件中读?* config.set (“hbase.zookeeper.property。clientPort”、“4181”); config.set (“hbase.zookeeper。法定人数”、“hadoop.datanode5.com, hadoop.datanode2.com, hadoop.datanode3.com”); config.set (“hbase。大师”、“hadoop.datanode3.com \ \: 600000”); */
<强> 2,表的创建,表信息修改,表删除强>
HBaseAdmin管理=new HBaseAdmin(配置);//创建表 HTableDescriptor htd=new HTableDescriptor(表); htd。addFamily(新HColumnDescriptor (“cf1”); htd。addFamily(新HColumnDescriptor (“cf2”); admin.createTable (htd);//修改表信息 admin.disableTable(表);//修改现有ColumnFamily 管理。modifyColumn(表名,新HColumnDescriptor (cf1 ")); admin.enableTable(表);//删除表 admin.disableTable (Bytes.toBytes(表); admin.deleteTable (Bytes.toBytes(表);>之前<强> 3,添加记录强>
/* *在多次使用时,建议用HTablePool HTable表=new HTable(配置表);=比; HTablePool池=new HTablePool(配置,1000);=pool.getTable HTableInterface表(表);*/HTable表=new HTable(配置表);/* * *在插入操作时,默认不适用任何缓存 *可自定义使用缓存,以及缓存大小 *每个任务最后需要手工调用flushCommits (); *//* table.setAutoFlush(假); table.setWriteBufferSize (1024); */把put1=new (Bytes.toBytes (rowKey)); 如果(t==0) { put1.add (Bytes.toBytes(家庭),Bytes.toBytes(预选赛),Bytes.toBytes(值)); 其他}{//自定义版本时,从自定义的版本号,类型为长 put1.add (Bytes.toBytes(家庭),Bytes.toBytes(预选赛),ts, Bytes.toBytes(值)); } table.put (put1);//table.flushCommits ();>之前<强> 4,查询,根据Rowkey查询强>
获得get1=new (Bytes.toBytes (rowKey)); 结果结果=table.get (get1); system . out。println(“得到结果:”+ Bytes.toString (result.getValue (Bytes.toBytes(家庭),Bytes.toBytes(限定词)))); 结果[]=table.get (List<强> 5,查询,指定条件和rowkey区间查询强>
扫描扫描=new扫描();//默认缓存大小为1,设置成一个合理的值,可以减少扫描过程中next()的时间开销,代价是客户端的内存 scan.setCaching (500); scan.setCacheBlocks(假);//根据startRowKey, endRowKey查询//扫描扫描=new扫描(Bytes.toBytes (“startRowKey”), Bytes.toBytes (endRowKey "));//rowKey之外的过滤条件,在列表中可以添加;/* * List过滤器=new ArrayList (); 过滤器过滤=new SingleColumnValueFilter (familyName .getBytes (), “qualifierName .getBytes (), CompareOp.EQUAL, Bytes.toBytes(“价值”)); filters.add(过滤器); 扫描。setFilter(新FilterList(过滤器));*/ResultScanner扫描仪=table.getScanner(扫描); system . out。println(“扫描结果列表:”); (结果结果:扫描仪){ System.out.println (Bytes.toString (result.getRow ())); System.out.println (Bytes.toString (result.getValue (Bytes.toBytes(“数据”),Bytes.toBytes (“data1”)))); System.out.println (Bytes.toString (result.getValue (Bytes.toBytes(“数据”),Bytes.toBytes (“data2 ")))); } scanner.close ();>之前
以上所述是小编给大家介绍的hbase访问方式之java api,希望对大家有所帮助,如果大家有任何疑问请给我留的言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
hbase访问方式之java api