Hadoop/Hive:从本地机器上的 .csv 加载数据 [英] Hadoop/Hive : Loading data from .csv on a local machine

查看:19
本文介绍了Hadoop/Hive:从本地机器上的 .csv 加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为这是一个新手...

As this is coming from a newbie...

我为我设置了 Hadoop 和 Hive,因此我可以在我的计算机上运行 Hive 查询以访问 AWS 集群上的数据.我可以使用存储在计算机上的 .csv 数据运行 Hive 查询吗,就像我使用 MS SQL Server 所做的那样?

I had Hadoop and Hive set up for me, so I can run Hive queries on my computer accessing data on AWS cluster. Can I run Hive queries with .csv data stored on my computer, like I did with MS SQL Server?

然后我如何将 .csv 数据加载到 Hive 中?它与 Hadoop 有什么关系,我应该在哪种模式下运行它?

How do I load .csv data into Hive then? What does it have to do with Hadoop and which mode I should run that one?

我应该关心哪些设置,以便如果我做错了什么,我可以随时返回并在 Amazon 上运行查询,而不会影响之前为我设置的内容?

What settings I should care about so that if I did something wrong I can always go back and run queries on Amazon without compromising what was set up for me earlier?

推荐答案

让我通过以下简单步骤来帮助您:

Let me work you through the following simple steps:

步骤:

首先,使用 csv 文件中的字段名称在 hive 上创建一个表.例如,您的 csv 文件包含三个字段(id、name、salary),并且您想在 hive 中创建一个名为staff"的表.使用以下代码在 hive 中创建表.

First, create a table on hive using the field names in your csv file. Lets say for example, your csv file contains three fields (id, name, salary) and you want to create a table in hive called "staff". Use the below code to create the table in hive.

hive> CREATE TABLE Staff (id int, name string, salary double) row format delimited fields terminated by ',';

第二,既然您的表是在 hive 中创建的,让我们将您的 csv 文件中的数据加载到 hive 上的staff"表中.

Second, now that your table is created in hive, let us load the data in your csv file to the "staff" table on hive.

hive>  LOAD DATA LOCAL INPATH '/home/yourcsvfile.csv' OVERWRITE INTO TABLE Staff;

最后,在hive上显示你的Staff"表的内容,检查数据是否加载成功

Lastly, display the contents of your "Staff" table on hive to check if the data were successfully loaded

hive> SELECT * FROM Staff;

谢谢.

这篇关于Hadoop/Hive:从本地机器上的 .csv 加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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