如何使用 PIG 将数据从本地系统加载到 hdfs

how to load the data from local system to hdfs using PIG

我有一个 csv 文件 sample.csv 并且位于 \home\hadoop\Desktop\script\sample.csv 中。 我尝试使用

加载 PIG
movies = load '/home/hadoop/Desktop/script/sample.csv' using PigStorage(',') as (id,name,year,rating,duration);

但是这个 PIG 语句给出了一个错误,但是当给出语句 dump movies; 时,它抛出错误并显示输入和输出失败。

请建议我如何使用 pig 语句加载数据。

如果您的输入文件在本地,那么您可以输入 pig -x local

进入 grunt shell

如果你输入 grunt shell 那么你可以输入下面的语句

 record = LOAD  '/home/hadoop/Desktop/script/sample.csv' using PigStorage(',') as (id:int,name:chararray,year:chararray,rating:chararray,duration:int); 


dump record;

如果您的输入文件不在本地,那么您首先需要使用以下命令将该文件从本地复制到 HDFS

hadoop dfs -put <path of file at local>  <path of hdfs dir>

将文件加载到 HDFS 后,您可以输入 pig

进入映射缩减模式

再次grunt shell将被打开。 ia 假设您的 HDFS 位置类似于下面的 LOAD 语句

record = LOAD  '/user/hadoop/inputfiles/sample.csv' using PigStorage(',') as (id:int,name:chararray,year:chararray,rating:chararray,duration:int); 


dump record;

您也可以在 grunt shell 中使用 copyFromLocal 命令将本地文件移动到 hdfs。

通过 pig -x local 在本地模式下打开 pig shell,如果您的文件存在于 hdfs 中,那么您可以使用 pig 打开 grant shell.

$pig -x local
grunt> movies = load '/home/hadoop/Desktop/script/sample.csv' using PigStorage(',') as (id:int,name:chararray,year:chararray,rating:chararray,duration:chararray);


grunt> dump movies;