MapReduce操作HBase错误一例

复制package test; import java.io.IOException; import java.util.Map; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; publicclass Htable { /** * @param args */ publicstaticvoid main(String[] args) throws IOException { // TODO Auto-generated method stub Configuration hbaseConf = HBaseConfiguration.create(); HBaseAdmin admin = new HBaseAdmin(hbaseConf); HTableDescriptor htableDescriptor = new HTableDescriptor("table" .getBytes()); //set the name of table htableDescriptor.addFamily(new HColumnDescriptor("fam1")); //set the name of column clusters admin.createTable(htableDescriptor); //create a table HTable table = new HTable(hbaseConf,操错误 "table"); //get instance of table. for (int i = 0; i < 3; i++) { //for is number of rows Put putRow = new Put(("row" + i).getBytes()); //the ith row putRow.add("fam1".getBytes(), "col1".getBytes(), "vaule1" .getBytes()); //set the name of column and value. putRow.add("fam1".getBytes(), "col2".getBytes(), "vaule2" .getBytes()); putRow.add("fam1".getBytes(), "col3".getBytes(), "vaule3" .getBytes()); table.put(putRow); } for(Result result: table.getScanner("fam1".getBytes())){//get data of column clusters for(Map.Entry<byte[], byte[]> entry : result.getFamilyMap("fam1".getBytes()).entrySet()){//get collection of result String column = new String(entry.getKey()); String value = new String(entry.getValue()); System.out.println(column+","+value); } } admin.disableTable("table".getBytes()); //disable the table admin.deleteTable("table".getBytes()); //drop the tbale } } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.
本文地址:http://www.bhae.cn/html/933b4199025.html
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。