zoukankan      html  css  js  c++  java
  • 大数据工具篇之Hive与MySQL整合完整教程

    大数据工具篇之Hive与MySQL整合完整教程

    一、引言

      Hive元数据存储可以放到RDBMS数据库中,本文以Hive与MySQL数据库的整合为目标,详细说明Hive与MySQL的整合方法。

    二、安装驱动

      MySQL最新的Java驱动版本为:mysql-connector-java-5.1.28-bin.jar,下载后拷贝到:Hive/Lib目录。

    三、安装MySQL

      3.1 版本

      RHEL5+mysql-5.5.35-1.i386.rpm

      3.2 顺序  

      MySQL-shared-compat-5.5.35-1.rhel15.i386.rpm

          MySQL-server-5.5.35-1.rhel5.i386.rpm

          MySQL-client-5.5.35-1.rhel5.i386.rpm

    四、配置文件

      修改Hive配置文件Hive-site.xml,修改后的结果如下所示:  

    复制代码
     1 <property>
     2   <name>javax.jdo.option.ConnectionURL</name>
     3   <value>jdbc:mysql://localhost:3306/hivedb?characterEncoding=UTF-8</value>
     4   <description>JDBC connect string for a JDBC metastore</description>
     5 </property>
     6 
     7 <property>
     8   <name>javax.jdo.option.ConnectionDriverName</name>
     9   <value>com.mysql.jdbc.Driver</value>
    10   <description>Driver class name for a JDBC metastore</description>
    11 </property>
    12 
    13 <property>
    14   <name>javax.jdo.PersistenceManagerFactoryClass</name>
    15   <value>org.datanucleus.jdo.JDOPersistenceManagerFactory</value>
    16   <description>class implementing the jdo persistence</description>
    17 </property>
    18 
    19 <property>
    20   <name>javax.jdo.option.DetachAllOnCommit</name>
    21   <value>true</value>
    22   <description>detaches all objects from session so that they can be used after transaction is committed</description>
    23 </property>
    24 
    25 <property>
    26   <name>javax.jdo.option.NonTransactionalRead</name>
    27   <value>true</value>
    28   <description>reads outside of transactions</description>
    29 </property>
    30 
    31 <property>
    32   <name>javax.jdo.option.ConnectionUserName</name>
    33   <value>root</value>
    34   <description>username to use against metastore database</description>
    35 </property>
    36 
    37 <property>
    38   <name>javax.jdo.option.ConnectionPassword</name>
    39   <value>root</value>
    40   <description>password to use against metastore database</description>
    41 </property>
    复制代码

    五、结果展示

      安装完成以后,通过访问mysql客户端,可以用来验证是否安装成功。注意与普通关系型数据创建表格后的区别。

      mysql>show tables;

    复制代码
     1 +----------------+
     2 | Tables_in_hive |
     3 +----------------+
     4 | BUCKETING_COLS |
     5 | COLUMNS |
     6 | DBS |
     7 | PARTITION_KEYS |
     8 | SDS |
     9 | SD_PARAMS |
    10 | SEQUENCE_TABLE |
    11 | SERDES |
    12 | SERDE_PARAMS |
    13 | SORT_COLS |
    14 | TABLE_PARAMS |
    15 | TBLS |
    16 +----------------+
    复制代码

     六、注意事项

      曾经有人单独找我咨询过这个问题:为何无法在Hive中指定使用哪个MySQL数据库?这里面有一个需要说明的地方是Hive的数据库的概念不同于RDBMS数据库,MySQL数据库的指定是基于配置文件的,但是Hive的数据库只是一个命名空间号,类似分组的概念。hive中的数据库可以在使用MySQL数据库中,通过Select * from DBS查看到。

    C++ Programming with TDD之一:GMOCK框架简介

     

    所谓测试驱动开发,英文全称Test-Driven Development,简称TDD,是一种不同于传统软件开发流程的新型的开发方法。就是在明确要开发某个功能后,首先思考如何对这个功能进行测试,并完成测试代码的编写,然后编写相关的代码满足这些测试用例。然后循环进行添加其他功能,直到完成全部功能的开发。

    Google Mock的设计灵感来源于jMock和EasyMock,它的作用是帮你快速地做出一个接口的仿制品。如果你的设计依赖其它的类,而这些类还没有完成或非常昂贵(如数据库);如果你要测试你的模块与其它模块是否能正确结合,并想了解其交互过程;那么Google Mock就能帮助你。

    PS: The official Google Mock site is https://code.google.com/p/googlemock/. The version used for building the examples is Google Mock 1.7.0.

    一、 环境配置

    gmock1.7.0中使用了C++11新标准,所以我们的编译器需要支持C++11才行,在Linux系统中,即需要安装GCC4.7/G++4.7,我的测试环境是Ubuntu12.04,默认安装的是GCC4.6/G++4.6,所以需要在安装编译gmock之前首先安装GCC4.7/G++4.7,这里也顺便把安装的过程加上,有需要的猿们可以参考:

    1

    1 sudo add-apt-repository ppa:ubuntu-toolchain-r/test
    2 sudo apt-get update
    3 sudo apt-get install gcc-4.7 g++-4.7

    安装成功后我们如果要使用gcc-4.7&g++-4.7来编译的话,我们就得把gcc改为gcc-4.7,g++同理,改为g++-4.7来进行编译.如果你想直接使用gcc-4.7而不改变编译时gcc改为gcc-4.7的话,我们就可以更改一下gcc的软链接:

    1 sudo rm /usr/bin/gcc
    2 sudo ln -s /usr/bin/gcc-4.7 /usr/bin/gcc
    3 sudo rm /usr/bin/g++
    4 sudo ln -s /usr/bin/g++-4.7 /usr/bin/g++

    PS: 在平时使用的时候如果使用C++0X标准,记得加-std=c++11。

    二、gmock安装

    下载好gmock之后,解压,然后切换到gmock源码所在目录,使用如下命令安装:

    1 mkdir mybuild
    2 cd mybuild
    3 cmake ..
    4 make

    同时,你还需要编译google test,其包含在gmock源码下的gtest文件夹,切换到gtest文件夹,然后用相同的方式安装即可。

    三、实例

    Soundex.h文件:

    复制代码
     1 #ifndef Soundex_h
     2 #define Soundex_h
     3 #include <string>
     4 
     5 class Soundex
     6 {
     7 public:
     8    std::string encode(const std::string& word) const {
     9       return zeroPad(word);
    10    }
    11 
    12 private:
    13    std::string zeroPad(const std::string& word) const {
    14       return word + "000";
    15    }
    16 };
    17 
    18 #endif
    复制代码

    SoundexTest.cpp文件:

    复制代码
     1 #include "gmock/gmock.h" 
     2 #include "Soundex.h"
     3 
     4 using namespace testing;
     5 
     6 class SoundexEncoding: public Test {
     7 public:
     8    Soundex soundex;
     9 };
    10 
    11 TEST_F(SoundexEncoding, RetainsSoleLetterOfOneLetterWord) {
    12    ASSERT_THAT(soundex.encode("A"), Eq("A000")); 
    13 }
    14 
    15 TEST_F(SoundexEncoding, PadsWithZerosToEnsureThreeDigits) {
    16    ASSERT_THAT(soundex.encode("I"), Eq("I000"));
    17 }
    复制代码

    main.cpp文件:

    复制代码
    1 #include "gmock/gmock.h"
    2 
    3 int main(int argc, char** argv) {
    4     testing::InitGoogleMock(&argc, argv);
    5     return RUN_ALL_TESTS();
    6 }
    复制代码

    CMakeLists.txt文件:

    复制代码
     1 project(chapterFirstExample)
     2 cmake_minimum_required(VERSION 2.6)
     3 
     4 include_directories($ENV{GMOCK_HOME}/include $ENV{GMOCK_HOME}/gtest/include)
     5 link_directories($ENV{GMOCK_HOME}/mybuild $ENV{GMOCK_HOME}/gtest/mybuild)
     6 add_definitions(-std=c++0x)
     7 set(CMAKE_CXX_FLAGS "${CMAXE_CXX_FLAGS} -Wall")
     8 
     9 set(sources 
    10    main.cpp 
    11    SoundexTest.cpp)
    12 add_executable(test ${sources})
    13 target_link_libraries(test pthread)
    14 target_link_libraries(test gmock)
    15 target_link_libraries(test gtest)
    复制代码

    好了,编译执行吧,执行结果如下:

    好了gmock的使用就介绍到这里,需要深入研究的童鞋可以参考官方文档。这里最重要的不是学会使用gmock,而是要在学会使用gmock之后养成TDD开发的好习惯.

    Test-driving vs Testing: Using a testing technique, you would seek to exhaustively analyze the specification in question (and possibly the code) and devise tests that exhaustively cover the behavior. TDD is instead a technique for driving the design of the code. In TDD, you write tests to describe the next behavior needed.

     

  • 相关阅读:
    VMware vSphere企业运维实战
    Unity 3D和2D手机游戏开发
    电商店铺装修推广教程
    uiiamgeview 设置圆角
    cgcolor regcolor tttatribute.
    谈待遇,
    不会自己 加的,也不会自己连线,
    代理,其他的类可以实现,而这个类不能实现,
    代理,
    TTTattribute 缺少 coretext
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3513947.html
Copyright © 2011-2022 走看看