02-Hive一个表创建另一个表,表分区,分桶

声明:如果你是初学者,看我这篇文章的时候,看我上一篇会更好。
Hive表的创建:http://blog.csdn.net/qq_29622761/article/details/51564680

这篇的主要内容目录是:

  1. 由一个表创建另一个表
  2. hive不同文件读取对比
  3. hive分区表
  4. hive分桶

你现在开始吧!

  1. 由一个表创建另一个表
    格式:ceate table test3 like test2;
    我要做的:create table testtext_c like testtext;(这种方式不会把数据复制过来,只是创建了相同的数据格式)
    我先加载数据到表testtext中:
[root@hadoop1 host]# cat testtext
wer	46
wer	89
weree	78
rr	89
hive> load data local inpath '/usr/host/testtext' into table testtext;
Copying data from file:/usr/host/testtext
Copying file: file:/usr/host/testtext
Loading data to table default.testtext
OK
Time taken: 0.294 seconds
hive> select * from testtext;
OK
wer	46
wer	89
weree	78
rr	89
Time taken: 0.186 seconds
hive> 

2 接着创建testtext_c吧(like方式)

hive> create table testtext_c like testtext;
OK
Time taken: 0.181 seconds
hive> select * from testtext;
OK
wer	46
wer	89
weree	78
rr	89
Time taken: 0.204 seconds
hive> select * from testtext_c;
OK
Time taken: 0.158 seconds
hive> 

哎,testtext_c中确实没有数据吧!真的没骗你啊!
3 客官,别急,还有一种方式(as)

hive> create table testtext_cc as select name,addr from testtext;
Total MapReduce jobs = 2
Launching Job 1 out of 2
Number of reduce tasks is set to 0 since there's no reduce operator
Job running in-process (local Hadoop)
Hadoop job information for null: number of mappers: 1; number of reducers: 0
2016-06-01 20:49:59,404 null map = 0%,  reduce = 0%
2016-06-01 20:50:20,644 null map = 100%,  reduce = 0%, Cumulative CPU 1.3 sec
2016-06-01 20:50:21,735 null map = 100%,  reduce = 0%, Cumulative CPU 1.3 sec
MapReduce Total cumulative CPU time: 1 seconds 300 msec
Ended Job = job_1464828076391_0004
Execution completed successfully
Mapred Local Task Succeeded . Convert the Join into MapJoin
Ended Job = 1011778050, job is filtered out (removed at runtime).
Moving data to: hdfs://hadoop1:9000/tmp/hive-root/hive_2016-06-01_20-49-43_516_5205177189363939745/-ext-10001
Moving data to: hdfs://hadoop1:9000/user/hive/warehouse/testtext_cc
Table default.testtext_cc stats: [num_partitions: 0, num_files: 1, num_rows: 0, total_size: 29, raw_data_size: 0]
OK
Time taken: 48.014 seconds

又跑mapreduce,为啥?create table testtext_c like testtext;这个都不走mapreduce的啊!怎么这里就跑mapreduce?嘿嘿,其实这里有select关键字,只有select * from 啥的不走mapreduce,其余的select都是会跑mapreduce的,hive的底层设计原理其实就是走mapreduce的,不信你看看我前一篇博客。
查查有没有数据:

hive> select * from testtext_cc;
OK
wer	46
wer	89
weree	78
rr	89
Time taken: 0.116 seconds
hive> 

有啦有啦!
所以:create table testtext_cc as select name,addr from testtext;(这一种方式是走mapreduce形式,这种方式是把数据也会复制过来)

4 接下来呢,看看不同文件格式读取对比
有textfile文件格式,sequencefile格式,rcfile格式,还有自定义的文件格式。

hive> create table test_text(name string,val string) stored as textfile;
OK
Time taken: 0.098 seconds
hive> desc formatted test_text;
OK
# col_name            	data_type           	comment             
	 	 
name                	string              	None                
val                 	string              	None                
	 	 
# Detailed Table Information	 	 
Database:           	default             	 
Owner:              	root                	 
CreateTime:         	Wed Jun 01 21:11:15 PDT 2016	 
LastAccessTime:     	UNKNOWN             	 
Protect Mode:       	None                	 
Retention:          	0                   	 
Location:           	hdfs://hadoop1:9000/user/hive/warehouse/test_text	 
Table Type:         	MANAGED_T
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

当法律与事业相遇

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值