• Hortonwork Ambari配置Hive集成Hbase的java开发maven配置


    集群环境

    ambari 2.7.3

    hdp/hortonwork 2.6.0.3

    maven

     1     <dependency>
     2       <groupId>org.apache.hive</groupId>
     3       <artifactId>hive-jdbc</artifactId>
     4       <version>1.2.1000.2.6.0.3-8</version>
     5       <classifier>standalone</classifier>
     6     </dependency>
     7     <dependency>
     8       <groupId>org.apache.hbase</groupId>
     9       <artifactId>hbase-client</artifactId>
    10       <version>1.1.2.2.6.0.3-8</version>
    11     </dependency>

    代码

    package com.yingzi.com.dmh;
    
    import java.io.IOException;
    import java.net.URL;
    import java.sql.SQLException;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.sql.DriverManager;
    import java.util.Enumeration;
    //import org.apache.hadoop.hbase.client.Connection;
    
    
    public class HiveJdbcClient {
      private static String driverName = "org.apache.hive.jdbc.HiveDriver";
     
      public static void main(String[] args) throws SQLException {
        try {
          Class.forName(driverName);
        } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          System.exit(1);
        }
    
        ClassLoader classLoader = App.class.getClassLoader();
        Enumeration<URL> paths  = null;
        try {
          paths = classLoader.getResources("META-INF");
        } catch (IOException e) {
          e.printStackTrace();
        } finally {
        }
        int count = 0;
        while (paths.hasMoreElements()){
          String path = paths.nextElement().toString();
          if (path.indexOf("jdk") == -1){
            count++;
            System.out.println(path);
          }
        }
        System.out.println(count);
    
        //
        Connection con = DriverManager.getConnection("jdbc:hive2://hdfs03.yingzi.com:2181,hdfs04.yingzi.com:2181,hdfs05.yingzi.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2");
        Statement stmt = con.createStatement();
        ResultSet res = stmt.executeQuery("show databases");
        if (res.next()) {
          System.out.println(res.getString(1));
        }
        //create table
        String sql = "CREATE TABLE IF NOT EXISTS hbase_hive_table(key string, value string)
    " +
                "STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
    " +
                "WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:json")
    " +
                "TBLPROPERTIES ("hbase.table.name" = "hbase_hive_table")";
        System.out.println(sql);
        stmt.execute(sql);
      }
    }
    

      运行报错:

    org.apache.hive.service.cli.HiveSQLException: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/client/Connection

    解决办法:

    参考:https://docs.hortonworks.com/HDPDocuments/HDP3/HDP-3.0.1/hbase-data-access/content/hdag_configuring_hbase_and_hive.html

    ambari->hive->configs->advanced->Custom hive-site->addproperity

  • 相关阅读:
    [译] 11. 流复制
    [译] 8. PG缓冲区管理器(Buffer Manager)
    [译] 6. Vacuum 处理
    centos 7 安装gitlab
    linux 源码安装git
    SonarQube
    百度Paddle速查_CPU和GPU的mnist预测训练_模型导出_模型导入再预测_导出onnx并预测
    Torch速查_CPU和GPU的mnist预测训练_模型导出_模型导入再预测_导出script并预测_导出onnx并预测
    Mxnet速查_CPU和GPU的mnist预测训练_模型导出_模型导入再预测_导出onnx并预测
    Chainer速查_CPU和GPU的mnist预测训练_模型导出_模型导入再预测_导出onnx并预测
  • 原文地址:https://www.cnblogs.com/stevensfollower/p/9806428.html
Copyright © 2020-2023  润新知