Uselesssss
Uselesssss

Reputation: 2133

ERROR 1066: Unable to open iterator for alias in pig

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

Upvotes: 3

Views: 10006

Answers (5)

y durga prasad
y durga prasad

Reputation: 1202

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

hadoop dfsadmin -safemode leave

Upvotes: 0

vk_only
vk_only

Reputation: 39

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

Upvotes: 0

user3356307
user3356307

Reputation: 63

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.

Upvotes: 0

java_enthu
java_enthu

Reputation: 2327

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.

Upvotes: 0

ysr
ysr

Reputation: 301

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();

Upvotes: 0

Related Questions