Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create UDF with optional 2nd argument #85

Closed
rjurney opened this issue Jan 5, 2014 · 10 comments
Closed

Unable to create UDF with optional 2nd argument #85

rjurney opened this issue Jan 5, 2014 · 10 comments

Comments

@rjurney
Copy link

rjurney commented Jan 5, 2014

How can I create a UDF with an optional 2nd argument? Two call() methods isn't working.

@matthayes
Copy link
Contributor

You could create two constructors. One constructor has one argument and the other constructor has two arguments.

@rjurney
Copy link
Author

rjurney commented Jan 5, 2014

I've tried that. There are two problems:

  1. I have to catch an IOException to call call()
  2. I have to return something to call call().

Hmmm I'll try again. Neither of those should block me.

On Sun, Jan 5, 2014 at 12:12 PM, Matt Hayes notifications@github.comwrote:

You could create two constructors. One constructor has one argument and
the other constructor has two arguments.


Reply to this email directly or view it on GitHubhttps://github.com//issues/85#issuecomment-31614088
.

Russell Jurney twitter.com/rjurney russell.jurney@gmail.com datasyndrome.com

@matthayes
Copy link
Contributor

Oh I misunderstood I think. I thought you meant the constructor. Are you using SimpleEvalFunc? I don't think it supports this use case of a 2nd optional argument. If you look in the implementation of exec() you see this

// check right number of arguments
if (input.size() != pvec.length)
  throw new IOException(String.format("%s: got %d arguments, expected %d.", _method_signature(), input.size(), pvec.length));

It expects there to be a call() method and it checks that the input tuple has the same number of values as there are arguments in the call() method.

I suggest just using EvalFunc then if you want optional parameters.

@rjurney
Copy link
Author

rjurney commented Jan 5, 2014

I thnk I made it work as you suggested. Testing now, but need to know how
to run just one test or it takes a half hour.

On Sunday, January 5, 2014, Matt Hayes wrote:

Oh I misunderstood I think. I thought you meant the constructor. Are you
using SimpleEvalFunc? I don't think it supports this use case of a 2nd
optional argument. If you look in the implementation of exec() you see this

// check right number of arguments
if (input.size() != pvec.length)
throw new IOException(String.format("%s: got %d arguments, expected %d.", _method_signature(), input.size(), pvec.length));

It expects there to be a call() method and it checks that the input tuple
has the same number of values as there are arguments in the call() method.

I suggest just using EvalFunc then if you want optional parameters.


Reply to this email directly or view it on GitHubhttps://github.com//issues/85#issuecomment-31614362
.

Russell Jurney twitter.com/rjurney russell.jurney@gmail.com datasyndrome.com

@rjurney
Copy link
Author

rjurney commented Jan 5, 2014

Using two constructors doesn't work. I am using SimpleEvalFunc. Ok, I will try using EvalFunc.

@rjurney
Copy link
Author

rjurney commented Jan 5, 2014

Is there some way to modify SimpleEvalFunc so that I can use two constructors? I like using it.

@matthayes
Copy link
Contributor

I think you should be able to have multiple constructors with SimpleEvalFunc. You just can't have multiple overloaded call implementations. You just need to ensure each calls super(). What is the problem you are having?

@rjurney
Copy link
Author

rjurney commented Jan 5, 2014

I created call(String input) that calls call(String input, String path)
with default path. It fails with the same error as before: expected 2, got
1.

On Sunday, January 5, 2014, Matt Hayes wrote:

I think you should be able to have multiple constructors with
SimpleEvalFunc. You just can't have multiple overloaded call
implementations. You just need to ensure each calls super(). What is the
problem you are having?


Reply to this email directly or view it on GitHubhttps://github.com//issues/85#issuecomment-31614937
.

Russell Jurney twitter.com/rjurney russell.jurney@gmail.com datasyndrome.com

@matthayes
Copy link
Contributor

the call method is not a constructor

On Jan 5, 2014, at 1:11 PM, Russell Jurney notifications@github.com wrote:

I created call(String input) that calls call(String input, String path)
with default path. It fails with the same error as before: expected 2, got
1.

On Sunday, January 5, 2014, Matt Hayes wrote:

I think you should be able to have multiple constructors with
SimpleEvalFunc. You just can't have multiple overloaded call
implementations. You just need to ensure each calls super(). What is the
problem you are having?

�\
Reply to this email directly or view it on GitHubhttps://github.com//issues/85#issuecomment-31614937
.

Russell Jurney twitter.com/rjurney russell.jurney@gmail.com datasyndrome.com

Reply to this email directly or view it on GitHub.

@rjurney
Copy link
Author

rjurney commented Jan 5, 2014

Good call. Lemme take another look.

On Sunday, January 5, 2014, Matt Hayes wrote:

the call method is not a constructor

On Jan 5, 2014, at 1:11 PM, Russell Jurney <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>>
wrote:

I created call(String input) that calls call(String input, String path)
with default path. It fails with the same error as before: expected 2,
got
1.

On Sunday, January 5, 2014, Matt Hayes wrote:

I think you should be able to have multiple constructors with
SimpleEvalFunc. You just can't have multiple overloaded call
implementations. You just need to ensure each calls super(). What is
the
problem you are having?


Reply to this email directly or view it on GitHub<
https://github.com/linkedin/datafu/issues/85#issuecomment-31614937>
.

Russell Jurney twitter.com/rjurney russell.jurney@gmail.com<javascript:_e({}, 'cvml', 'russell.jurney@gmail.com');>
datasyndrome.com

Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHubhttps://github.com//issues/85#issuecomment-31616199
.

Russell Jurney twitter.com/rjurney russell.jurney@gmail.com datasyndrome.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants