hive mysql 外部表_hive外部表

我们在创建表的时候可以指定external关键字创建外部表,外部表对应的文件存储在location指定的目录下,向该目录添加新文件的同时,该表也会读取到该文件(当然文件格式必须跟表定义的一致),删除外部表的同时并不会删除location指定目录下的文件.

1.查看hdfs系统目录/user/hadoop1/myfile下文件

[hadoop1@node1]$ hadoop fs -ls /user/hadoop1/myfile/

Found 1 items

-rw-r--r--   3 hadoop1 supergroup     567839 2014-10-29 16:50 /user/hadoop1/myfile/tb_class.txt

2.创建外部表指向myfile目录下的文件

hive (hxl)> create external table tb_class_info_external

> (id int,

> class_name string,

> createtime timestamp ,

> modifytime timestamp)

> ROW FORMAT DELIMITED

> FIELDS TERMINATED BY '|'

> location '/user/hadoop1/myfile';

OK

Time taken: 0.083 seconds

注意这里的location指向的是hdfs系统上的路径,而不是本地机器上的路径,这里表tb_class_info_external会读取myfile目录下的所有文件

3.查看外部表

hive (hxl)> select count(1) from tb_class_info_external;

Total MapReduce jobs = 1

Launching Job 1 out of 1

Number of reduce tasks determined at compile time: 1

In order to change the average load for a reducer (in bytes):

set hive.exec.reducers.bytes.per.reducer=

In order to limit the maximum number of reducers:

set hive.exec.reducers.max=

In order to set a constant number of reducers:

set mapred.reduce.tasks=

Starting Job = job_201

你可能感兴趣的:(hive,mysql,外部表)