3

I am running a pig script which is as follows

REGISTER '/home/vishal/FirstUdf.jar';
DEFINE UPPER com.first.UPPER();
A = LOAD '/home/vishal/exampleforPIG1' AS (exchange: chararray, symbol: chararray, date: int,value:float);
B= FOREACH A GENERATE com.first.UPPER(exchange);
DUMP B;

Following is my UDF in java

package com.first;

import java.io.IOException;

import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.util.WrappedIOException;

@SuppressWarnings("deprecation")
public class UPPER extends EvalFunc<String> {
    public String exec(Tuple input) throws IOException {
        if (input == null || input.size() == 0)
            return null;
        try {
            String str = (String) input.get(0);
            return str.toLowerCase();
        } catch (Exception e) {
            throw WrappedIOException.wrap(
                    "Caught exception processing input row ", e);
        }
    }
}

Now when i try to run that ,it gives me the following error

Pig Stack Trace

ERROR 1066: Unable to open iterator for alias B

org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias B
    at org.apache.pig.PigServer.openIterator(PigServer.java:866)
    at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:683)
    at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:303)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:190)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:166)
    at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84)
    at org.apache.pig.Main.run(Main.java:430)
    at org.apache.pig.Main.main(Main.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:156) Caused by: java.io.IOException: Job terminated with anomalous status FAILED
    at org.apache.pig.PigServer.openIterator(PigServer.java:858)
    ... 12 more

Whys is that in pig script it is not able to open an iterator for B ie (it is not able to assign an iterator for the following line)

B = FOREACH A GENERATE com.first.UPPER(exchange);

'exampleforPIG1' file has following data

NYSE    CPO 2009-12-30  0.14
NYSE    CPO 2009-09-28  0.14
NYSE    CPO 2009-06-26  0.14
NYSE    CPO 2009-03-27  0.14
NYSE    CPO 2009-01-06  0.14
NYSE    CCS 2009-10-28  0.414
NYSE    CCS 2009-07-29  0.414
..
..
etc
Uselesssss
  • 2,127
  • 6
  • 28
  • 37
  • Which Pig version do you use? – Lorand Bendig Mar 21 '13 at 13:42
  • Hi Lonard I am using Pig 0.10.1 .Is the problem version specific? – Uselesssss Mar 22 '13 at 03:51
  • Do you use run it locally or on a cluster? If on a cluster I'd check the tasktrackers' logs for more error messages (e.g: outofmemory error) You may also increase the logging level in Pig to see whether it helps to track down the error: (log4j.properties, set the root logger to debug: log4j.logger.org.apache.pig=debug..) With the same setup you have, it works flawlessly for me – Lorand Bendig Mar 22 '13 at 09:09
  • Following is what i got after doing log4j.logger.org.apache.pig=debug – Uselesssss Mar 26 '13 at 04:04
  • 2013-03-26 09:36:28,054 [main] INFO org.apache.pig.tools.pigstats.SimplePigStats - Script Statistics: HadoopVersion PigVersion UserId StartedAt FinishedAt Features 1.1.1 0.10.1-SNAPSHOT vishal 2013-03-26 09:36:22 2013-03-26 09:36:28 UNKNOWN Failed! Failed Jobs: JobId Alias Feature Message Outputs job_local_0001 A,B MAP_ONLY Message: Job failed! Error - NA file:/tmp/temp1667865178/tmp-477995688, Input(s): Failed to read data from "/home/vishal/BaseballExampleForPig" – Uselesssss Mar 26 '13 at 04:05
  • Output(s): Failed to produce result in "file:/tmp/temp1667865178/tmp-477995688" Job DAG: job_local_0001 2013-03-26 09:36:28,055 [main] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - Failed! 2013-03-26 09:36:28,064 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1066: Unable to open iterator for alias B Details at logfile: /home/vishal/pig_1364270780503.log – Uselesssss Mar 26 '13 at 04:05
  • Hey Lonard I am running the script in local mode,still I am getting the same issue..What could be the problem Thanks – Uselesssss Apr 02 '13 at 05:55
  • Are you sure the problem is your UDF? What happens if you dump A instead of B? Does it work? – DMulligan Apr 16 '13 at 08:16
  • Hi AFinkelstein,,yes it is working fine .Where could be the problem – Uselesssss Apr 17 '13 at 04:09
  • You sure the files paths are valid? /home/vishal/exampleforPIG1 or /home/vishal/BaseballExampleForPig – jaguarpaw Apr 23 '13 at 16:58
  • yes jaguarpaw the paths are valid – Uselesssss Apr 24 '13 at 17:31
  • For people who found this post when looking for [ERROR 1066: Unable to open iterator for alias](http://stackoverflow.com/questions/34495085/error-1066-unable-to-open-iterator-for-alias-in-pig-generic-solution) here is a [generic solution](http://stackoverflow.com/a/34495086/983722). – Dennis Jaheruddin Dec 28 '15 at 15:33

5 Answers5

0

Well two things,

  1. If all you want to do is typecast to upper/lower case, why not use the inbuilt functions UPPER/LOWER. You can find the usage in the reference manuals.

  2. If you want to continue in the same method, it should be
    B = FOREACH A GENERATE UPPER(exchange);
    You have already defined it as DEFINE UPPER com.first.UPPER();

ysr
  • 301
  • 2
  • 5
0

I faced this issue and after breaking my head I found that the flaw was in the input data, even though I was cleaning by replacing null. I had a single record which had fields like '(null)', and it was causing everything to fail. Just check this once, if you have bad records like this.

java_enthu
  • 2,279
  • 7
  • 44
  • 74
0

Its the avro version which caused this error for me. I was using avro-1.7.6.jar. Changing it to avro-1.4.0.jar solved my issue.

0

Are you running a pig 0.12.0 or earlier jar against hadoop 2.2, if this is the case then I managed to get around this error by recompiling the pig jar from src, here is a summary of the steps involved on a debian type box

  1. download the pig-0.12.0.tar.gz
  2. unpack the jar and set permissions
  3. then inside the unpacked directory compile the src with 'ant clean jar -Dhadoopversion=23' then you need to get the jar on your class-path in maven, for example, in the same directory

mvn install:install-file -Dfile=pig.jar -DgroupId={set a groupId}- DartifactId={set a artifactId} -Dversion=1.0 -Dpackaging=jar

or if in eclipse then add jar as external libary/dependency

I was getting your exact trace trying to run pig 12 in a hadoop 2.2.0 and the above steps worked for me

UPDATE I posted my issue on the pig jira and they responded. They have a pig jar already compiled for hadoop2 pig-h2.jar here http://search.maven.org/#artifactdetails|org.apache.pig|pig|0.12.0|jar a maven tag for this jar is

org.apache.pig pig h2 0.12.0 provided

vk_only
  • 39
  • 4
0

Safe mode is also on of reason for this exception run the below command

hadoop dfsadmin -safemode leave

y durga prasad
  • 1,184
  • 8
  • 11