• 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.client.coprocessor.Batch;
    import org.apache.hadoop.hbase.util.Bytes;
    import java.io.IOException;
    import java.util.List;
    import java.util.ArrayList;
    
    /**
     使用回调函数进行批处理操作
     */
    public class BatchOperationsWithCallbacks {
        public static void main(String[] args) throws IOException{
            Configuration configuration = HBaseConfiguration.create();
            Connection connection = ConnectionFactory.createConnection(configuration);
            //建立表的连接
            Table table = connection.getTable(TableName.valueOf("testtable"));
            List<Row> batch = new ArrayList<Row>();
            byte[] ROW= Bytes.toBytes("10000");
            byte[] ROW1=Bytes.toBytes("10000");
            byte[] ROW2=Bytes.toBytes("10000");
            byte[] COLFAM2=Bytes.toBytes("colfam1");
            byte[] COLFAM1=Bytes.toBytes("colfam1");
            byte[] QUAL1=Bytes.toBytes("company");
            byte[] QUAL2=Bytes.toBytes("company2");
            Put put = new Put(ROW2);
            put.addColumn(COLFAM2, QUAL1, 4, Bytes.toBytes("val5"));
            batch.add(put);
            Get get1 = new Get(ROW1);
            get1.addColumn(COLFAM1, QUAL1);
            batch.add(get1);
            Delete delete = new Delete(ROW1);
            delete.addColumns(COLFAM1, QUAL2);
            batch.add(delete);
            Get get2 = new Get(ROW2);
            get2.addFamily(Bytes.toBytes("BOGUS"));
            batch.add(get2);
            Object[] results = new Object[batch.size()];
            try {
                table.batchCallback(batch, results, new Batch.Callback<Result>() {
                    @Override
                    public void update(byte[] region, byte[] row, Result result) {
                        System.out.println("Received callback for row[" + Bytes.toString(row) + "] -> " + result);
                    } });
            } catch (Exception e) {
                System.err.println("Error: " + e);
            }
            for (int i = 0; i < results.length; i++) {
                System.out.println("Result[" + i + "]: type = " +
                        results[i].getClass().getSimpleName() + "; " + results[i]);
            }
    table.close();
    connection.close();
    } }
  • 相关阅读:
    VS2010之– Web Development(四)-将WebApplication打包发布到IIS
    .NET中TextBox控件设置ReadOnly=true后台取不到值三种解决方法
    jQuery 二级联动
    ajax实现无刷新两级联动DropDownList
    CheckStyle
    《Thinking in Java》学习笔记(三)
    Java垃圾回收机制[转]
    《Thinking in Java》学习笔记(二)
    MySQL操作的一些优化
    《Thinking in Java》学习笔记(一)
  • 原文地址:https://www.cnblogs.com/similarface/p/5799379.html
Copyright © 2020-2023  润新知