hive的基本数据类型

本是古典 何须时尚 2021-11-05 04:08 419阅读 0赞

hive的基本数据类型

1.基本数据类型

hive类型        说明         java类型      实例
  1).tinyint      1byte有符号的整数    byte        20
  2).smalint     2byte有符号的整数   short       20
  3).int       4byte有符号的整数   int        20
  4).bigint      8byte有符号的整数   long       20
  5).boolean     布尔类型true或false   boolean     true
  6).float      单精度         float 3.217
  7).double    双精度         double 3.212
  8).string      字符序列,单双即可   string ‘zhang’;“ashakjds”
  9).timestamp    时间戳,精确的纳秒 timestamp ‘158030219111’
  10).binary      字节数组        byte[]

2.集合数据类型

hive类型      说明                       java类型             实例
  1).struct        对象类型,可以通过字段名.元素名来访问      object          struct(‘name’,‘age’)
  2).map        一组键值对的元组                 map            map(‘name’,‘zhangsan’,‘age’,‘23’)
  3).array          数组                     array            array(‘name’,‘age’)
  4).union          组合
  3.案例:
    hive>create table employees(
      > name string,
      > salary float,
      > subordinates array,
      > deductions map,
      > address structstreet:string,city:string,state:string,zip:int
      > );

hive的数据编码格式

1.默认hive通过^A(\001)、^B(\002)、^C(\003)分别对列、(array和struct)、map进行匹配;

2.创建表时,可以通过以下命令进行设置:
    row format delimited
    fields terminated by ‘\001’
    collection items terminated by ‘\002’
    map keys terminated by ‘\003’
    lines terminated by ‘\n’
  3.加载数据
    $>cd ~
    $>cp /mnt/hgfs/2.安装环境/data/employees/employees.txt .
    hive> load data local inpath ‘/home/hyxy/employees.txt’ into table employees;
    hive>select * from employees;

hive的读时模式

1.传统的关系型数据库在进行数据加载时,必须验证数据格式是否符合表字段定义,如果不符合,数据将无法插入至数据库表中。这种模式称为“写时模式”。

2.hive中,数据加载过程采用“读时模式”。

hive数据存在什么地方

1.数据将存储在hdfs中,在{/user/hive/warehouse/}目录的*_db下面。

删除表中的全部数据,你将执行$>hadoop fs -rm /user/hive/warehouse/employees/employees.txt

转载:
https://www.cnblogs.com/lyr999736/p/9468469.html

发表评论

表情:
评论列表 (有 0 条评论,419人围观)

还没有评论,来说两句吧...

相关阅读