理解目录/user/hive/warehouse/与表的关系

查看目录与表

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)

准备hive脚本文件与测试数据文件

[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/    

数据文件说明:字段之间使用'\t'隔开
创建表格

[root@master hive]# hive -f /opt/visits.hive 

此时没有表中没有数据

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

复制数据文件到warehouse目录下面,查看数据

[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)

删除表格后再观察数据文件

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

你可能感兴趣的:(理解目录/user/hive/warehouse/与表的关系)