Pass a method as parameter

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Pass a method as parameter

Soheil Pourbafrani
Is it possible in Flink to write a method A that we can give it a written function's name B and function A will apply function B to DataStream?
Reply | Threaded
Open this post in threaded view
|

Re: Pass a method as parameter

Hequn Cheng
Hi Soheil,

What do you mean by "give it a written function's name B" and "function A will apply function B"? Do you mean function A override B? 
Perhaps the DataStream api guide[1] may gives you some guidance.

Best, Hequn


On Sun, Jul 8, 2018 at 1:21 PM, Soheil Pourbafrani <[hidden email]> wrote:
Is it possible in Flink to write a method A that we can give it a written function's name B and function A will apply function B to DataStream?

Reply | Threaded
Open this post in threaded view
|

Re: Pass a method as parameter

Rong Rong
Hi Soheil,

I think I knew what you meant by passing a function's name B to another method A: assuming in function "A" you are trying to dynamically load another function "B" based on either (1) some characteristic of the message in your data stream, or (2) some configuration during start up.
And I further assume here "method A" is part of your job graph, otherwise it would be as easy to just get rid of it.

You can definitely include "function B" in your job JAR and ship it over to the execution cluster; and then simple use Classloader to load by name and instantiate. However I am not sure this is the best programming paradigm.

To add to Hequn's comment [1], some alternatives you can try to eliminate the need to load function "B" during execution:
- Consolidate all of the "function B variances" into one function, and use a filterBy or a keyBy [2] for choosing different code path upon message arrival;
- You can use broadcast state [3] to assist you when choosing different code path if it depends on some external configurations;

Thanks,
Rong

On Sun, Jul 8, 2018 at 5:50 AM Hequn Cheng <[hidden email]> wrote:
Hi Soheil,

What do you mean by "give it a written function's name B" and "function A will apply function B"? Do you mean function A override B? 
Perhaps the DataStream api guide[1] may gives you some guidance.

Best, Hequn


On Sun, Jul 8, 2018 at 1:21 PM, Soheil Pourbafrani <[hidden email]> wrote:
Is it possible in Flink to write a method A that we can give it a written function's name B and function A will apply function B to DataStream?