2024年大数据最新hbase 总结,学习大数据开发开发的步骤

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  1. 表:HBase采用表来组织数据,表由行和列组成,列划分为若干个列族;
  2. 行:每个HBase表都由若干行组成,每个行由行键(row key)来标识;
  3. 列族:一个HBase表被分组成许多“列族”(Column Family)的集合,它是基本的访问控制单元,创建表的时候创建;
  4. 列限定符:列族里的数据通过列限定符(或列)来定位;
  5. 单元格:在HBase表中,通过行、列族和列限定符确定一个“单元格”(cell);
  6. 时间戳:每个单元格都保存着同一份数据的多个版本,这些版本采用时间戳进行索引;

hbase-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://mycluster/hbase</value>
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>xiemeng-01,xiemeng-02,xiemeng-03,xiemeng-04</value>
    </property>
    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/home/xiemeng/software/hadoop-3.2.0/app/apache-zookeeper-3.5.8-bin/data</value>
    </property>
    <property>
        <name>hbase.tmp.dir</name>
        <value>/home/xiemeng/software/hbase-2.2.6/tmp</value>
    </property>
</configuration>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>${hbase.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-server</artifactId>
            <version>${hbase.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-common</artifactId>
            <version>${hbase.version}</version>
        </dependency>
class StudentBean {

    private  Integer studentNo;

    private  String name;

    private  String studentName;

    private Integer studentAge;

}

/**
 * HBabse 测试类
 */
public class HBaseTest {
    /**
     * 获取连接对象
     * @return
     * @throws IOException
     */
    private static  Connection connection = null;

    /**
     * 日志类
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(HBaseTest.class);

    /**
     * 获取连接
     * @return
     * @throws IOException
     */
    public static Connection getConnection() throws IOException {
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.zookeeper.property.clientPort","2181");
        configuration.set("hbase.zookeeper.quorum","192.168.64.128,192.168.64.130,192.168.64.131,192.168.64.133");
        configuration.set("hbase.master","192.168.64.128:16010");
        synchronized(HBaseTest.class){
            if(null==connection){
              connection = ConnectionFactory.createConnection(configuration);
            }
        }

        return  connection;
    }

    /**
     * 创建表
     * @param tableName
     * @param cols
     * @throws IOException
     */
    public static void createTable(String tableName,String [] cols) throws IOException {
        TableName name = TableName.valueOf(tableName);
        Admin admin = getConnection().getAdmin();
        if(admin.tableExists(name)){
            System.out.println("表已经存在");
        }else {
            TableDescriptorBuilder.ModifyableTableDescriptor descriptor = (TableDescriptorBuilder.ModifyableTableDescriptor) TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName)).build();
            for(String col: cols){
                ColumnFamilyDescriptor columnDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(col.getBytes()).build();
                descriptor.setColumnFamily(columnDescriptor);
            }
            admin.createTable(descriptor);
        }
    }

    /**
     * 插入数据
     * @param tableName
     * @param student
     * @throws IOException
     */
    public static  void  insert(String tableName, StudentBean student) throws IOException {
        Table table = getConnection().getTable(TableName.valueOf(tableName));
        Put put = new Put(("stu"+student.getStudentNo()).getBytes());
        put.addColumn("stu_name".getBytes(),"student_name".getBytes(),student.getStudentName().getBytes());
        put.addColumn("stu_name".getBytes(),"name".getBytes(),student.getStudentName().getBytes());
        put.addColumn("stu_age".getBytes(),"student_age".getBytes(),(""+student.getStudentAge()).getBytes());
        table.put(put);
    }

    public static List<String> getColumnFamilyNames(String tableName) throws IOException {
        Table table = getConnection().getTable(TableName.valueOf(tableName));
        TableDescriptor tableDescriptor = table.getDescriptor();
        List<String> columnFamilyNames = new ArrayList<>();
        for(ColumnFamilyDescriptor columnFamilyDescriptor :tableDescriptor.getColumnFamilies()){
            columnFamilyNames.add(columnFamilyDescriptor.getNameAsString());
        }
        return columnFamilyNames;
    }

    public static Set<String> getFamilyNames(String tableName) throws IOException {
        Table table = getConnection().getTable(TableName.valueOf(tableName));
        TableDescriptor descriptor = table.getDescriptor();
        Set<byte[]> familySet = descriptor.getColumnFamilyNames();
        Set<String> familyNameSet = familySet.stream().map(byteValue -> Bytes.toString(byteValue)).collect(Collectors.toSet());
        return familyNameSet;
    }



![img](https://img-blog.csdnimg.cn/img_convert/c3d625f8de8fd4256c0f0d3f41f1579c.png)
![img](https://img-blog.csdnimg.cn/img_convert/50d4e83228a97bb70d264dafc5cb65e7.png)
![img](https://img-blog.csdnimg.cn/img_convert/46f12bdb4341a91e7a9dd449ed3af185.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值