我使用以下命令创建了配置单元外部表:
use hive2;
create external table depTable (depId int comment 'This is the unique id for each dep', depName string,location string) comment 'department table' row format delimited fields terminated by ","
stored as textfile location '/dataDir/';
现在,当我查看 HDFS 时,我可以看到 db 但depTable
仓库内没有。
[cloudera@quickstart ~]$ hadoop fs -ls /user/hive/warehouse/hive2.db
[cloudera@quickstart ~]$
上面你可以看到这个数据库中没有创建表。据我所知,外部表不存储在配置单元仓库中。所以我正确吗??如果是,那么它存储在哪里?
但是如果我先创建外部表然后加载数据,那么我可以看到里面的文件hive2.db
。
hive> create external table depTable (depId int comment 'This is the unique id for each dep', depName string,location string) comment 'department table' row format delimited fields terminated by "," stored as textfile;
OK
Time taken: 0.056 seconds
hive> load data inpath '/dataDir/department_data.txt' into table depTable;
Loading data to table default.deptable
Table default.deptable stats: [numFiles=1, totalSize=90]
OK
Time taken: 0.28 seconds
hive> select * from deptable;
OK
1001 FINANCE SYDNEY
2001 AUDIT MELBOURNE
3001 MARKETING PERTH
4001 PRODUCTION BRISBANE
现在,如果我触发hadoop fs
查询,我可以在数据库下看到这个表,如下所示:
[cloudera@quickstart ~]$ hadoop fs -ls /user/hive/warehouse/hive2.db
Found 1 items
drwxrwxrwx - cloudera supergroup 0 2019-01-17 09:07 /user/hive/warehouse/hive2.db/deptable
如果我仍然删除表,我可以在 HDFS 中看到如下表:
[cloudera@quickstart ~]$ hadoop fs -ls /user/hive/warehouse/hive2.db
Found 1 items
drwxrwxrwx - cloudera supergroup 0 2019-01-17 09:11 /user/hive/warehouse/hive2.db/deptable
那么,外部表的确切行为是什么?当我创建 usingLOCATION
关键字时,它在哪里存储,当我创建 usingload
语句时,为什么它被存储在中,HDFS
以及在删除它之后为什么它没有被删除。