Hive 0.13 数据类型

来源:互联网 发布:哪个会计从业软件好 编辑:程序博客网 时间:2024/06/06 04:19

hive支持的数据类型路下

数值类型 Numeric Types

  • TINYINT (1字节,数据范围: -128 to 127)
  • SMALLINT (2字节,数据范围: -32,768 to 32,767)
  • INT (4字节,数据范围:-2,147,483,648 to 2,147,483,647)
  • BIGINT (8字节,数据范围: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
  • FLOAT (4字节, 单精度浮点数)
  • DOUBLE (8字节,双精度浮点数)
  • DECIMAL
    • Introduced in Hive 0.11.0 with a precision of 38 digits
    • Hive 0.13.0 introduced user definable precision and scale

日期/时间类型 Date/Time Types 

  • TIMESTAMP (Hive 0.8.0以上支持)
  • DATE (Hive 0.12.0以上支持)

字符串类型 String Types

  • STRING
  • VARCHAR (Hive 0.12.0以上支持)
  • CHAR (Hive 0.13.0以上支持)

Misc Types

  • BOOLEAN
  • BINARY (Hive 0.8.0以上支持)

复合类型 Complex Types

  • arrays: ARRAY<data_type>
  • maps: MAP<primitive_type, data_type>
  • structs: STRUCT<col_name : data_type [COMMENT col_comment], ...>
  • union: UNIONTYPE<data_type, data_type, ...> (Hive 0.7.0以上支持)

列类型 Column Types

Integral Types (TINYINTSMALLINTINTBIGINT)

数值类型默认是int,如果数值超出int的范围,就会被解释为bigint。

 数值后面加上后缀表示:

Type

Postfix

Example

TINYINT

Y

100Y

SMALLINT

S

100S

BIGINT

L

100L

Strings

字符串可以用单引号(')或双引号(“)。Hive在字符串中使用C-Style的转义。

Varchar

Varchar types 创建的长度是 ( 1 到 65355), 在字符串中容许使用最大数量的字符. 如果string类型转换成varchar类型, 长度超过了最大值,将会被截断。 字符长度是由字符串所包含的数量决定.

Version

Icon

Varchar 类型在 Hive 0.12.0中支持 (HIVE-4844).

Char

最大固定长度255.

CREATE TABLE foo (bar CHAR(10))

Version

Icon

Char类型在Hive 0.13.0中支持 (HIVE-5191).

Timestamps

 支持传统的unix时间戳,可选的纳秒级精度。

支持的转换:

  • 整型数值类型:解读为以秒为单位的UNIX时间戳
  • 浮动点数值类型:解读为以秒和小数精度为单位的UNIX时间戳
  • 字符串:JDBC兼容的java.sql.Timestamp格式“YYYY-MM-DD HH:MM:SS.fffffffff”(9位小数位精度)

时间戳被解释是与timezone无关,存储为从UNIX纪元的偏移量。提供便利的UDF和时区转换(to_utc_timestamp,from_utc_timestamp)。
所有现有datetime的UDF(月,日,年,小时,等)可以工作于TIMESTAMP数据类型。

Version

Icon

Timestamps在Hive 0.8.0支持 (HIVE-2272).

Dates

日期值描述一个特定的年/月/日的{ { YYYY - MM - DD } }. 

例, DATE '2013-­01-­01'. Date 类型没有时间.
Date 类型支持的范围是是 0000-­01-­01 to 9999-­12-­31, 依赖于原始的Java支持的日期类型.

Version

Icon

Dates 在 in Hive 0.12.0支持 (HIVE-4055).

转换 Dates

Date类型能和 Timestamp, String互相转换.

Valid casts to/from Date type

Result

cast(date as date)

Same date value

cast(timestamp as date)

The year/month/day of the timestamp is determined, based on the local timezone, and returned as a date value.

cast(string as date)

If the string is in the form 'YYYY-MM-DD', then a date value corresponding to that year/month/day is returned. If the string value does not match this formate, then NULL is returned.

cast(date as timestamp)

A timestamp value is generated corresponding to midnight of the year/month/day of the date value, based on the local timezone.

cast(date as string)

The year/month/day represented by the Date is formatted as a string in the form 'YYYY-MM-DD'.

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types

0 0
原创粉丝点击