zoukankan      html  css  js  c++  java
  • Hbase API 写入操作代码,基于hbase-client 1.0.3版本

        <dependency>
          <groupId>org.apache.hbase</groupId>
          <artifactId>hbase-client</artifactId>
          <version>1.0.3</version>
        </dependency>
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.TableName;
    import org.apache.hadoop.hbase.client.BufferedMutator;
    import org.apache.hadoop.hbase.client.BufferedMutatorParams;
    import org.apache.hadoop.hbase.client.Connection;
    import org.apache.hadoop.hbase.client.ConnectionFactory;
    import org.apache.hadoop.hbase.client.Put;
    import org.apache.hadoop.hbase.client.Table;
    import org.apache.hadoop.hbase.util.Bytes;
    import java.io.IOException;
    
    public class HbaseTest01 {
        public static void main(String[] args) throws IOException{
            TableName name = TableName.valueOf("testtable");
            Configuration conf = HBaseConfiguration.create();
            Connection connection = ConnectionFactory.createConnection(conf);
            Table table = connection.getTable(name);
            
            BufferedMutator mutator = connection.getBufferedMutator(name);
            
            for (int i = 0; i < 1000000; i++){
                
                String rowStr = "row"+i;
                String valStr = "val"+i;
                
                Put put = new Put(Bytes.toBytes(rowStr));
                put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), Bytes.toBytes(valStr));
                
                mutator.mutate(put);
            }
            
            mutator.close();
            table.close();
            connection.close(); 
            System.out.println("done!");
        }
    }
  • 相关阅读:
    git技能
    iOS 命名规则
    iOS crash 报错类型
    iOS 面试相关
    【转】app后端如何选择合适的数据库产品
    App的token机制
    【转】Spring注解详解
    spring mvc ModelAndView 404的原因
    ibatis 环境搭建(1)
    Android中的Selector的用法
  • 原文地址:https://www.cnblogs.com/zhengchunhao/p/5684111.html
Copyright © 2011-2022 走看看