Hbase Java API (DDL DML)

本文介绍HBase Java API的基本使用方法,包括表的增删改查操作及数据的读写,同时涵盖过滤器的使用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Hbase Java API

package com.hbase.api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.*;
import org.apache.hadoop.hbase.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * @description: Hbase Java API 常用 DDL DML 操作
 * @author: Mr.zhou
 * @version: Hbase-client : 1.2.0-cdh5.14.0
 */
public class HbaseClient {
    private static Connection connection = null;
    private static Admin admin = null;

    private static Logger logger = LoggerFactory.getLogger(HbaseClient.class);
    //创建表的操作连接  使用静态代码块进行加载一次
    static {
        try {
            //1:获取Hbase配置
            Configuration configuration = HBaseConfiguration.create();
            //指定ZK的Host 访问Hbase不需要访问HMaster地址 可在
            configuration.set("hbase.zookeeper.quorum", "node1:2181,node2:2181,node3:2181");

            //2:获取Hbase客户端连接
            connection = ConnectionFactory.createConnection(configuration);
            //3:创建admain对象 进行DDL操作 表的创建 删除 修改等操作
            admin = connection.getAdmin();
        } catch (IOException e) {
            logger.info("获取hbase连接失败!", e.getMessage());
        }
    }

    //todo 1 :判断表是否存在
    @SuppressWarnings("all")
    public static boolean isTableExist(String tableName) throws IOException {

        return admin.tableExists(TableName.valueOf(tableName));
    }

