您的位置:首页 > 运维架构

Hive 安装及测试二

2015-10-16 09:50 363 查看
上一节我们演示了hive的安装,下面我们通过命令行的方式演示一下hive的应用。

进入命令行

bin/hive

1.查看所有表

>show tables;

2.创建表,并指定每行数据的列分隔符

>CREATE TABLE t_hive (id int,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

3.查看表结构

> desc t_hive;

hive> desc t_hive;
OK
id                      int
name                    string
Time taken: 0.242 seconds, Fetched: 2 row(s)
4.导入文本数据

创建如下文件

[hadoop@study-90 ~]$ cat /home/hadoop/t_hive.txt
1       aaa
2       bbb
3       ccc
4       ddd
>LOAD DATA LOCAL INPATH '/home/hadoop/t_hive.txt' OVERWRITE INTO TABLE t_hive ;

5.查询表数据

hive> select * from t_hive;
OK
1       aaa
2       bbb
3       ccc
4       ddd
Time taken: 0.295 seconds, Fetched: 4 row(s)
hive>
>
> select * from t_hive where id=2;
OK
2       bbb
Time taken: 5.904 seconds, Fetched: 1 row(s)
6.复制表结构

create table t_hive1 LIKE t_hive;

7.复制表数据

INSERT OVERWRITE TABLE t_hive1 SELECT * FROM t_hive ;

hive> INSERT OVERWRITE TABLE t_hive1 SELECT * FROM t_hive ;
Query ID = hadoop_20151008023154_d6decee5-2900-461d-a706-4195b9626711
Total jobs = 3
Launching Job 1 out of 3
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1444271460174_0001, Tracking URL = http://study-90:8088/proxy/application_1444271460174_0001/ Kill Command = /home/hadoop/hadoop-2.6.0/bin/hadoop job  -kill job_1444271460174_0001
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2015-10-08 02:34:33,496 Stage-1 map = 0%,  reduce = 0%
2015-10-08 02:35:14,243 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 1.84 sec
MapReduce Total cumulative CPU time: 1 seconds 840 msec
Ended Job = job_1444271460174_0001
Stage-4 is selected by condition resolver.
Stage-3 is filtered out by condition resolver.
Stage-5 is filtered out by condition resolver.
Moving data to: hdfs://mycluster/user/hive/warehouse/t_hive1/.hive-staging_hive_2015-10-08_02-31-54_835_5493803551258585988-1/-ext-10000
Loading data to table default.t_hive1
Table default.t_hive1 stats: [numFiles=1, numRows=4, totalSize=24, rawDataSize=20]
MapReduce Jobs Launched:
Stage-Stage-1: Map: 1   Cumulative CPU: 1.84 sec   HDFS Read: 3148 HDFS Write: 95 SUCCESS
Total MapReduce CPU Time Spent: 1 seconds 840 msec
OK
Time taken: 210.383 seconds
hive> select * from t_hive1
> ;
OK
1       aaa
2       bbb
3       ccc
4       ddd
Time taken: 0.832 seconds, Fetched: 4 row(s)
8.删除表

drop table t_hive1;

详细请参考:hive用户指南
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hadoop hive