Hive的數據類型


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<string>,
      > deductions map<string,float>,
      > address struct<street: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

  

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM