Using static variables inside Cascading

110 views Asked by At

When I start my MapReduce job I save the current timestamp as a Date object in a static variable of my main class.

Later when I want to read the value from a different class (such as my custom Cascading Filter or Cascading Function class) the job crashes with a java.lang.NullPointerException according to Driven.

Is it not possible to access a static variable within the Cascading logic? I have no idea why this doesn't work. The Date variable is definitely not null as I print it to console when the job is launched and afterwards it is not touched by any logic.

This is the class that throws the error. If I create a new Date (with the current time) within the operate() method everything works fine.

public class TimestampAppender extends BaseOperation implements Function {

public TimestampAppender(Fields fieldDeclaration) {
    super(Fields.ARGS);
}

public void operate(FlowProcess flowProcess, FunctionCall functionCall) {

    TupleEntry argument = functionCall.getArguments();

    Date timestamp = Main.timeFrameMiddle;
    String arg0 = argument.getString(0);
    String arg1 = argument.getString(1);

    Tuple result = new Tuple();
    result.addString(arg0);
    result.addString(arg1);
    result.addLong(timestamp.getTime());

    functionCall.getOutputCollector().add(result);
  }
}
1

There are 1 answers

0
pramesh On

it is not clear about Main.timeFrameMiddle.Could you please include Main class as well. If you are trying to get current time then you can do it within the cascading function.