zoukankan      html  css  js  c++  java
  • Hbase之更新单条数据

    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.TableName;
    import org.apache.hadoop.hbase.client.*;
    import org.apache.hadoop.hbase.util.Bytes;
    import java.io.IOException;
    
    /**
     * 修改数据
     */
    public class MutateDataSingle {
        public static void main(String[] args) throws IOException{
            Configuration configuration = HBaseConfiguration.create();
            Connection connection = ConnectionFactory.createConnection(configuration);
            //建立表的连接
            Table table = connection.getTable(TableName.valueOf("testtable"));
            //获取put实例
            Put put = new Put(Bytes.toBytes("10086"));
            put.addColumn(Bytes.toBytes("colfam1"),Bytes.toBytes("qual1"),4,Bytes.toBytes("china mobile 1"));
            put.addColumn(Bytes.toBytes("colfam1"),Bytes.toBytes("qual4"),4,Bytes.toBytes("china mobile 4"));
            //删除
            Delete delete = new Delete(Bytes.toBytes("10086"));
            delete.addColumn(Bytes.toBytes("colfam1"),Bytes.toBytes("qual1"));
            //更新实例
            RowMutations mutations = new RowMutations(Bytes.toBytes("10086"));
            mutations.add(put);
            mutations.add(delete);
            table.mutateRow(mutations);
        }
    }
    //olddata
    /**
     10086                                           column=colfam1:qual1, timestamp=1471836722159, value=xE4xB8xADxE5x9BxBDxE7xA7xBBxE5x8AxA8
     */
    //newdata
    /**
     10086                                           column=colfam1:qual1, timestamp=4, value=china mobile 1                                                                                      
     10086                                           column=colfam1:qual4, timestamp=4, value=china mobile 4    
    **/
    
  • 相关阅读:
    L1-031 到底是不是太胖了
    L1-030 一帮一
    PyCharm--git配置
    websocket--python
    UDP--python
    TCP--python
    pytest--metadata
    pytest--xdist
    pytest--夹具
    pytest--变量
  • 原文地址:https://www.cnblogs.com/similarface/p/5798556.html
Copyright © 2011-2022 走看看