    //todo 2: 创建表 存在 多个列族
    @SuppressWarnings("all")
    public static void createTable(String tableName, String... columFamilys) throws IOException {
        //判断列族是否传递
        if (columFamilys.length <= 0) {
            logger.info("创建表时至少需要一个列族");
            return;
        }
        //判断表是否已存在
        if (isTableExist(tableName)) {
            logger.info("表已存在!");
            return;
        }
        //创建表描述器
        HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName));
        for (String columFamily : columFamilys) {
            //列族描述器
            HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(columFamily);
            //给表添加列族 可添加多个
            tableDescriptor.addFamily(hColumnDescriptor);
        }
        //创建表
        admin.createTable(tableDescriptor);
    }

    //todo 3: 删除表

    public static void dropTable(String tableName) throws IOException {
        //删除表之前需先禁用表
        admin.disableTable(TableName.valueOf(tableName));
        admin.deleteTable(TableName.valueOf(tableName));
    }

    //todo: 创建命名空间
    public static void createNameSpace(String spaceName) throws IOException {
        //需先创建控件描述器
        NamespaceDescriptor descriptor = NamespaceDescriptor.create(spaceName).build();
        admin.createNamespace(descriptor);
    }

    /**
     * todo :   对表的CRUD
     *
     * @param
     * @throws Exception
     */

    //todo :插入数据
    @SuppressWarnings("all")
    public static void putData(String tableName) throws Exception {
        Table tb = null;
        try {
            //获取表的对象
            tb = connection.getTable(TableName.valueOf(tableName));
            //获取Put对象 并指定rowKey
            Put put = new Put(Bytes.toBytes("0001"));
            //添加列族:列 值
            put.addColumn("f1".getBytes(), "id".getBytes(), "1".getBytes(StandardCharsets.UTF_8));
            put.addColumn("f1".getBytes(), "name".getBytes(), "Tony".getBytes(StandardCharsets.UTF_8));
            put.addColumn("f1".getBytes(), "age".getBytes(), Bytes.toBytes("20"));

            //给第二个列族 添加value
            put.addColumn("f2".getBytes(), "address".getBytes(), "Japan".getBytes(StandardCharsets.UTF_8));
            put.addColumn("f2".getBytes(), "phone".getBytes(), Bytes.toBytes("15888888888"));
            //执行写入操作
            tb.put(put);
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("插入数据失败 {}" + tableName);
        } finally {
            if (tb != null) {
                //释放资源
                tb.close();
            }
        }
    }

    //todo :批量插入数据
    @SuppressWarnings("all")
    public static void batchPut(String tableName) throws Exception {
        //获取表
        Table myuserTb = null;
        try {
            myuserTb = connection.getTable(TableName.valueOf(tableName));
            //创建Put对象 指定rowKey
            Put put = new Put("0002".getBytes());
            put.addColumn("f1".getBytes(), "id".getBytes(), Bytes.toBytes("2"));
            put.addColumn("f1".getBytes(), "name".getBytes(), Bytes.toBytes("曹操"));
            put.addColumn("f1".getBytes(), "age".getBytes(), Bytes.toBytes("30"));
            put.addColumn("f2".getBytes(), "sex".getBytes(), Bytes.toBytes("1"));
            put.addColumn("f2".getBytes(), "address".getBytes(), Bytes.toBytes("沛国谯县"));
            put.addColumn("f2".getBytes(), "phone".getBytes(), Bytes.toBytes("16888888888"));
            put.addColumn("f2".getBytes(), "say".getBytes(), Bytes.toBytes("helloworld"));

            Put put2 = new Put("0003".getBytes());
            put2.addColumn("f1".getBytes(), "id".getBytes(), Bytes.toBytes("3"));
            put2.addColumn("f1".getBytes(), "name".getBytes(), Bytes.toBytes("刘备"));
            put2.addColumn("f1".getBytes(), "age".getBytes(), Bytes.toBytes("32"));
            put2.addColumn("f2".getBytes(), "sex".getBytes(), Bytes.toBytes("1"));
            put2.addColumn("f2".getBytes(), "address".getBytes(), Bytes.toBytes("幽州涿郡涿县"));
            put2.addColumn("f2".getBytes(), "phone".getBytes(), Bytes.toBytes("17888888888"));
            put2.addColumn("f2".getBytes(), "say".getBytes(), Bytes.toBytes("talk is cheap , show me the code"));


            Put put3 = new Put("0004".getBytes());
            put3.addColumn("f1".getBytes(), "id".getBytes(), Bytes.toBytes("4"));
            put3.addColumn("f1".getBytes(), "name".getBytes(), Bytes.toBytes("孙权"));
            put3.addColumn("f1".getBytes(), "age".getBytes(), Bytes.toBytes("35"));
            put3.addColumn("f2".getBytes(), "sex".getBytes(), Bytes.toBytes("1"));
            put3.addColumn("f2".getBytes(), "address".getBytes(), Bytes.toBytes("下邳"));
            put3.addColumn("f2".getBytes(), "phone".getBytes(), Bytes.toBytes("12888888888"));
            put3.addColumn("f2".getBytes(), "say".getBytes(), Bytes.toBytes("what are you 弄啥嘞!"));

            Put put4 = new Put("0005".getBytes());
            put4.addColumn("f1".getBytes(), "id".getBytes(), Bytes.toBytes("5"));
            put4.addColumn("f1".getBytes(), "name".getBytes(), Bytes.toBytes("诸葛亮"));
            put4.addColumn("f1".getBytes(), "age".getBytes(), Bytes.toBytes("28"));
            put4.addColumn("f2".getBytes(), "sex".getBytes(), Bytes.toBytes("1"));
            put4.addColumn("f2".getBytes(), "address".getBytes(), Bytes.toBytes("四川隆中"));
            put4.addColumn("f2".getBytes(), "phone".getBytes(), Bytes.toBytes("14888888888"));
            put4.addColumn("f2".getBytes(), "say".getBytes(), Bytes.toBytes("出师表你背了嘛"));

            Put put5 = new Put("0006".getBytes());
            put5.addColumn("f1".getBytes(), "id".getBytes(), Bytes.toBytes("6"));
            put5.addColumn("f1".getBytes(), "name".getBytes(), Bytes.toBytes("司马懿"));
            put5.addColumn("f1".getBytes(), "age".getBytes(), Bytes.toBytes("27"));
            put5.addColumn("f2".getBytes(), "sex".getBytes(), Bytes.toBytes("1"));
            put5.addColumn("f2".getBytes(), "address".getBytes(), Bytes.toBytes("哪里人有待考究"));
            put5.addColumn("f2".getBytes(), "phone".getBytes(), Bytes.toBytes("15888888888"));
            put5.addColumn("f2".getBytes(), "say".getBytes(), Bytes.toBytes("跟诸葛亮死掐"));


            Put put6 = new Put("0007".getBytes());
            put6.addColumn("f1".getBytes(), "id".getBytes(), Bytes.toBytes("7"));
            put6.addColumn("f1".getBytes(), "name".getBytes(), Bytes.toBytes("xiaobubu—吕布"));
            put6.addColumn("f1".getBytes(), "age".getBytes(), Bytes.toBytes("28"));
            put6.addColumn("f2".getBytes(), "sex".getBytes(), Bytes.toBytes("1"));
            put6.addColumn("f2".getBytes(), "address".getBytes(), Bytes.toBytes("内蒙人"));
            put6.addColumn("f2".getBytes(), "phone".getBytes(), Bytes.toBytes("15788888888"));
            put6.addColumn("f2".getBytes(), "say".getBytes(), Bytes.toBytes("貂蝉去哪了"));

            ArrayList<Put> listPut = new ArrayList<>();
            //将put对象装入list
            listPut.add(put);
            listPut.add(put2);
            listPut.add(put3);
            listPut.add(put4);
            listPut.add(put5);
            listPut.add(put6);

            //批量插入数据
            myuserTb.put(listPut);
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("批量插入数据失败 {}" + tableName);
        } finally {
            if (myuserTb != null) {
                myuserTb.close();
            }
        }
    }

    /**
     * todo :根据rowkey查询数据
     *
     * @param tableName rowKey
     * @throws Exception
     */
    @SuppressWarnings("all")
    public static void getDataByRowKey(String tableName, String rowKey) {
        Table MyuserTable = null;
        try {
            //获取表对象
            MyuserTable = connection.getTable(TableName.valueOf(tableName));
            //创建Get对象
            Get get = new Get(rowKey.getBytes());
            //Get 查询数据
            Result result = MyuserTable.get(get);
            //从结果中获取Cell(每个value就是一个cell)
            Cell[] cells = result.rawCells();
            if (cells.length < 1) {
                System.out.println("未查询到数据");
            }
            for (Cell cell : cells) {
                //取出cell中的数据
                //取出rowkey
                System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("查询数据异常!", e.getMessage());
        } finally {
            if (MyuserTable != null) {
                try {
                    MyuserTable.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    logger.info("释放表异常");
                }
            }
        }
    }

    /**
     * todo :查询指定列族:列 数据
     *
     * @param tableName
     * @param rowKey
     * @param columFamily
     * @param qualifilter
     */
    @SuppressWarnings("all")
    public static void getColumnFamily(String tableName, String rowKey, String columFamily, String qualifilter) {
        Table myuserTable = null;
        try {
            //获取表对象
            myuserTable = connection.getTable(TableName.valueOf(tableName));
            //创建Get对象 并指定RowKey
            Get get = new Get(Bytes.toBytes(rowKey));
            //指定对应的列族:列
            get.addColumn(columFamily.getBytes(), qualifilter.getBytes());
            //get查询
            Result result = myuserTable.get(get);
            //也可直接获取指定列族:列
            // List<Cell> columnCells = result.getColumnCells(columFamily.getBytes(), qualifilter.getBytes());
            Cell[] cells = result.rawCells();
            if (cells.length < 1) {
                System.out.println("没有查询导数据");
                logger.info("表 {},行键 {},列族 {},列 {}" + tableName, rowKey, columFamily, qualifilter);
            }
            for (Cell cell : cells) {
                //取出cell中的数据
                //取出rowkey
                System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("获取数据失败");
        } finally {
            if (myuserTable != null) {
                try {
                    myuserTable.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    logger.info("关闭表失败");
                }
            }
        }
    }

    /**
     * todo : 扫描指定rowkey 范围 左闭右开
     *
     * @param tableName
     * @param startRowKey
     * @param endRowKey
     */
    @SuppressWarnings("all")
    public static void getRowKeyRange(String tableName, String startRowKey, String endRowKey) {
        Table myuserTable = null;
        ResultScanner scannerResult = null;
        try {
            //获取表的连接
            myuserTable = connection.getTable(TableName.valueOf(tableName));
            //创建get对象
            Scan scan = new Scan();
            //设置起始RowKey
            scan.setStartRow(Bytes.toBytes(startRowKey));
            //左闭右开 结束RowKey
            scan.setStopRow(Bytes.toBytes(endRowKey));
            //扫描表 返回扫描的结果扫描器
            scannerResult = myuserTable.getScanner(scan);
            //获取扫描接过迭代器 每行数据一个result
            Iterator<Result> iterator = scannerResult.iterator();
            while (iterator.hasNext()) {
                Result result = iterator.next();
                if (result == null) {
                    System.out.println("扫描失败");
                }
                //获取数据 cell
                Cell[] cells = result.rawCells();
                if (cells.length < 1) {
                    System.out.println("未查询到数据");
                }
                for (Cell cell : cells) {
                    //取出cell中的数据
                    //取出rowkey
                    System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                    System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                    System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                    System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("扫描范围失败!");
        } finally {
            if (myuserTable != null) {
                try {
                    myuserTable.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    logger.info("关闭表失败!");
                }
            }
            if (scannerResult != null) {
                scannerResult.close();
            }
        }
    }

    /**
     * todo: 全表扫描
     * @param tableName
     */
    public static void getScan(String tableName){
        Table myuserTable = null;
        Scan scan = null;
        try {
            //获取表对象
             myuserTable = connection.getTable(TableName.valueOf(tableName));
            //通过table对象获取一个扫描器对象
            scan = new Scan();
            ResultScanner resultScanner = myuserTable.getScanner(scan);
            for (Result result : resultScanner) {
                Cell[] cells = result.rawCells();
                for (Cell cell : cells) {
                    //取出cell中的数据
                    //取出rowkey
                    System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                    System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                    System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                    System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("扫描失败!");
        } finally {
            if (myuserTable != null){
                try {
                    myuserTable.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    logger.info("关表失败!");
                }
            }
        }
    }

    /**
     * 删除指定rowkey
     * @param tableName
     * @param rowKey
     */
    public static void deleteRowKey(String tableName,String rowKey){
        Table myuserTable = null;
        try {
            //获取表对象
             myuserTable = connection.getTable(TableName.valueOf(tableName));
            //删除指定rowkey
            Delete delete = new Delete(rowKey.getBytes());
            //执行删除操作
            myuserTable.delete(delete);
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("删除失败!");
        }finally {
            if (myuserTable != null){
                try {
                    myuserTable.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    logger.info("关表失败!");
                }
            }
        }
    }

    /**
     *  todo :  过滤器查询数据
     * @param tableName
     */
    public static void rowKeyFilter(String tableName,String rowKey){
        //获取表对象
        Table myUserName = null;
        ResultScanner scanner = null;
        try {
            myUserName = connection.getTable(TableName.valueOf(tableName));
            Scan scan = new Scan();
            //创建一个rowkey过滤器
            // LESS_OR_EQUAL <=    BinaryComparator:按字节索引顺序比较指定字节数组,采用Bytes.compareTo(byte[])
            RowFilter rowFilter = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL, new BinaryComparator(Bytes.toBytes(rowKey)));
            //给扫描器添加过滤器
            scan.setFilter(rowFilter);
            scanner = myUserName.getScanner(scan);
            for (Result result : scanner) {
                Cell[] cells = result.rawCells();
                for (Cell cell : cells) {
                    //取出cell中的数据
                    //取出rowkey
                    System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                    System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                    System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                    System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("扫描失败");
        } finally {
            if (myUserName != null){
                try {
                    myUserName.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (scanner != null){
                scanner.close();
            }
        }
    }

    /**
     * todo:列族过滤器 SubstringComparator 判断提供的子串是否出现在value中。
     * @param tableName
     * @param family
     */
   public static void familyFilter(String tableName,String family){
       Table table = null;
       ResultScanner scanner = null;

       try {
           //获取表的对象
            table = connection.getTable(TableName.valueOf(tableName));
           Scan scan = new Scan();
           //查找比f2列族小的  只有f1列族 CompareOp.LESS <
           FamilyFilter familyFilter = new FamilyFilter(CompareFilter.CompareOp.LESS, new SubstringComparator(family));
           scan.setFilter(familyFilter);
            scanner = table.getScanner(scan);
           for (Result result : scanner) {
               Cell[] cells = result.rawCells();
               for (Cell cell : cells) {
                   //取出cell中的数据
                   //取出rowkey
                   System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                   System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                   System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                   System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
               }
           }
       } catch (IOException e) {
           e.printStackTrace();
       } finally {
           if (table != null ){
               try {
                   table.close();
               } catch (IOException e) {
                   e.printStackTrace();
               }
           }
           if (scanner != null) {
               scanner.close();
           }
       }
   }

    /**
     * 列过滤器
     * @param tableName
     * @param qualifier
     */
   public static void qualifierFilter(String tableName,String qualifier){
       //获取表对象
       Table table = null;
       ResultScanner scanner = null;
       try {
            table = connection.getTable(TableName.valueOf(tableName));
           Scan scan = new Scan();
           //CompareOp.EQUAL "="   SubstringComparator:判断提供的子串是否出现在value中。
           QualifierFilter qualifierFilter = new QualifierFilter(CompareFilter.CompareOp.EQUAL, new SubstringComparator(qualifier));
           scan.setFilter(qualifierFilter);
            scanner = table.getScanner(scan);
           for (Result result : scanner) {
               Cell[] cells = result.rawCells();
               for (Cell cell : cells) {
                   //取出cell中的数据
                   //取出rowkey
                   System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                   System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                   System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                   System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
               }
           }
       } catch (IOException e) {
           e.printStackTrace();
           logger.info("过滤失败!");
       } finally {
           if (table != null){
               try {
                   table.close();
               } catch (IOException e) {
                   e.printStackTrace();
               }
           }
           if (scanner != null){
               scanner.close();
           }
       }
   }

    /**
     *  todo 15.专用过滤器--单列值过滤器 SingleColumnValueFilter
     *     会返回满足条件的整列值的所有字段
     * @param tableName
     */
    public static void singleColumnFilter(String tableName){
        Table table = null;
        ResultScanner scanner = null;
        try {
            table = connection.getTable(TableName.valueOf(tableName));
            Scan scan = new Scan();
            //过滤出 指定列族:列 值  满足与值相关的列都会扫描出来
            SingleColumnValueFilter singleColumnValueFilter = new SingleColumnValueFilter("f1".getBytes(), "name".getBytes(), CompareFilter.CompareOp.EQUAL, "刘备".getBytes());
            scan.setFilter(singleColumnValueFilter);
             scanner = table.getScanner(scan);
            for (Result result : scanner) {
                Cell[] cells = result.rawCells();
                for (Cell cell : cells) {
                    //取出cell中的数据
                    //取出rowkey
                    System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                    System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                    System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                    System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("过滤失败!");
        } finally {
            if (table != null){
                try {
                    table.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (scanner != null){
                scanner.close();
            }
        }
    }

    public static void rowKeyPrefixFilter(String tableName,String rowKeyPrefix){
        //获取表对象
        Table table =null;
        ResultScanner scanner = null;
        try {
             table = connection.getTable(TableName.valueOf(tableName));
            Scan scan = new Scan();
            //rowKey前缀
            PrefixFilter prefixFilter = new PrefixFilter(rowKeyPrefix.getBytes());
            scan.setFilter(prefixFilter);
            scanner = table.getScanner(scan);
            for (Result result : scanner) {
                Cell[] cells = result.rawCells();
                for (Cell cell : cells) {
                    //取出cell中的数据
                    //取出rowkey
                    System.out.println("rowKey: " + Bytes.toString(CellUtil.cloneRow(cell)));
                    System.out.println("列族 :" + Bytes.toString(CellUtil.cloneFamily(cell)));
                    System.out.println("列 :" + Bytes.toString(CellUtil.cloneQualifier(cell)));
                    System.out.println("值 :" + Bytes.toString(CellUtil.cloneValue(cell)));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (table != null){
                try {
                    table.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (scanner != null){
                scanner.close();
            }
        }
    }


    public static void main(String[] args) throws Exception {
        boolean myuser = isTableExist("myuser");
        System.out.println(myuser);

        //创建表
        //HbaseClient.createTable("user1", "info","name");
        //删除表
        //HbaseClient.dropTable("user1");
        //创建命名空间
        // HbaseClient.createNameSpace("wentao");
        //单个插入数据
        // putData("myuser");
        //批量插入
        // HbaseClient.batchPut("myuser");
        //根据rowKey 获取 get数据
        //HbaseClient.getDataByRowKey("myuser", "0001");
        //根据列族:列查询数据
        // HbaseClient.getColumnFamily("myuser", "0001", "f1", "name");
        //扫描指定范围RowKey 返回的是0001-0002 左闭右开
        //HbaseClient.getRowKeyRange("myuser", "0001", "0003");
        //全表扫描
       // HbaseClient.getScan("myuser");
        //删除指定rowkey
        //HbaseClient.deleteRowKey("t_user", "004");
        //添加过滤器进行扫描 <= 0004 rowKey 都会被扫描出来
       // HbaseClient.rowKeyFilter("myuser", "0004");
        //列族过滤器
      //  HbaseClient.familyFilter("myuser", "f2");
        //列过滤器
       // HbaseClient.qualifierFilter("myuser", "name");
        //单列值过滤器
       // HbaseClient.singleColumnFilter("myuser");
        //rowKey前缀过滤器
        HbaseClient.rowKeyPrefixFilter("myuser", "00");

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值