hive常用操作

2021-10-02 04:08:57 字數 1252 閱讀 3837

create table tablename (

id int,

name string,

likes array, #陣列

address map#字典

)#接下來設定分隔加入資訊的分隔符

row format delimited

fields terminated by ',' #按','分隔每一列

collection items terminated by '-' #按'-'分隔每一列中具體指

map key terminated by ':'; 按 ':'分隔字典

按什麼分隔可以根據資料來定。

insert into tablename (欄位1,欄位2,..) values (v1,v2..)#這種插入方式太慢
下面介紹如何將大量資料插入到表中

假如/root/data/下有乙個檔案data,data檔案中存放著我們需要加入到表中的資料,可以使用下面的語句將資料大量加入到表中。

load data local inpath '/root/data/data' into table tablename;
注:建立的每個hive對應的表,都對應著hdfs中的乙個檔案。

外部表

create external table psn4

(id int,

name string,

likes array,

address map)

row format delimited

fields terminated by ','

collection items terminated by '-'

map keys terminated by ':'

location '/usr/';

注:內部表與外部表的區別:

1、建立表的時候,內部表直接儲存到預設的hdfs路徑,外部表需要自己制定儲存路徑。

2、刪除表時,內部表會將資料和元資料全部刪除,外部表只刪除元資料,資料不刪除。

內部表和外部表的使用時機:

現有資料再有表的使用外部表。先有表再有資料,用內部表。hive:讀時檢查,即插入資料時不論插入的資料是否正確,都存起來,當讀取時,將正確的資料顯示出來。(讀時檢查,實現解耦,提高資料記載的效率)

關係型資料庫:寫時檢查。

Hive 常用操作

hive f script.q 可以直接執行在指令碼中的命令 hive e select from users 直接執行sql語句 hive s e select from users 靜默的方式執行,不顯示輸入資訊只顯示輸出結果 hive v 將會列印所執行的sql語句 hive h 192.16...

hive 常用操作

1。建立表 內部表 create table ifnot exists hibernate.student id string age string name string row format delimited fields terminated by t 外部表create external ...

Hive常用操作

1.1 建立表 建立文字檔案create table fantj.t3 id int,name string,age int row format delimited fields terminated by stored as textfile hive create table fantj.t3...