码迷,mamicode.com
首页 > 其他好文 > 详细

hive 下篇

时间:2018-04-13 14:31:21      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:use   txt   any   nal   cat   成功   tab   ||   external   

通过查询语句向表中插入数据

hive> select * from cust; OK cust.custname   cust.sex        cust.nianling tianyt_touch100 1       50 wangwu  1       85 zhangsan        1       20 liuqin  0       56 wangwu  0       47 liuyang 1       32 hello   0       100 Time taken: 0.151 seconds, Fetched: 7 row(s)

 

hive> create external table tb_cust_externl     > (custname string,sex int,nianling int) row format delimited fields terminated by ‘ ‘     > location ‘/root/tmpdata/customers.txt‘; OK Time taken: 0.288 seconds

 

[root@host ~]# hdfs dfs -ls -R /tmp/201804* -rw-r--r--   1 root supergroup         14 2018-04-12 16:50 /tmp/20180410/customer1.txt

 

hive> alter  table tb_cust_externl set location ‘/tmp/20171024/customers1.txt‘; OK Time taken: 0.146 seconds

hive> select * from tb_cust_externl; OK tb_cust_externl.custname        tb_cust_externl.sex     tb_cust_externl.nianling nihao   1       5 Time taken: 0.176 seconds, Fetched: 1 row(s)

查看HDFS:

drwxr-xr-x   - root supergroup          0 2018-04-13 11:41 /user/hive/warehouse/gamedw.db/cust -rwxr-xr-x   1 root supergroup         96 2018-04-11 17:14 /user/hive/warehouse/gamedw.db/cust/customers.txt

通过spark插入数据:

scala> hivecon.sql("insert into table gamedw.cust select * from gamedw.tb_cust_externl").show 18/04/13 11:50:56 WARN lazy.LazyStruct: Extra bytes detected at the end of the row! Ignoring similar problems. ++ || ++ ++

hive> select * from cust; OK cust.custname   cust.sex        cust.nianling tianyt_touch100 1       50 wangwu  1       85 zhangsan        1       20 liuqin  0       56 wangwu  0       47 liuyang 1       32 hello   0       100 nihao   1       5 Time taken: 0.137 seconds, Fetched: 8 row(s)

 

发现tb_cust_externl外部表的nihao成功插入

然后查看HDFS:

drwxr-xr-x   - root supergroup          0 2018-04-13 11:50 /user/hive/warehouse/gamedw.db/cust -rwxr-xr-x   1 root supergroup         96 2018-04-11 17:14 /user/hive/warehouse/gamedw.db/cust/customers.txt -rwxr-xr-x   1 root supergroup         10 2018-04-13 11:50 /user/hive/warehouse/gamedw.db/cust/part-00000-ebb85cb3-73e4-4d7b-aa07-8f007c8887bb-c000

发现cust多了一个文件,咱们来查看一下文件内容:

[root@host ~]# hdfs dfs -text /user/hive/warehouse/gamedw.db/cust/part-00000-ebb85cb3-73e4-4d7b-aa07-8f007c8887bb-c000 nihao 1 5

也就是说插入的数据会生成一个新的文件

hive 下篇

标签:use   txt   any   nal   cat   成功   tab   ||   external   

原文地址:https://www.cnblogs.com/playforever/p/8819814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!