In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the Hive composite data type, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. Overview
Hive serves as the storage of offline data in big data, and uses Hive as the environment for building data warehouses. Generally speaking, the data types of data warehouses are basic data types, such as int, string, double, etc., but sometimes some composite data structures are needed to store data, such as array, map, struct;. Below, we will introduce these three data structures:
Types
Define
Description
Array
The data in Arrayarray is of the same type. For example, if the element in array An is ['axiomagy], the value of A [1] is' b'map].
The MapMap data type, which is mainly stored in the form of key V, can be accessed through the field name ['key']. The Valuestruct corresponding to this key will be returned.
STRUCT
< col_name : data_type [COMMENT col_comment], …>The data within structs can be accessed through DOT (.). For example, a column in the table is of type STRUCT {b INT; c INT}, and we can visit domain b through a.ba.
2.Array usage
1)。 Create a new student grade table student1, which contains the id,name,score field. Score is an array data type, in which is the student's grade. Create a new table statement:
Hive > create table student1 (id int,name string, score array) ROW FORMAT DELIMITED FIELDS TERMINATED BY', 'COLLECTION ITEMS TERMINATED BY' |'
2) data preparation student1.txt
[root@salver158 ~] # cat student1.txt 100, "student1", 80 | 82 | 84101, "student2", 70 | 72 | 74102, "student3", 60 | 62 | 64
3) load data
Hive > load data local inpath "/ root/student1.txt" into table student1
4) load successfully. Check the query below:
Hive > select * from student1;OK100 "student1" [80.0 seconds 82.0 row 84.0] 101 "student2" [70.0 74.0] 102 "student3" [62.0 seconds 64.0] Time taken: 0.612 seconds, Fetched: 3 row (s)
3.Map usage
1)。 Create table sudent2, field id,name,score, where score data type is Map, table creation statement:
Hive > create table student2 (id int,name string,score map) ROW FORMAT DELIMITED FIELDS TERMINATED BY', 'COLLECTION ITEMS TERMINATED BY' | 'MAP KEYS TERMINATED BY':'
2)。 Data preparation student2.txt
[root@salver158 ~] # cat student2.txt 100, "student1", "yuwen": 80 | "shuxue": 82 | "yingyu": 84101, "student2", "yuwen": 70 | "shuxue": 72 | "yingyu": 74102, "student3", "yuwen": 60 | "shuxue": 62 | "yingyu": 64
3)。 Data loading
Hive > load data local inpath "/ root/student2.txt" into table student2
4)。 After loading successfully, check the query below:
Hive > select * from student2 OK100 "student1" {"\" yuwen\ ": 80.0,"\ "shuxue\": 82.0,"\ "yingyu\": 84.0} 101" student2 "{"\ "yuwen\": 70.0,"\ "shuxue\": 72.0,"\ "yingyu\": 74.0} 102" student3 "{"\ "yuwen\": 60.0, "\" shuxue\ ": 62.0 "\" yingyu\ ": 64.0} Time taken: 0.124 seconds, Fetched: 3 row (s)
4.struct usage
1)。 Create table sudent3, field id,name,score, where score data type is struct, table creation statement:
Hive > create table student3 (id int,name string,score struct) ROW FORMAT DELIMITED FIELDS TERMINATED BY', 'COLLECTION ITEMS TERMINATED BY' |'
2)。 Data preparation student3.txt
[root@salver158 ~] # cat student3.txt 100, "student1", "yuwen" | 80101, "student2", "yuwen" | 70102, "student3", "yuwen" | 60
3)。 Data loading
Hive > load data local inpath "/ root/student3.txt" into table student3
4)。 After loading successfully, check the query below:
Hive > select * from student3 OK100 "student1" {"kecheng": "\" yuwen\ "," score ": 80.0} 101" student2 "{" kecheng ":"\ "yuwen\", "score": 70.0} 102 "student3" {"kecheng": "\" yuwen\ "," score ": 60.0} Time taken: 0.091 seconds, Fetched: 3 row (s) Thank you for reading this article carefully I hope the article "how to use Hive compound data types" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.