最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于idea操作hbase數(shù)據(jù)庫(kù)并映射到hive表

 更新時(shí)間:2023年03月17日 10:18:14   作者:思達(dá)滴  
這篇文章主要介紹了用idea操作hbase數(shù)據(jù)庫(kù),并映射到hive,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

依賴條件:需要有Hadoop,hive,zookeeper,hbase環(huán)境

映射:每一個(gè)在 Hive 表中的域都存在于 HBase 中,而在 Hive 表中不需要包含所有HBase 中的列。HBase 中的 RowKey 對(duì)應(yīng)到 Hive 中為選擇一個(gè)域使用 :key 來(lái)對(duì)應(yīng),列族(cf:)映射到 Hive 中的其它所有域,列為(cf:cq)

配置映射環(huán)境

一:先關(guān)閉所有服務(wù)

[root@siwen ~]# stop-hbase.sh -----關(guān)閉hbase

[root@siwen ~]# zkServer.sh stop -----關(guān)閉zookeeper

[root@siwen ~]# stop-alll.sh -----關(guān)閉hadoop

二:配置文件

1,修改host文件:

C:\Windows\System32\drivers\etc在此目錄下的hosts文件把此機(jī)器的ip和hostname加入進(jìn)去

2,修改hive-site.xml

[root@siwen ~]# cd /opt/soft/hive312/conf/

[root@siwen conf]# vim ./hive-site.xml

加入下面幾行

  <property>
    <name>hive.zookeeper.quorum</name>
    <value>192.168.255.159</value>
  </property>
  <property>
    <name>hbase.zookeeper.quorum</name>
    <value>192.168.255.159</value>
  </property>
  <property>
    <name>hive.aux.jars.path</name>
    <value>file:///opt/soft/hive312/lib/hive-hbase-handler-3.1.2.jar,file:///opt/soft/hive312/lib/zookeeper-3.4.6.jar,file:///opt/soft/hive312/lib/hbase-client-2.3.5.jar,file:///opt/soft/hive312/lib/hbase-common-2.3.5-tests.jar,file:///opt/soft/hive312/lib/hbase-server-2.3.5.jar,file:///opt/soft/hive312/lib/hbase-common-2.3.5.jar,file:///opt/soft/hive312/lib/hbase-protocol-2.3.5.jar,file:///opt/soft/hive312/lib/htrace-core-3.2.0-incubating.jar</value>
  </property>

3,拷貝jar包

①將hbase235/lib目錄下所有的jar包都拷貝到hive下面

[root@siwen conf]# cp /opt/soft/hbase235/lib/* /opt/soft/hive312/lib/

是否覆蓋內(nèi)容的時(shí)候,可以輸入n,不覆蓋;或者覆蓋了也沒(méi)問(wèn)題

②統(tǒng)一guava文件

[root@siwen lib]# find ../lib/guava* -------查看所有的guava文件

[root@siwen lib]# rm -rf ../lib/guava-11.0.2.jar -------刪除11版本的

[root@siwen conf]# cd /opt/soft/hbase235/lib/
[root@siwen lib]# pwd
/opt/soft/hbase235/lib

[root@siwen lib]# cp /opt/soft/hive312/lib/guava-27.0-jre.jar ./ -----把hive的guava文件拷貝給hbase

三:?jiǎn)?dòng)服務(wù)

#啟動(dòng)hadoop
[root@siwen lib]# start-all.sh
#啟動(dòng)zookeeper
[root@siwen lib]# zkServer.sh start
#啟動(dòng)hbase
[root@siwen lib]# start-hbase.sh
#啟動(dòng)hive
[root@siwen lib]# nohup hive --service metastore &
[root@siwen lib]# nohup hive --service hiveserver2 &

開(kāi)始使用idea創(chuàng)建maven工程

在pom.xml 里面添加依賴

<dependency>
      <groupId>org.apache.hbase</groupId>
      <artifactId>hbase-client</artifactId>
      <version>2.3.5</version>
    </dependency>
    <dependency>
      <groupId>org.apache.hbase</groupId>
      <artifactId>hbase-server</artifactId>
      <version>2.3.5</version>
    </dependency>

