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