create external table if not exists kylin_hive.dept(
deptno int,
dname string,
loc int )
row format delimited fields terminated by '\t';
(2)创建员工表
create external table if not exists kylin_hive.emp(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
row format delimited fields terminated by '\t';
(3)查看创建的表
jdbc:hive2://node03:10000> show tables;
OK
tab_name
dept
emp
(4)向外部表中导入数据导入数据
load data local inpath '/kkb/install/dept.txt' into table kylin_hive.dept;
load data local inpath '/kkb/install/emp.txt' into table kylin_hive.emp;
查询结果
jdbc:hive2://node03:10000> select * from emp;
jdbc:hive2://node03:10000> select * from dept;
我们知道,一个N维的Cube,是由1个N维子立方体、N个(N-1)维子立方体、N*(N-1)/2个(N-2)维子立方体、......、N个1维子立方体和1个0维子立方体构成,总共有2^N个子立方体组成,在逐层算法中,按维度数逐层减少来计算,每个层级的计算(除了第一层,它是从原始数据聚合而来),是基于它上一层级的结果来计算的。比如,[Group by A, B]的结果,可以基于[Group by A, B, C]的结果,通过去掉C后聚合得来的;这样可以减少重复计算;当 0维度Cuboid计算出来的时候,整个Cube的计算也就完成了。
cd /kkb/install/hive-1.1.0-cdh5.14.2/conf
vim hive-site.xml
<property>
<name>hive.zookeeper.quorum</name>
<value>node01,node02,node03</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>node01,node02,node03</value>
</property>
第三步:修改hive-env.sh配置文件添加以下配置
cd /kkb/install/hive-1.1.0-cdh5.14.2/conf
vim hive-env.sh
export HADOOP_HOME=/kkb/install/hadoop-2.6.0-cdh5.14.2
export HBASE_HOME=/kkb/install/hbase-1.2.0-cdh5.14.2/
export HIVE_CONF_DIR=/kkb/install/hive-1.1.0-cdh5.14.2/conf
第四步:创建hive表,映射hbase当中的数据
进入hive客户端,创建hive映射表,映射hbase当中的两张表数据
create database hive_hbase;
use hive_hbase;
CREATE external TABLE hive_hbase.data_goods(goodsId int ,goodsName string ,sellingPrice string ,productPic string ,productBrand string ,productfbl string ,productNum string ,productUrl string ,productFrom string ,goodsStock int , appraiseNum int)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES
("hbase.columns.mapping" = ":key,f1:goodsName ,f1:sellingPrice ,f1:productPic ,f1:productBrand ,f1:productfbl ,f1:productNum ,f1:productUrl ,f1:productFrom ,f1:goodsStock , f1:appraiseNum")
TBLPROPERTIES("hbase.table.name" ="flink:data_goods");
CREATE external TABLE hive_hbase.data_orders(orderId int,orderNo string ,userId int,goodId int ,goodsMoney decimal(11,2) ,realTotalMoney decimal(11,2) ,payFrom int ,province string ,createTime timestamp )
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES
("hbase.columns.mapping" = ":key, f1:orderNo , f1:userId , f1:goodId , f1:goodsMoney ,f1:realTotalMoney,f1:payFrom ,f1:province,f1:createTime")
TBLPROPERTIES("hbase.table.name" ="flink:data_orders");
File "/usr/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 323, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: attempt to write a readonly database
cd /kkb/install/hue-3.9.0-cdh5.14.2/desktop/conf
vim hue.ini
[[[mysql]]]
nice_name="My SQL DB"
engine=mysql
host=node03.kaikeba.com
port=3306
user=root
password=123456
options={"init_command":"set names utf8;SET CHARACTER SET utf8;SET character_set_connection=utf8;"}
更改完了配置,重新启动hue的服务
cd /kkb/install/hue-3.9.0-cdh5.14.2/
build/env/bin/supervisor
3.5、配置hue与hbase的集成
第一步:修改hue.ini
如果hue已经启动,需要先停止hue的服务,然后继续修改hue的配置文件hue.ini
cd /kkb/install/hue-3.9.0-cdh5.14.2/desktop/conf
vim hue.ini
[hbase]
hbase_clusters=(Cluster|node01:9090)
hbase_conf_dir=/kkb/install/hbase-1.2.0-cdh5.14.2/conf
第二步:启动hbase的thrift server服务
第一台机器执行以下命令启动hbase的thriftserver
cd /kkb/install/hbase-1.2.0-cdh5.14.2
bin/start-hbase.sh
bin/hbase-daemon.sh start thrift
$ impala-shell
Starting Impala Shell without Kerberos authentication
Connected to node03:21000
Server version: impalad version 2.11.0-cdh5.14.2 RELEASE (build ed85dce709da9557aeb28be89e8044947708876c)
**********************************************************************
Welcome to the Impala shell.
(Impala Shell v2.11.0-cdh5.14.2 (ed85dce) built on Tue Mar 27 13:39:48 PDT 2018)
You can run a single query from the command line using the '-q' option.
**********************************************************************
[node03:21000] >
exit;退出交互界面
1、impala-shell语法
1.1、impala-shell的外部命令参数语法
不需要进入到impala-shell交互命令行当中即可执行的命令参数
impala-shell后面执行的时候可以带很多参数:
-h 查看帮助文档
impala-shell -h
-r 刷新整个元数据,数据量大的时候,比较消耗服务器性能
impala-shell -r
-v 查看对应版本
impala-shell -v -V
-f 执行查询文件
cd /kkb/install
vim impala-shell.sql
select * from course.score;
通过-f 参数来执行执行的查询文件
impala-shell -f impala-shell.sql
CREATE DATABASE IF NOT EXISTS mydb1;
drop database if exists mydb;
创建数据库表并指定数据库表数据存放hdfs的位置(与hive建表语法类似)
hdfs dfs -mkdir -p /input/impala
create external table t3(id int ,name string ,age int ) row format delimited fields terminated by '\t' location '/input/impala/external';
3、 创建数据库表
创建student表
CREATE TABLE IF NOT EXISTS mydb1.student (name STRING, age INT, contact INT );
创建employ表
create table employee (Id INT, name STRING, age INT,address STRING, salary BIGINT);
3.1、 数据库表中插入数据
insert into employee (ID,NAME,AGE,ADDRESS,SALARY)VALUES (1, 'Ramesh', 32, 'Ahmedabad', 20000 );
insert into employee values (2, 'Khilan', 25, 'Delhi', 15000 );
Insert into employee values (3, 'kaushik', 23, 'Kota', 30000 );
Insert into employee values (4, 'Chaitali', 25, 'Mumbai', 35000 );
Insert into employee values (5, 'Hardik', 27, 'Bhopal', 40000 );
Insert into employee values (6, 'Komal', 22, 'MP', 32000 );
数据的覆盖
Insert overwrite employee values (1, 'Ram', 26, 'Vishakhapatnam', 37000 );
执行覆盖之后,表中只剩下了这一条数据了
另外一种建表语句
create table customer as select * from employee;
3.2、 数据的查询
select * from employee;
select name,age from employee;
3.3、 删除表
DROP table mydb1.employee;
3.4、 清空表数据
truncate employee;
3.5、 查看视图数据
select * from employee_view;
4、 order by语句
基础语法
select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]
Select * from employee ORDER BY id asc;
5、group by 语句
Select name, sum(salary) from employee Group BY name;
6、 having 语句
基础语法
select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]
按年龄对表进行分组,并选择每个组的最大工资,并显示大于20000的工资
select max(salary) from employee group by age having max(salary) > 20000;
7、 limit语句
select * from employee order by id limit 4;
8、impala当中的数据表导入几种方式
第一种方式,通过load hdfs的数据到impala当中去
create table user(id int ,name string,age int ) row format delimited fields terminated by "\t";
准备数据user.txt并上传到hdfs的 /user/impala路径下去
1 hello 15
2 zhangsan 20
3 lisi 30
4 wangwu 50
加载数据
load data inpath '/user/impala/' into table user;
查询加载的数据
select * from user;
如果查询不不到数据,那么需要刷新一遍数据表
refresh user;