Grokbase Groups Pig user August 2010
FAQ
Hello!

I created custom UDF and I need to have different outputSchema columns(in one
case - 2 chararray fields, in the other - 3 chararray fields for
output) depends on UDF input parameter(mode_1 = 'one'):
..FLATTEN(myUDF('int, char', 'one'))

I overrided
@Override
public Schema getOutputSchema(Schema input){
Schema schema = new Schema();
// check mode_1 parameter 'one'- it's null because it will be set
// in evaluate func. only
if( mode_1!= null && mode_1.equal("one")){
schema.add(new FieldSchema("type", DataType.CHARARRAY));
schema.add(new FieldSchema("text", DataType.CHARARRAY));
return schema;
}
// default
schema.add(new FieldSchema("type", DataType.CHARARRAY));
schema.add(new FieldSchema("text", DataType.CHARARRAY));
schema.add(new FieldSchema("age", DataType.CHARARRAY));
return schema;
}
}
but this function is called before
@Override
public DataBag evaluate(Tuple input)
{
// get UDF mode parameter mode_1
Object xmode = input.get(1);
mode_1 = xmode.toString();
...
}
where I can check needed parameter 'one' - so I can't change schema defined
in getOutputSchema(...) function initially.

Is it a way to change OutputSchema from evaluate(...) ?

I tried to create a constructor
public myUDF(String param, String mode )
{
}
but it was never called. Only myUDF() - constructor without parameters
was called.

Class' static variable for mode down't work also.
I use Pig 0.3.0.

--
Best regards,
Serg.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
groupuser @
categoriespig, hadoop
postedAug 6, '10 at 12:31p
activeAug 6, '10 at 7:54p
posts2
users2
websitepig.apache.org

People

Translate

site design / logo © 2021 Grokbase