查看目錄與表
hive> dfs -ls /user/hive/warehouse/
> ;
Found 10 items
drwxr-xr-x - root supergroup 0 2017-09-29 09:14 /user/hive/warehouse/choice
drwxr-xr-x - root supergroup 0 2017-09-29 09:14 /user/hive/warehouse/classinfo
drwxr-xr-x - root supergroup 0 2017-09-29 09:26 /user/hive/warehouse/ptest
drwxr-xr-x - root supergroup 0 2017-09-29 22:32 /user/hive/warehouse/sample.db
drwxr-xr-x - root supergroup 0 2017-09-29 04:20 /user/hive/warehouse/sgr
drwxr-xr-x - root supergroup 0 2017-09-29 04:30 /user/hive/warehouse/sgr_results
drwxr-xr-x - root supergroup 0 2017-09-29 04:06 /user/hive/warehouse/sogou
drwxr-xr-x - root supergroup 0 2017-09-29 08:20 /user/hive/warehouse/tb_stu1
drwxr-xr-x - root supergroup 0 2017-09-29 09:13 /user/hive/warehouse/userinfo
drwxr-xr-x - root supergroup 0 2017-09-28 09:03 /user/hive/warehouse/wordcount
hive> show tables;
OK
choice
classinfo
ptest
sgr
sgr_results
sogou
tb_stu1
userinfo
wordcount
Time taken: 0.347 seconds, Fetched: 9 row(s)
準(zhǔn)備hive腳本文件與測(cè)試數(shù)據(jù)文件
[root@master hive]# cat /opt/visits.hive
create table people_visits (
last_name string,
first_name string,
arrival_time string,
meeting_location string,
info_comment string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t';
[root@master hive]# cat tmp_data/visits_data.txt
BUCKLEY SUMMER 10/12/2010 14:48 10/12/2010 14:45 WH
CLOONEY GEORGE 10/12/2010 14:47 10/12/2010 14:45 WH
PRENDERGAST JOHN 10/12/2010 14:48 10/12/2010 14:45 WH
LANIER JAZMIN 10/12/2010 14:48 10/12/2010 14:45 WH BILL SIGNING/
MAYNARD ELIZABETH 10/13/2010 12:34 10/13/2010 13:00 WH BILL SIGNING/
數(shù)據(jù)文件說(shuō)明:字段之間使用'\t'隔開(kāi)
創(chuàng)建表格
[root@master hive]# hive -f /opt/visits.hive
此時(shí)沒(méi)有表中沒(méi)有數(shù)據(jù)
hive> desc people_visits;
OK
last_name string
first_name string
arrival_time string
meeting_location string
info_comment string
Time taken: 1.618 seconds, Fetched: 5 row(s)
hive> select * from people_visits;
OK
Time taken: 1.464 seconds
復(fù)制數(shù)據(jù)文件到warehouse目錄下面,查看數(shù)據(jù)
[root@master hive]# hadoop fs -put ./tmp_data/visits_data.txt /user/hive/warehouse/people_visits/
hive> select * from people_visits;
OK
BUCKLEY SUMMER 10/12/2010 14:48 10/12/2010 14:45 WH NULL NULL
CLOONEY GEORGE 10/12/2010 14:47 10/12/2010 14:45 WH NULL
PRENDERGAST JOHN 10/12/2010 14:48 10/12/2010 14:45 WH NULL
LANIER JAZMIN 10/12/2010 14:48 10/12/2010 14:45 WH BILL SIGNING/
MAYNARD ELIZABETH 10/13/2010 12:34 10/13/2010 13:00 WH BILL SIGNING/
Time taken: 2.561 seconds, Fetched: 5 row(s)
刪除表格后再觀察數(shù)據(jù)文件
hive> drop table people_visitsddd;
OK
Time taken: 0.024 seconds
hive> dfs -ls /user/hive/warehouse/people_visits;
ls: `/user/hive/warehouse/people_visits': No such file or directory
Command -ls /user/hive/warehouse/people_visits failed with exit code = 1
Query returned non-zero code: 1, cause: null