Derek Lac
Derek Lac

Reputation: 131

Cannot load a file from Hadoop HDFS from Pig Latin

I am having trouble trying to load a csv from file. I keep on getting the following error:

Input(s):
Failed to read data from "hdfs://localhost:9000/user/der/1987.csv"

Output(s):
Failed to produce result in                 "hdfs://localhost:9000/user/der/totalmiles3"

Looking at my Hadoop hdfs installed in my local machine I see the file. In fact the file is located at multiple locations such as /, /user/ , etc.

hdfs dfs -ls /user/der
Found 1 items
-rw-r--r--   1 der supergroup  127162942 2015-05-28 12:42 
/user/der/1987.csv

My pig scripts is as follows:

records = LOAD '1987.csv' USING PigStorage(',') AS
       (Year, Month, DayofMonth, DayOfWeek, DepTime, CRSDepTime, ArrTime,
         CRSArrTime, UniqueCarrier, FlightNum, TailNum,ActualElapsedTime,
      CRSElapsedTime,AirTime,ArrDelay, DepDelay, Origin, Dest,
         Distance:int, TaxIn, TaxiOut, Cancelled,CancellationCode,
          Diverted, CarrierDelay, WeatherDelay, NASDelay,     SecurityDelay,
     lateAircraftDelay);
milage_recs= GROUP records ALL;
tot_miles = FOREACH milage_recs GENERATE SUM(records.Distance);
STORE tot_miles INTO 'totalmiles3';

I ran pig with the -x local option. I was able to read the files from my local hard disk with the -x local option. Got the right answer and the tail -f on Hadoop namenode did not scroll which proves I ran the files all locally on hard disk:

pig  -x local totalmiles.pig

Now I am getting errors. It seems the hadoop name server is getting request because I used tail -f and see the logs scroll.

pig totalmiles.pig

records = LOAD '/user/der/1987.csv' USING PigStorage(',') AS

I get the following error:

Failed Jobs: 
  JobId Alias   Feature Message Outputs 
    job_local602774674_0001 milage_recs,records,tot_miles           
GROUP_BY,COMBINER   Message: ENOENT: No such file or directory 

        at  
org.apache.hadoop.io.nativeio.NativeIO$POSIX.chmodImpl(Native     Method) 

    at        
org.apache.hadoop.io.nativeio.NativeIO$POSIX.chmod(NativeIO.java:230) 

at         org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.j
    ava:724) 
    at     


org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:    502) 
        at org.apache.hadoop.fs.FileSystem.mkdirs(FileSys   tem.java:600) 
    at     
org.apache.hadoop.mapreduce.JobResourceUploader.uploadFiles(JobResourceUpl
    oader.java:94) 
        at      
org.apache.hadoop.mapreduce.JobSubmitter.copyAndConfigureFiles(JobSubmitte
   r.java:98) 
    at      org .apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:193) 

...blah...

Input(s): 
Failed to read data from "/user/der/1987.csv" 

Output(s): 
Failed to produce result in "hdfs://localhost:9000/user/der/totalmiles3" 

I used the hdfs to check for permissions by mkdir and that seems ok:

hdfs dfs -mkdir /user/der/temp2 
hdfs dfs -ls /user/der 

Found 3 items 
-rw-r--r--   1 der supergroup  127162942 2015-05-28 12:42  
/user/der/1987.csv 
drwxr-xr-x   - der supergroup          0 2015-05-28 16:21     
/user/der/temp2 
drwxr-xr-x   - der supergroup          0 2015-05-28 15:57 
/user/der/test 

I tried the pig with mapreduce option and still get the same type of error:

 pig -x mapreduce totalmiles.pig

 5-05-28 20:58:44,608 [JobControl] INFO  
  org.apache.hadoop.mapreduce.lib.jobc
    ontrol.ControlledJob - PigLatin:totalmiles.pig while            
  submitting 

    ENOENT: No such file or directory
        at 
org.apache.hadoop.io.nativeio.NativeIO$POSIX.chmodImpl(Na       at         
org.apache.hadoop.io.nativeio.NativeIO$POSIX.chmod(NativeIO.java:230)
at 

org.apache.hadoop.fs.RawLocalFileSystem.setPermissi     at  
org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSy
at org.apache.hadoop.fs.FileSystem.mkdirs(FileSystem.java:600)
at     
org.apache.hadoop.mapreduce.JobResourceUploader.uploadFiles(Job
at org.apache.hadoop.mapreduce.JobSubmitter.copyAndConfigureFiles(Jo
at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobS
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1290)

My core-site.xml has the temp dir as follows:

<property>
      <name>hadoop.tmp.dir</name>
     <value>/usr/local/hadoop</value>
      <description>A base for other temporary directories.    
</description>
 </property>

and my hdfs-site.xml as the namenode and datanode as follows:

 <property>
     <name>dfs.namenode.name.dir</name>  
     <value>file:/usr/local/hadoop/dfs/namenode</value>
  </property>





 <property> 
        <name>dfs.datanode.data.dir</name>
        <value>file:/usr/local/hadoop/dfs/datanode</value>
    </property>

I've gotten a bit further in debugging the issue. It seems my namenode is misconfigured as I cannot reformat it:

[hadoop hdfs formatting gets error failed for Block pool ]

Upvotes: 1

Views: 2876

Answers (1)

Murali Rao
Murali Rao

Reputation: 2287

We have to give the hadoop file path as : /user/der/1987.csv

 records = LOAD '/user/der/1987.csv' USING PigStorage(',') AS
   (Year, Month, DayofMonth, DayOfWeek, DepTime, CRSDepTime, ArrTime,
     CRSArrTime, UniqueCarrier, FlightNum, TailNum,ActualElapsedTime,
  CRSElapsedTime,AirTime,ArrDelay, DepDelay, Origin, Dest,
     Distance:int, TaxIn, TaxiOut, Cancelled,CancellationCode,
      Diverted, CarrierDelay, WeatherDelay, NASDelay,     SecurityDelay,
 lateAircraftDelay);

If its for testing, you can have the file : 1987.csv in the path from where you are executing the pig script, i.e. have 1987.csv and the .pig file in the same location.

Upvotes: 1

Related Questions