hive 数据类型

数字类型

  • TINYINT (1-byte signed integer, from -128 to 127)
  • SMALLINT (2-byte signed integer, from -32,768 to 32,767)
  • INT/INTEGER (4-byte signed integer, from -2,147,483,648 to 2,147,483,647)
  • BIGINT (8-byte signed integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
  • FLOAT (4-byte single precision floating point number)
  • DOUBLE (8-byte double precision floating point number)
  • DOUBLE PRECISION (alias for DOUBLE, only available starting with Hive 2.2.0)
  • DECIMAL
    • Introduced in Hive 0.11.0 with a precision of 38 digits
    • Hive 0.13.0 introduced user-definable precision and scale
  • NUMERIC (same as DECIMAL, starting with Hive 3.0.0)

日期/时间类型

  • TIMESTAMP (Note: Only available starting with Hive 0.8.0)
  • DATE (Note: Only available starting with Hive 0.12.0)
  • INTERVAL (Note: Only available starting with Hive 1.2.0)

字符串类型

  • STRING
  • VARCHAR (Note: Only available starting with Hive 0.12.0)
  • CHAR (Note: Only available starting with Hive 0.13.0)

misc类型

  • BOOLEAN
  • BINARY (Note: Only available starting with Hive 0.8.0)

集合类型

1.Array类型

arrays: ARRAY (Note: negative values and non-constant expressions are allowed as of Hive 0.14.)

例:

  • 创建表

    hive> create table class_test(name string, student_id_list array) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' COLLECTION ITEMS TERMINATED BY ':';
    
  • 导入数据

    hive> LOAD DATA LOCAL INPATH  '/home/hadoop/software/class_test.txt' INTO TABLE class_test;
    

    hive 数据类型_第1张图片

  • 查询

    hive> select * from class_test;
    OK
    034     [1,2,3,4]
    035     [5,6]
    036     [7]
    
    
    hive> select student_id_list[0] from class_test;
    OK
    1
    5
    7
    

2.Map类型

例:

  • 创建表

     hive> create table employee_test(id string, perf map) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' COLLECTION ITEMS TERMINATED BY ',' MAP KEYS TERMINATED BY ':';
    
  • 导入数据

    hive> LOAD DATA LOCAL INPATH '/home/hadoop/software/employee_test.txt'  INTO TABLE employee_test;
    

    hive 数据类型_第2张图片

  • 查询

    hive> select * from employee_test;
    OK
    1       {"job":80,"team":60,"person":70}
    2       {"job":60,"team":80}
    3       {"job":90,"team":70,"person":100}
    Time taken: 0.069 seconds, Fetched: 3 row(s) 
    

3.Struct类型

例:

  • 创建表
hive> create table student_test(id INT, info struct) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' COLLECTION ITEMS TERMINATED BY ':'; 
  • 导入数据

     hive> LOAD DATA LOCAL INPATH '/home/hadoop/software/student_test.txt' INTO TABLE student_test;
    

    hive 数据类型_第3张图片

  • 查询

    hive> select * from student_test;
    OK
    1       {"name":"zhou","age":30}
    2       {"name":"yan","age":30}
    3       {"name":"chenli","age":20}
    4       {"name":"li","age":80}
    Time taken: 0.066 seconds, Fetched: 4 row(s)
    
    hive> select info.age from student_test;
    OK
    30
    30
    20
    80
    Time taken: 0.071 seconds, Fetched: 4 row(s)
    

    参考

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

你可能感兴趣的:(hive)