玩转大数据计算之Hive

2017-07-09  本文已影响0人  编程回忆录

Hive版本:我们使用2.1.1的版本安装

Hive介绍:能够让你使用SQL语言查询分布式文件如HDFS。

Hive安装

tar zxvf apache-hive-2.1.1-bin.tar.gz

设置HIVE_HOME:

vim ~/.bash_profile
hive-0.png

使配置文件立即生效

source ~/.bash_profile
cd conf
cp hive-default.xml.template hive-site.xml

直接用如下配置覆盖hive-site.xml文件内容:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<configuration>
 <property>
    <name>hive.server2.enable.doAs</name>
    <value>false</value>
  </property>
  <property>
    <name>hive.metastore.warehouse.dir</name>
    <value>/tmp/hive/warehouse</value>
  </property>
  <property>
    <name>hive.metastore.local</name>
    <value>true</value>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>root</value>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>hive123456</value>
  </property>
</configuration>
/Users/****/apps/apache-hive-2.1.1-bin/lib
$HIVE_HOME/bin/schematool -dbType mysql -initSchema
hive-1.png
hive
hive-2.png

创建数据库:pptb

create database pptb;

在pptb数据库下面创建表ad_log:

use pptb;   
CREATE EXTERNAL TABLE ad_log (
time timestamp comment '访问时间',
user_id string comment '用户id',
ad_slot_id int comment '广告位id',
event_type int comment '日志类型 1:广告请求 2:广告展示 3:广告点击',
creative_id int comment '广告创意id',
url string comment '用户浏览的网站地址',
referer_url string comment '来源网址',
ip string comment '用户访问ip',
city_id int comment '城市id'
)
partitioned by (dt string,hour string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
location 'hdfs://localhost:9000/ad_log/';
hive-3.png hive-4.png

查看广告创建的表:

desc ad_log;
hive-5.png
$HIVE_HOME/bin/hiveserver2 &
hive-7.png
beeline -u jdbc:hive2://localhost:10000/default -n user_name -p password

下一篇文章将介绍如何使用Hue通过页面访问Hive。

上一篇 下一篇

猜你喜欢

热点阅读