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

How to use Hive data type

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

Share

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

This article mainly shows you "how to use Hive data types", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Hive data types" this article.

Basic data type "basic data type"

Tinyint/smallint/int/bigint: integer type

Float/double: floating point type

Boolean: Boolean typ

String: string type

"complex data types"

Array: array type, consisting of a series of elements of the same data type

Map: collection type, which contains key- > value key-value pairs. Elements can be accessed through key

Struct: structural type, which can contain elements of different data types. These elements can be obtained by the way of "dot syntax".

"time type"

Date: support from Hive0.12.0

Timestamp: support from Hive0.8.0

Commonly used DDL operations to view data list show databases

Create a new database using the database USE database_name;

Syntax:

CREATE (DATABASE | SCHEMA) [IF NOT EXISTS] database_name-- DATABASE | SCHEMA is equivalent [COMMENT database_comment]-- database comment [LOCATION hdfs_path]-- location stored on HDFS [WITH DBPROPERTIES (property_name=property_value,...)];-- specify additional attributes

Example:

CREATE DATABASE IF NOT EXISTS hive_test COMMENT 'hive database for test' WITH DBPROPERTIES (' create'='heibaiying')

Create a database whose default storage path on HDFS is / user/hive/warehouse/\ * .db.

Create a database that can specify where the database is stored on the HDFS

Hive > CREATE DATABASE hive_test location'/ db_hive.db'; to view database information

Syntax:

DESC DATABASE [EXTENDED] db_name;-- EXTENDED indicates whether additional attributes are displayed

Example:

DESC DATABASE EXTENDED hive_test; deletes the database

Syntax:

DROP (DATABASE | SCHEMA) [IF EXISTS] database_name [RESTRICT | CASCADE]

The default behavior is RESTRICT, and deletion fails if a table exists in the database. To delete the library and its tables, you can use CASCADE cascading deletions.

Example:

DROP DATABASE IF EXISTS hive_test CASCADE; case practice

Import local files into Hive

[hadoop@node02 ~] $vim student.txt student.id student.name 1 Runsen 2 Zhangsan 3 Lisi hive > CREATE DATABASE db_hive; hive > use db_hive; hive > create table student (id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY'\ thands; hive > load data local inpath 'student.txt' into table student; hive > select * from student; OK student.id student.name 1 Runsen 2 Zhangsan 3 Lisi

In addition to importing local files into HIve, we first upload the files to HDFS, and then use HDFS to import the data into Hive.

The above is all the content of the article "how to use Hive data types". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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