hive插入数据-单条

写入数据到hive的hdfs文件中即可,hive创建表的时候用小写做表名,不然查不到

相关操作如下:

查看目录与表

hive> dfs -ls /user/hive/warehouse/

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

[root@master hive]# cat /opt/flight.hive
create table flight (
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/flight_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/flight.hive 

此时没有表中没有数据

hive> select * from flight;
OK
Time taken: 1.464 seconds

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

[root@master hive]# hadoop fs -put ./tmp_data/visits_data.txt /user/hive/warehouse/flight/
hive> select * from flight;
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 flight;
OK
Time taken: 0.024 seconds
hive> dfs -ls /user/hive/warehouse/flight;
ls: `/user/hive/warehouse/people_visits': No such file or directory
上一篇:读取本地excel发短信


下一篇:java实现——006重建二叉树