从本地文件系统中导入数据到Hive表
先在Hive里面创建好表,如下:
- hive> create table wyp
- > (id int, name string,
- > age int, tel string)
- > ROW FORMAT DELIMITED
- > FIELDS TERMINATED BY '\t'
- > STORED AS TEXTFILE;
- OK
- Time taken: 2.832 seconds
这个表很简单,只有四个字段,具体含义我就不解释了。本地文件系统里面有个/home/wyp/wyp.txt文件,内容如下:
- [wyp@master ~]$ cat wyp.txt
- 1 wyp 25 13188888888888
- 2 test 30 13888888888888
- 3 zs 34 899314121
wyp.txt文件中的数据列之间是使用\t分割的,可以通过下面的语句将这个文件里面的数据导入到wyp表里面,操作如下:
- hive> load data local inpath 'wyp.txt' into table wyp;
- Copying data from file:/home/wyp/wyp.txt
- Copying file: file:/home/wyp/wyp.txt
- Loading data to table default.wyp
- Table default.wyp stats:
- [num_partitions: 0, num_files: 1, num_rows: 0, total_size: 67]
- OK
- Time taken: 5.967 seconds
这样就将wyp.txt里面的内容导入到wyp表里面去了,可以到wyp表的数据目录下查看,如下命令:
- hive> dfs -ls /user/hive/warehouse/wyp ;
- Found 1 items
- -rw-r--r--3 wyp supergroup 67 2014-02-19 18:23 /hive/warehouse/wyp/wyp.txt
浙公网安备 33010602011771号