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(id int,name string,age int) row format delimited fields terminated by ','stored as textfile;
oktime taken: 4.467 seconds
hive> select * from fantj.t3;
oktime taken: 2.82 seconds
表示行格式用逗號來分割字段。
建立文字檔案test.txt
我建立在/home/fantj
目錄下。
1,jiao,18
2,fantj,20
3,laowang,30
4,laotie,40
1.2 從本地匯入到hive
load data local inpath '/home/fantj/test.txt' overwrite into table t3;
hive> load data
local inpath '/home/fantj/test.txt' overwrite into table fantj.t3;
loading data
to table fantj.t3
[warning]
could not update stats.
oktime taken: 26.334 seconds
select * from fantj.t3;
hive> select * from fantj.t3;
ok1 jiao 18
2 fantj 20
3 laowang 30
4 laotie 40
time taken: 2.303 seconds, fetched: 4 row(s)
匯入成功!
1.3 從hdfs匯入到hive
先將test檔案上傳到hdfs中
[root@s166 fantj]# hadoop fs -put test.txt /hdfs2hive
-rw-
r--r
--3root
supergroup
46/hdfs2hive/test
.txt
進入hive,建立表t5create
table fantj.t5(id int,name string,age int) row format delimited fields terminated by
','stored as textfile;
hive> create table fantj.t5(id int,name string,age int) row format delimited fields terminated by ','stored as textfile;
oktime taken: 3.214 seconds
執行匯入
load data inpath '/hdfs2hive/test.txt' overwrite into table fantj.t5;
hive> load data inpath '/hdfs2hive/test.txt' overwrite into table fantj.t5;
loading data
to table fantj.t5
[warning]
could not update stats.
oktime taken: 25.498 seconds
檢查是否成功:
hive> select * from fantj.t5;
ok1 jiao 18
2 fantj 20
3 laowang 30
4 laotie 40
time taken: 5.046 seconds, fetched: 4 row(s)
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...