Hive Data type

Source: Internet
Author: User

The data types commonly used in 1.hive include:

TinyInt (byte), smallint (short), Int,bigint (long), float,double,boolean,string type. "Corresponding Java type in parentheses"

add: for varchar and char types in MySQL: If the string length is less than 10 it is recommended to use char, greater than 10 using varchar. This is because for a varchar type, you must occupy one to two bytes to illustrate its character length. (Char addressing fast)

2. Type conversion

  implicit conversion rules: Any integer type can be implicitly converted to a wider range of types.

All integer types + float + string can be converted to a double type.

You can use the cast operation for data type display conversions .

For example, cast (' 1 ' as int) converts the string ' 1 ' to an integer value of 1, the conversion fails and the expression returns control null.

3. Complex types

Create Table complex (Col1 array<int>, Col2 map<int  >, Col3 struct<a:string, B:int, C:double> );

The contents are: The data file of array map (' A ', 1, ' B ', 2) struct (' a ', 1,1.0) is load into the table above.

Execute Hive statement: Select col1[0], col2[' B '],col3.c from complex;

Back: 1 2 1.0

      • The array type is evaluated by subscript, and the type of the field must be the same
      • The map type is value by key,
      • A struct type is defined by its name, and the field type can be different

4. Built-in functions

    • Same as SQL: equivalent judgment x= ' a ', null value is NULL, pattern match x like ' A% ', arithmetic operation x+1, logical operation x or Y.
    • One of the differences with SQL-92 is: | | is logical or (or), not the string "connection". The string connection in MySQL and Hive is the concat () function.
    • You can use:show functions to get a list of functions. The describe function obtains the use Help for a particular functions.

Hive Data type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.