从本地文件系统中导入数据到Hive表
先在Hive里面创建好表,如下:

  1. hive> create table wyp
  2.     > (id int, name string,
  3.     > age int, tel string)
  4.     > ROW FORMAT DELIMITED
  5.     > FIELDS TERMINATED BY '\t'
  6.     > STORED AS TEXTFILE;
  7. OK
  8. Time taken: 2.832 seconds


这个表很简单,只有四个字段,具体含义我就不解释了。本地文件系统里面有个/home/wyp/wyp.txt文件,内容如下:

  1. [wyp@master ~]$ cat wyp.txt
  2. 1       wyp     25      13188888888888
  3. 2       test    30      13888888888888
  4. 3       zs      34      899314121


wyp.txt文件中的数据列之间是使用\t分割的,可以通过下面的语句将这个文件里面的数据导入到wyp表里面,操作如下:

  1. hive> load data local inpath 'wyp.txt' into table wyp;
  2. Copying data from file:/home/wyp/wyp.txt
  3. Copying file: file:/home/wyp/wyp.txt
  4. Loading data to table default.wyp
  5. Table default.wyp stats:
  6. [num_partitions: 0, num_files: 1, num_rows: 0, total_size: 67]
  7. OK
  8. Time taken: 5.967 seconds


这样就将wyp.txt里面的内容导入到wyp表里面去了,可以到wyp表的数据目录下查看,如下命令:

  1. hive> dfs -ls /user/hive/warehouse/wyp ;
  2. Found 1 items
  3. -rw-r--r--3 wyp supergroup 67 2014-02-19 18:23 /hive/warehouse/wyp/wyp.txt
posted on 2021-11-18 16:55  sean1246  阅读(77)  评论(0编辑  收藏  举报