将数据插入 Hive 表 [英] Inserting Data into Hive Table

查看:31
本文介绍了将数据插入 Hive 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是蜂巢新手.我已经成功地设置了一个用于开发目的的单节点 hadoop 集群,在它之上,我安装了 hive 和 pig.

I am new to hive. I have successfully setup a single node hadoop cluster for development purpose and on top of it, I have installed hive and pig.

我在 hive 中创建了一个虚拟表:

I created a dummy table in hive:

create table foo (id int, name string);

现在,我想向这个表中插入数据.我可以像 sql 一样一次添加一条记录吗?请用类似的命令帮助我:

Now, I want to insert data into this table. Can I add data just like sql one record at a time? kindly help me with an analogous command to:

insert into foo (id, name) VALUES (12,"xyz);

另外,我有一个包含以下格式数据的 csv 文件:

Also, I have a csv file which contains data in the format:

1,name1
2,name2
..
..

..


1000,name1000

如何将这些数据加载到虚拟表中?

How can I load this data into the dummy table?

推荐答案

我认为最好的方法是:
a) 将数据复制到 HDFS(如果它还没有)
b) 像这样在 CSV 上创建外部表

I think the best way is:
a) Copy data into HDFS (if it is not already there)
b) Create external table over your CSV like this

CREATE EXTERNAL TABLE TableName (id int, name string)
ROW FORMAT DELIMITED   
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '
'
STORED AS TEXTFILE
LOCATION 'place in HDFS';

c) 您可以通过向 TableName 发出查询来开始使用它.
d) 如果要将数据插入到其他 Hive 表中:

c) You can start using TableName already by issuing queries to it.
d) if you want to insert data into other Hive table:

insert overwrite table finalTable select * from table name;

这篇关于将数据插入 Hive 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