hive 下篇
Posted 努力,奋斗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hive 下篇相关的知识,希望对你有一定的参考价值。
通过查询语句向表中插入数据
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
[[email protected] ~]# 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多了一个文件,咱们来查看一下文件内容:
[[email protected] ~]# hdfs dfs -text /user/hive/warehouse/gamedw.db/cust/part-00000-ebb85cb3-73e4-4d7b-aa07-8f007c8887bb-c000 nihao 1 5
也就是说插入的数据会生成一个新的文件
以上是关于hive 下篇的主要内容,如果未能解决你的问题,请参考以下文章