Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sample code for basic operation of Hive

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the sample code about the basic operation of Hive. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

1. Create new source data on the server side of hive

[root@hadoop5 ~] # cat hivedata 1Participant XiaomingReader ReadLeibing3jangsanliujiahui, ShopeatLigshanghaiVujiahui

two。 Create an internal table

Create table test1 (id int,name string,likes array,address map) row format delimitedfields terminated by', 'collection items terminated by'-'map keys terminated by':'

3. Import data into hive

Load data local inpath'/ root/hivedata' into table test1;0: jdbc:hive2://hadoop5:10000 > select * from test1 +-- +-+ | test1.id | test1.name | test1.likes | Test1.address | +-- +-+ | 1 | xiaoming | ["read" "tv", "code"] | {"beijing": "chaoyang", "shanghai": "pudong"} | | 2 | lisi | ["cook", "game"] | {"chongqing": "yongchun", "sichuan": "yibing"} | 3 | zhangsan | ["shop" "eat"] | {"shanghai": "xujiahui"} | + -+ 3 rows selected (0.207 seconds) 0: jdbc:hive2://hadoop5:10000 >

4. Create an external table (after it is deleted in hive, the data on hdfs will not be deleted)

Create external table test2 (id int,name string,likes array,address map) row format delimitedfields terminated by, 'collection items terminated by'-'map keys terminated by': 'location' / user/test2'

5. Create a test3 with a partial test1 as a template

Create table test3 as select id, name from test1;0: jdbc:hive2://hadoop5:10000 > desc test3 +-+ | col_name | data_type | comment | +-+ | id | int | | name | string | | +- -- + 2 rows selected (0.406 seconds) 0: jdbc:hive2://hadoop5:10000 >

6. Create test4 with reference to test1

Create table test4 like test1

7. Create a partition table

Create table test5 (id int,name string,likes array,address map) partitioned by (sex string) row format delimitedfields terminated by', 'collection items terminated by'-'map keys terminated by':'; 0: jdbc:hive2://hadoop5:10000 > desc test5 +-- +-+ | col_name | data_type | comment | +- -+-+ | id | int | name | string | | | likes | array | address | map | sex | string | NULL | NULL | | # Partition Information | NULL | NULL | | # col_name | data_type | comment | | NULL | NULL | | sex | string | | | +-- +-+-- + 10 rows selected (0.382 seconds) 0: jdbc:hive2://hadoop5:10000 > |

8. Add load data for the partition

Load data local inpath'/ root/hivedata' into table test5 partition (sex='boy'); 0: jdbc:hive2://hadoop5:10000 > select * from test5 +-+ | test5.id | test5.name | Test5.likes | test5.address | test5.sex | +-- -+-+ | 1 | xiaoming | ["read" "tv", "code"] | {"beijing": "chaoyang", "shanghai": "pudong"} | boy | | 2 | lisi | ["cook", "game"] | {"chongqing": "yongchun", "sichuan": "yibing"} | boy | 3 | zhangsan | ["shop" "eat"] | {"shanghai": "xujiahui"} | boy | + -+-+ 3 rows selected (0.784 seconds) 0: jdbc:hive2://hadoop5:10000 >

9. Add a sex=girl partition for test5

Alter table test5 add partition (sex='girl')

10. Delete a partition

Alter table test5 drop partition (sex='girl'); this is the end of the article on "sample code for basic operation of Hive". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report