FAQ

[Pig-user] Boolean pig UDF constructor

Meghana narasimhan
Nov 8, 2012 at 6:30 pm
Hi All,

Can I pass in a boolean value to Pig UDF constructor with Pig 0.9.2?

I have a constructor :

public GenStartEndDate(boolean mtdNoGlob) {

this.mtdNoGlob = mtdNoGlob;

}


I am instantiating it in my Pig script :


DEFINE START_END_DATE com.demandmedia.dig.udf.GenStartEndDate(false);


I get :


org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1000: Error
during parsing. <line 4, column 62> mismatched input 'false' expecting
RIGHT_PAREN

at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1641)

at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1584)

at org.apache.pig.PigServer.registerQuery(PigServer.java:584)

at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:967)

at org.apache.pig.pigunit.pig.GruntParser.processPig(GruntParser.java:61)

at
org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:386)

at
org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:189)

at org.apache.pig.pigunit.pig.PigServer.registerScript(PigServer.java:53)

at org.apache.pig.pigunit.PigTest.registerScript(PigTest.java:160)

at org.apache.pig.pigunit.PigTest.runScript(PigTest.java:170)

at
com.demandmedia.dig.incite.TestSiteUrlDaily.testBasic(TestSiteUrlDaily.java:84)

Caused by: Failed to parse: <line 4, column 62> mismatched input 'false'
expecting RIGHT_PAREN

at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:222)

at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:164)

at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1633)

... 43 more


I also tried :

DEFINE START_END_DATE com.demandmedia.dig.udf.GenStartEndDate('false');


with :


<line 138, column 10> Failed to generate logical plan. Nested exception:
java.lang.RuntimeException: could not instantiate
'com.demandmedia.dig.udf.GenStartEndDate' with arguments '[false]'

at
org.apache.pig.parser.LogicalPlanBuilder.buildUDF(LogicalPlanBuilder.java:912)

at
org.apache.pig.parser.LogicalPlanGenerator.func_eval(LogicalPlanGenerator.java:7047)

at
org.apache.pig.parser.LogicalPlanGenerator.projectable_expr(LogicalPlanGenerator.java:8583)

at
org.apache.pig.parser.LogicalPlanGenerator.var_expr(LogicalPlanGenerator.java:8358)

at
org.apache.pig.parser.LogicalPlanGenerator.expr(LogicalPlanGenerator.java:7711)


What am I doing wrong?

- Meg
reply

Search Discussions

