MapReduce操作HBase错误一例

应用开发2025-11-05 13:04:2516316
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
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

全站热门

三星S8国行信号表现如何?(国行三星S8信号稳定性评测与分析)

如何使Ubuntu用GNOME自带面板生成侧翼面板?

字节一面,MySQL 一行记录是怎么存储的

聊聊 Flink SQL增量查询Hudi表

智齿难拔的原因及处理方法(探索智齿难拔的原因以及有效的处理方法)

Ubuntu10.04上如何搭建iPhone开发环境?

数据血缘在安全大数据中的重要性

分布式数据库:如何保证数据在分布式场景下的高性能?

友情链接

滇ICP备2023000592号-9