1,編寫(xiě)初始化方法:配置hbase信息,連接數(shù)據(jù)庫(kù)

    //定義一個(gè)config,用于獲取配置對(duì)象
    static Configuration config = null;
    //獲取連接
    private Connection conn = null;
    Admin admin = null;
 
    @Before
    public void init() throws IOException {
        //配置hbase信息,連接hbase數(shù)據(jù)庫(kù)
        config = HBaseConfiguration.create();
        config.set(HConstants.HBASE_DIR, "hdfs://192.168.255.159:9000/hbase");
        config.set(HConstants.ZOOKEEPER_QUORUM, "192.168.255.159");
        config.set(HConstants.CLIENT_PORT_STR, "2181");
        //hbase連接工廠
        conn = ConnectionFactory.createConnection(config);
        //拿到admin
        admin = conn.getAdmin();
    }

2,編寫(xiě)關(guān)閉方法

    @After
    public void close() throws IOException {
        System.out.println("執(zhí)行close()方法");
        if (admin!=null)
            admin.close();
        if (conn!=null)
            conn.close();
    }

3,編寫(xiě)創(chuàng)建命名空間方法

    @Test
    public void createNameSpace() throws IOException {
        NamespaceDescriptor bigdata = NamespaceDescriptor.create("bigdata").build();
        #執(zhí)行創(chuàng)建對(duì)象
        admin.createNamespace(bigdata); 
    }