3 responses

  • Jonathan Coveney at Nov 8, 2012 at 6:35 pm
    UDF's can only be given String arguments, period. So you can pass it a
    boolean in String form and parse it.


    2012/11/8 meghana narasimhan <meg...@...com>
    Hi All,

    Can I pass in a boolean value to Pig UDF constructor with Pig 0.9.2?

    I have a constructor :

    public GenStartEndDate(boolean mtdNoGlob) {

    this.mtdNoGlob = mtdNoGlob;

    }


    I am instantiating it in my Pig script :


    DEFINE START_END_DATE com.demandmedia.dig.udf.GenStartEndDate(false);


    I get :


    org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1000: Error
    during parsing. <line 4, column 62> mismatched input 'false' expecting
    RIGHT_PAREN

    at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1641)

    at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1584)

    at org.apache.pig.PigServer.registerQuery(PigServer.java:584)

    at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:967)

    at org.apache.pig.pigunit.pig.GruntParser.processPig(GruntParser.java:61)

    at

    org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:386)

    at

    org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:189)

    at org.apache.pig.pigunit.pig.PigServer.registerScript(PigServer.java:53)

    at org.apache.pig.pigunit.PigTest.registerScript(PigTest.java:160)

    at org.apache.pig.pigunit.PigTest.runScript(PigTest.java:170)

    at

    com.demandmedia.dig.incite.TestSiteUrlDaily.testBasic(TestSiteUrlDaily.java:84)

    Caused by: Failed to parse: <line 4, column 62> mismatched input 'false'
    expecting RIGHT_PAREN

    at
    org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:222)

    at
    org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:164)

    at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1633)

    ... 43 more


    I also tried :

    DEFINE START_END_DATE com.demandmedia.dig.udf.GenStartEndDate('false');


    with :


    <line 138, column 10> Failed to generate logical plan. Nested exception:
    java.lang.RuntimeException: could not instantiate
    'com.demandmedia.dig.udf.GenStartEndDate' with arguments '[false]'

    at

    org.apache.pig.parser.LogicalPlanBuilder.buildUDF(LogicalPlanBuilder.java:912)

    at

    org.apache.pig.parser.LogicalPlanGenerator.func_eval(LogicalPlanGenerator.java:7047)

    at

    org.apache.pig.parser.LogicalPlanGenerator.projectable_expr(LogicalPlanGenerator.java:8583)

    at

    org.apache.pig.parser.LogicalPlanGenerator.var_expr(LogicalPlanGenerator.java:8358)

    at

    org.apache.pig.parser.LogicalPlanGenerator.expr(LogicalPlanGenerator.java:7711)


    What am I doing wrong?

    - Meg
  • Meghana narasimhan at Nov 8, 2012 at 6:42 pm
    Thanks Jonathan! Will do.

    On Thu, Nov 8, 2012 at 10:35 AM, Jonathan Coveney wrote:

    UDF's can only be given String arguments, period. So you can pass it a
    boolean in String form and parse it.


    2012/11/8 meghana narasimhan <meg...@...com>
    Hi All,

    Can I pass in a boolean value to Pig UDF constructor with Pig 0.9.2?

    I have a constructor :

    public GenStartEndDate(boolean mtdNoGlob) {

    this.mtdNoGlob = mtdNoGlob;

    }


    I am instantiating it in my Pig script :


    DEFINE START_END_DATE com.demandmedia.dig.udf.GenStartEndDate(false);


    I get :


    org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1000: Error
    during parsing. <line 4, column 62> mismatched input 'false' expecting
    RIGHT_PAREN

    at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1641)

    at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1584)

    at org.apache.pig.PigServer.registerQuery(PigServer.java:584)

    at
    org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:967)
    at org.apache.pig.pigunit.pig.GruntParser.processPig(GruntParser.java:61)

    at

    org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:386)
    at

    org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:189)
    at org.apache.pig.pigunit.pig.PigServer.registerScript(PigServer.java:53)

    at org.apache.pig.pigunit.PigTest.registerScript(PigTest.java:160)

    at org.apache.pig.pigunit.PigTest.runScript(PigTest.java:170)

    at

    com.demandmedia.dig.incite.TestSiteUrlDaily.testBasic(TestSiteUrlDaily.java:84)
    Caused by: Failed to parse: <line 4, column 62> mismatched input 'false'
    expecting RIGHT_PAREN

    at
    org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:222)

    at
    org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:164)

    at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1633)

    ... 43 more


    I also tried :

    DEFINE START_END_DATE com.demandmedia.dig.udf.GenStartEndDate('false');


    with :


    <line 138, column 10> Failed to generate logical plan. Nested exception:
    java.lang.RuntimeException: could not instantiate
    'com.demandmedia.dig.udf.GenStartEndDate' with arguments '[false]'

    at

    org.apache.pig.parser.LogicalPlanBuilder.buildUDF(LogicalPlanBuilder.java:912)
    at

    org.apache.pig.parser.LogicalPlanGenerator.func_eval(LogicalPlanGenerator.java:7047)
    at

    org.apache.pig.parser.LogicalPlanGenerator.projectable_expr(LogicalPlanGenerator.java:8583)
    at

    org.apache.pig.parser.LogicalPlanGenerator.var_expr(LogicalPlanGenerator.java:8358)
    at

    org.apache.pig.parser.LogicalPlanGenerator.expr(LogicalPlanGenerator.java:7711)

    What am I doing wrong?

    - Meg
  • Prashant Kommireddi at Nov 8, 2012 at 6:43 pm
    Hi Meghana,

    UDFs accept String arguments in the constructor. You would have to
    pass in the Boolean value as a string ('true' or 'false') and handle
    that in your constructor.

    Sent from my iPhone

    On Nov 8, 2012, at 10:30 AM, meghana narasimhan
    wrote:
    Hi All,

    Can I pass in a boolean value to Pig UDF constructor with Pig 0.9.2?

    I have a constructor :

    public GenStartEndDate(boolean mtdNoGlob) {

    this.mtdNoGlob = mtdNoGlob;

    }


    I am instantiating it in my Pig script :


    DEFINE START_END_DATE com.demandmedia.dig.udf.GenStartEndDate(false);


    I get :


    org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1000: Error
    during parsing. <line 4, column 62> mismatched input 'false' expecting
    RIGHT_PAREN

    at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1641)

    at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1584)

    at org.apache.pig.PigServer.registerQuery(PigServer.java:584)

    at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:967)

    at org.apache.pig.pigunit.pig.GruntParser.processPig(GruntParser.java:61)

    at
    org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:386)

    at
    org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:189)

    at org.apache.pig.pigunit.pig.PigServer.registerScript(PigServer.java:53)

    at org.apache.pig.pigunit.PigTest.registerScript(PigTest.java:160)

    at org.apache.pig.pigunit.PigTest.runScript(PigTest.java:170)

    at
    com.demandmedia.dig.incite.TestSiteUrlDaily.testBasic(TestSiteUrlDaily.java:84)

    Caused by: Failed to parse: <line 4, column 62> mismatched input 'false'
    expecting RIGHT_PAREN

    at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:222)

    at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:164)

    at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1633)

    ... 43 more


    I also tried :

    DEFINE START_END_DATE com.demandmedia.dig.udf.GenStartEndDate('false');


    with :


    <line 138, column 10> Failed to generate logical plan. Nested exception:
    java.lang.RuntimeException: could not instantiate
    'com.demandmedia.dig.udf.GenStartEndDate' with arguments '[false]'

    at
    org.apache.pig.parser.LogicalPlanBuilder.buildUDF(LogicalPlanBuilder.java:912)

    at
    org.apache.pig.parser.LogicalPlanGenerator.func_eval(LogicalPlanGenerator.java:7047)

    at
    org.apache.pig.parser.LogicalPlanGenerator.projectable_expr(LogicalPlanGenerator.java:8583)

    at
    org.apache.pig.parser.LogicalPlanGenerator.var_expr(LogicalPlanGenerator.java:8358)

    at
    org.apache.pig.parser.LogicalPlanGenerator.expr(LogicalPlanGenerator.java:7711)


    What am I doing wrong?

    - Meg

Related Discussions

Discussion Navigation
viewthread | post