您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

HBase-scanAPI通过scan读取表中数据

2025/10/31 2:28:23发布15次查看
直接贴代码啦 /** * * @param zkip * @param zkport * @param tablename * @param startrow 传null扫全表 * @param stoprow 已~结尾 * @throws exception */public static void scantable(string zkip,string zkport,string tablename,string startrow,strin
直接贴代码啦
/** * * @param zkip * @param zkport * @param tablename * @param startrow 传null扫全表 * @param stoprow 已~结尾 * @throws exception */ public static void scantable(string zkip,string zkport,string tablename,string startrow,string stoprow) throws exception { htablepool pool; configuration config = hbaseconfiguration.create(); config.set(hbase.zookeeper.quorum,zkip);// config.set(hbase.zookeeper.property.clientport, zkport); pool = new htablepool(config, 2); htableinterface hbtable = null; try { hbtable = pool.gettable(tablename); // 表名 resultscanner rs = null; scan scan = new scan(); // scan.addcolumn(bytes.tobytes(cf1),bytes.tobytes(qual1));扫某一列 if (startrow != null) { // 设置扫描的范围 scan.setstartrow(bytes.tobytes(startrow)); } if (stoprow != null) { scan.setstoprow(bytes.tobytes(stoprow)); } rs = hbtable.getscanner(scan); hbtable.close(); for (result r : rs) {// 按行去遍历 for (keyvalue kv : r.raw()) {// 遍历每一行的各列 stringbuffer sb = new stringbuffer() .append(bytes.tostring(kv.getrow())).append(\t) .append(bytes.tostring(kv.getfamily())) .append(\t) .append(bytes.tostring(kv.getqualifier())) .append(\t).append(bytes.tostring(kv.getvalue())); system.out.println(sb.tostring()); // kv.getrow() key // kv.getfamily() cf1 // kv.getqualifier() 列名 // kv.getvalue() value } } } catch (exception e) { system.out.println(e.getmessage()); }finally{ pool.close(); } }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product