4,編寫(xiě)創(chuàng)建表的方法

    @Test
    public void createTable() throws IOException {
        //創(chuàng)建表的描述類
        TableName tableName = TableName.valueOf("bigdata:student");
        //獲取表格描述器
        HTableDescriptor desc = new HTableDescriptor(tableName);
 
        //創(chuàng)建列族的描述,添加列族
        HColumnDescriptor family1 = new HColumnDescriptor("info1");
        HColumnDescriptor family2 = new HColumnDescriptor("info2");
        desc.addFamily(family1);
        desc.addFamily(family2);
 
        admin.createTable(desc);*/

5,編寫(xiě)查看表結(jié)構(gòu)的方法

    @Test
    public void getAllNamespace() throws IOException {
        List<TableDescriptor> tableDesc = admin.listTableDescriptorsByNamespace("bigdata".getBytes());
        System.out.println(tableDesc.toString());
    }

6,編寫(xiě)插入數(shù)據(jù)方法

   @Test
   public void insertData() throws IOException {
        //獲取表的信息
        Table table = conn.getTable(TableName.valueOf("bigdata:student"));
        //設(shè)置行鍵
        Put put = new Put(Bytes.toBytes("student1"));
        //設(shè)置列的標(biāo)識(shí)以及列值
        put.addColumn("info1".getBytes(), "name".getBytes(), "zs".getBytes());
        put.addColumn("info2".getBytes(), "school".getBytes(), "xwxx".getBytes());
        //執(zhí)行添加
        table.put(put);
 
        //使用集合添加數(shù)據(jù)
        Put put2 = new Put(Bytes.toBytes("student2"));
        put2.addColumn("info1".getBytes(), "name".getBytes(), "zss".getBytes());
        put2.addColumn("info2".getBytes(), "school".getBytes(), "xwxx".getBytes());
        Put put3 = new Put(Bytes.toBytes("student3"));
        put3.addColumn("info1".getBytes(), "name".getBytes(), "zsr".getBytes());
        put3.addColumn("info2".getBytes(), "school".getBytes(), "xwxx".getBytes());
        List<Put> list = new ArrayList<>();
        list.add(put2);
        list.add(put3);
        table.put(list);
    }

7,編寫(xiě)查詢指定數(shù)據(jù)的方法

    #查詢student1的信息
    @Test
    public void queryData() throws IOException {
        Table table = conn.getTable(TableName.valueOf("bigdata:student"));
        Get get = new Get(Bytes.toBytes("student1"));
        Result result = table.get(get);
        byte[] value = result.getValue(Bytes.toBytes("info1"), Bytes.toBytes("name"));
        System.out.println("姓名:"+Bytes.toString(value));
        value = result.getValue(Bytes.toBytes("info2"), Bytes.toBytes("school"));
        System.out.println("學(xué)校:"+Bytes.toString(value));
    }

8,編寫(xiě)掃描數(shù)據(jù)的方法(所有數(shù)據(jù))

    @Test
    public void scanData() throws IOException {
        Table table = conn.getTable(TableName.valueOf("kb21:student"));
        Scan scan = new Scan();
        ResultScanner scanner = table.getScanner(scan);
        for (Result result : scanner) {
            byte[] value = result.getValue(Bytes.toBytes("info1"), Bytes.toBytes("name"));
            System.out.println("姓名:"+Bytes.toString(value));
            value = result.getValue(Bytes.toBytes("info2"), Bytes.toBytes("school"));
            System.out.println("學(xué)校:"+Bytes.toString(value));
            System.out.println(Bytes.toString(result.getRow()));
        }
    }

9,編寫(xiě)刪除表的方法

     @Test
    public void deleteTable() throws IOException {
        //先禁用
        admin.disableTable(TableName.valueOf("bigdata:student"));
        //再刪除
        admin.deleteTable(TableName.valueOf("bigdata:student"));
    }

創(chuàng)建外部表

---------主要外部表的字段需要和Hbase中的列形成映射

create external table student(
    id string,
    name string,
    school string
)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with
serdeproperties ("hbase.columns.mapping"=":key,info1:name,info2:school")
tblproperties ("hbase.table.name"="bigdata:student");
select * from student

到此這篇關(guān)于用idea操作hbase數(shù)據(jù)庫(kù),并映射到hive的文章就介紹到這了,更多相關(guān)idea操作hbase數(shù)據(jù)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java?Socket實(shí)現(xiàn)聊天室功能

    Java?Socket實(shí)現(xiàn)聊天室功能

    這篇文章主要為大家詳細(xì)介紹了Java?Socket實(shí)現(xiàn)聊天室功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-09-09
  • Mybatis Generator逆向工程的使用詳細(xì)教程

    Mybatis Generator逆向工程的使用詳細(xì)教程

    這篇文章主要介紹了Mybatis Generator逆向工程的使用詳細(xì)教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-06-06
  • 一文教你如何更改IDEA已有項(xiàng)目的路徑/名稱

    一文教你如何更改IDEA已有項(xiàng)目的路徑/名稱

    由于IDEA項(xiàng)目路徑中有中文、空格等特殊符號(hào),影響正常使用,想要修改路徑名稱,怎么正確修改IDEA項(xiàng)目名稱,使其正常運(yùn)行呢?所以本文小編講給大家詳細(xì)的介紹了更改IDEA已有項(xiàng)目的路徑/名稱解決方案,需要的朋友可以參考下
    2023-11-11
  • Spring boot JPA實(shí)現(xiàn)分頁(yè)和枚舉轉(zhuǎn)換代碼示例

    Spring boot JPA實(shí)現(xiàn)分頁(yè)和枚舉轉(zhuǎn)換代碼示例

    這篇文章主要介紹了Spring boot JPA實(shí)現(xiàn)分頁(yè)和枚舉轉(zhuǎn)換代碼示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Java字符串中刪除指定子字符串的方法簡(jiǎn)介

    Java字符串中刪除指定子字符串的方法簡(jiǎn)介

    這篇文章主要介紹了Java字符串中刪除指定子字符串的方法,是Java入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-11-11
  • Java多線程通信:交替打印ABAB實(shí)例

    Java多線程通信:交替打印ABAB實(shí)例

    這篇文章主要介紹了Java多線程通信:交替打印ABAB實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • 基于slf4j日志MDC輸出格式的問(wèn)題

    基于slf4j日志MDC輸出格式的問(wèn)題

    這篇文章主要介紹了基于slf4j日志MDC輸出格式的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • uploadify java實(shí)現(xiàn)多文件上傳和預(yù)覽

    uploadify java實(shí)現(xiàn)多文件上傳和預(yù)覽

    這篇文章主要為大家詳細(xì)介紹了java結(jié)合uploadify實(shí)現(xiàn)多文件上傳和預(yù)覽的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Java instanceof用法詳解及實(shí)例代碼

    Java instanceof用法詳解及實(shí)例代碼

    這篇文章主要介紹了Java instanceof用法詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • 詳解Java中多線程異常捕獲Runnable的實(shí)現(xiàn)

    詳解Java中多線程異常捕獲Runnable的實(shí)現(xiàn)

    這篇文章主要介紹了詳解Java中多線程異常捕獲Runnable的實(shí)現(xiàn)的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家理解掌握這樣的知識(shí),需要的朋友可以參考下
    2017-10-10

最新評(píng)論

芜湖市| 监利县| 阿坝县| 武汉市| 汕头市| 华容县| 都江堰市| 曲松县| 武威市| 曲松县| 敖汉旗| 南江县| 肥西县| 舞钢市| 唐海县| 新乡市| 博罗县| 舟曲县| 镇平县| 和顺县| 泰来县| 依兰县| 平昌县| 耒阳市| 宁城县| 绥阳县| 博兴县| 南城县| 胶州市| 利川市| 商河县| 寻甸| 芒康县| 台北市| 庄浪县| 阜阳市| 临江市| 太康县| 临泽县| 怀仁县| 玉环县|