hive使用load載入資料1 0

2021-08-28 01:35:19 字數 1938 閱讀 7676

安裝hive

直接操作hive

create table if not exists l_employee (eid int,name string,salary string,destination string)

comment 'employee details'

row format delimited

fields terminated by '\t'

lines terminated by '\n'

stored as textfile;

載入資料到資料表中,

這時你用下邊的命令看看你是不是可以讀的資料

檔案中的內容為,這裡注意建立表的時候fields terminated by '\t'所以在txt中列注意要用'\t'隔開

[table]

|1202 | manisha |45000| proof reader|

|1203 | masthanvali | 40000 | technical writer|

|1204 | kiran |40000 | hr admin|

|1205 | kranthi |30000 | op admin|

[/table]

匯入後select * from l_employee就會看家你要看到的資料

[b]hive修改表[/b]

drop table if exists l_employee;

alter table l_employee rename l_emlpoyee1;

alter table employee change name ename string;

alter table employee change salary salary double;

[b]新增表的分割槽[/b]

create table employee (id int, name string, dept string, yoj stirng)

comment 'employee details'

row format delimited

fields terminated by ','

lines terminated by '\n'

partition by 'yoj'

stored as textfile;

載入的資料

id, name, dept, yoj

1, gopal, tp, 2012

2, kiran, hr, 2012

3, kaleel,sc, 2013

4, prasanth, sc, 2013

這裡我們將上邊的資料放入檔案/tmp/employee/file1.txt

load資料,如果我們沒有加

partition by 'yoj'
會出現:validationfailuresemanticexception table is not partitioned but partition spec exists:

這是由於我們在建立表的時候沒有建立分割槽。由於在新建表的時候,所以只有在存在分割槽列的表上執行增加分割槽的操作,才會成功。

[b]裝載資料總結[/b]

上邊我們已經從本地裝載了資料,我們可以試試其他的相關的命令試試

如果table是乙個分割槽表,則在hql中必須指定分割槽。

如果加上location,hive會將本地檔案複製乙份上傳到指定目錄,如果不加local關鍵字,hive只是將hdfs上的資料移動到指定的目錄。

hive載入資料時發現不會對資料格式進行任何的校驗,需要使用者自己保證資料格式與定義的格式一致。

向hive中load資料

hive中如果有分割槽的話,如果是需要自己構造資料且不知道是否有分割槽,可以使用這條語句看是否有分割槽 show create table tabletest tabletest為需要看是否有分割槽的表,執行這條語句之後會有這樣一條出來 partitioned by string 即為分割槽的字段,...

Hive使用指令碼載入資料

方式一 直接寫在指令碼中 load track logs.sh bin sh 環境變數生效 etc profile hive home hive home opt cdh 5.3.6 hive 0.13.1 cdh5.3.6 日誌目錄 log dir datas tracklogs 獲取昨天的日期 ...

hive資料載入

一.需要注意的問題 1.hive不支援行級別的增刪改 2.使用overwrite會覆蓋表的原有資料,into則是追加。3.local會將本地檔案系統複製乙份再上傳至指定目錄,無local只是將本地檔案系統上的資料移動到指定目錄。4.若目錄指向hdfs上的資料則執行的是move操作。5.分隔符要與資料...