FlinkUserClassLoader in AggregateFunction

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

FlinkUserClassLoader in AggregateFunction

chiggi_dev
Hi All,

Is there any other way to get hold of the FlinkUserClassLoaderother than the RuntimeContext?

The problem is, AggregateFunction cant be a RichFunction. I understand that's because of the state merging issue(from a thread here earlier). Now, I need DynamicClassLoading in AggregateFunction. And apparently, the only way to get a UserClassLoader is through the RuntimeContext.


Any workaround around this? Or someway I can create my custom UserClassLoader in the AggregateFunction?

Thanks in advance!

Chirag
Reply | Threaded
Open this post in threaded view
|

Re: FlinkUserClassLoader in AggregateFunction

Aljoscha Krettek
Hi,

you are right in that you can't get it from the RuntimeContext because AggregateFunction doesn't have access to that. As an alternative, you can use Thread.currentThread().getContextClassLoader(), which always should have the user-code ClassLoader set.

Best,
Aljoscha

On 4. Oct 2018, at 12:14, Chirag Dewan <[hidden email]> wrote:

Hi All,

Is there any other way to get hold of the FlinkUserClassLoaderother than the RuntimeContext?

The problem is, AggregateFunction cant be a RichFunction. I understand that's because of the state merging issue(from a thread here earlier). Now, I need DynamicClassLoading in AggregateFunction. And apparently, the only way to get a UserClassLoader is through the RuntimeContext.


Any workaround around this? Or someway I can create my custom UserClassLoader in the AggregateFunction?

Thanks in advance!

Chirag

Reply | Threaded
Open this post in threaded view
|

Re: FlinkUserClassLoader in AggregateFunction

chiggi_dev
That worked pretty well. Thank you so much Aljoscha :) 

On Thursday, 4 October, 2018, 5:40:17 PM IST, Aljoscha Krettek <[hidden email]> wrote:


Hi,

you are right in that you can't get it from the RuntimeContext because AggregateFunction doesn't have access to that. As an alternative, you can use Thread.currentThread().getContextClassLoader(), which always should have the user-code ClassLoader set.

Best,
Aljoscha

On 4. Oct 2018, at 12:14, Chirag Dewan <[hidden email]> wrote:

Hi All,

Is there any other way to get hold of the FlinkUserClassLoaderother than the RuntimeContext?

The problem is, AggregateFunction cant be a RichFunction. I understand that's because of the state merging issue(from a thread here earlier). Now, I need DynamicClassLoading in AggregateFunction. And apparently, the only way to get a UserClassLoader is through the RuntimeContext.


Any workaround around this? Or someway I can create my custom UserClassLoader in the AggregateFunction?

Thanks in advance!

Chirag