zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    ObjectC&&Swift 渐变色算法实现
    【iOS数据存储】iOS文件系统介绍
    1 、Quartz 2D绘图基础
    iOS 常用框架列表
    【Foundation Frame】Struct
    【Foundation Frame】NSMutableArray
    【Foundation Frame】NSDictionary/NSMutableDictionary
    【Foundation Frame】NSString
    【Foundation Frame】NSArray
    在vue项目中使用自己封装的ajax
  • 原文地址:https://www.cnblogs.com/stevensfollower/p/9806428.html
Copyright © 2011-2022 走看看