pig报错Failed to read data from

  • 时间:
  • 来源:互联网

pig版本 0.17.0
hadoop版本 2.7.7

这学期学期hadoop,在做pig的实验时,使用load读取文件,进行处理后使用dump输出处理结果,结果显示读取文件失败,如图

pig语句:

register /home/node01/pigdemo-1.0-SNAPSHOT.jar;
emp = load '/B18042015/pig/input/emp.csv'
emp2 = foreach emp generate empno,ename,sal,org.example.CheckSalaryGrade(sal);
dump emp2;

emp.csv 在HDFS上是存在的
在这里插入图片描述

emp.csv 文件内容:

7369,SMITH,CLERK,7902,1980/12/17,800,20
7499,ALLEN,SALESMAN,7698,1981/2/20,1600,300,30
7521,WARD,SALESMAN,7698,1981/2/22,1250,500,30
7566,JONES,MANAGER,7839,1981/4/2,2975,20
7654,MARTIN,SALESMAN,7698,1981/9/28,1250,1400,30
7698,BLAKE,MANAGER,7839,1981/5/1,2850,30
7782,CLARK,MANAGER,7839,1981/6/9,2450,10
7788,SCOTT,ANALYST,7566,1987/4/19,3000,20
7839,KING,PRESIDENT,1981/11/17,5000,10
7844,TURNER,SALESMAN,7698,1981/9/8,1500,0,30
7876,ADAMS,CLERK,7788,1987/5/23,1100,20
7900,JAMES,CLERK,7698,1981/12/3,950,30
7902,FORD,ANALYST,7566,1981/12/3,3000,20
7934,MILLER,CLERK,7782,1982/1/23,1300,10

emp.csv文件可以在pig中通过cat指令读取到内容:

cat /B18042015/pig/emp.csv

# 打印结果正常
7369,SMITH,CLERK,7902,1980/12/17,800,,20
7499,ALLEN,SALESMAN,7698,1981/2/20,1600,300,30
7521,WARD,SALESMAN,7698,1981/2/22,1250,500,30
7566,JONES,MANAGER,7839,1981/4/2,2975,,20
7654,MARTIN,SALESMAN,7698,1981/9/28,1250,1400,30
7698,BLAKE,MANAGER,7839,1981/5/1,2850,,30
7782,CLARK,MANAGER,7839,1981/6/9,2450,,10
7788,SCOTT,ANALYST,7566,1987/4/19,3000,,20
7839,KING,PRESIDENT,,1981/11/17,5000,,10
7844,TURNER,SALESMAN,7698,1981/9/8,1500,0,30
7876,ADAMS,CLERK,7788,1987/5/23,1100,,20
7900,JAMES,CLERK,7698,1981/12/3,950,,30
7902,FORD,ANALYST,7566,1981/12/3,3000,,20
7934,MILLER,CLERK,7782,1982/1/23,1300,,10

报错部分:

Input(s):
Failed to read data from "/B18042015/pig/input/emp.csv"

报错部分截图
在这里插入图片描述
先说原因:

load读取文件方式错误

观察emp.csv文件内容,很明显该文件有八列,但是使用load读取时只读了 “empno,ename,sal” 三列,所以读取文件失败

修改一下读取的语句即可
修改如下:

emp = load '/B18042015/pig/input/emp.csv' using PigStorage(',') as (empno:int,ename:chararray,job:chararray,mgr:int,hiredate:chararray,sal:int,comm:int,deptno:int);

将文件的八列全部读取,完美解决

本文链接http://element-ui.cn/news/show-576574.aspx