You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by simon peyer <si...@soom-it.ch> on 2016/07/07 08:38:54 UTC
Accessing external DB inside RichFlatMap Function
Hi guys
Is there a easy way to handle external DB connections inside a RichFlatMap Function?
--Thanks Simon
Re: Accessing external DB inside RichFlatMap Function
Posted by Kostas Kloudas <k....@data-artisans.com>.
Yes, Chesnay is right. You can open and close the connection in
the open() and close() methods of your RichFlatMapFunction.
Kostas
> On Jul 7, 2016, at 11:03 AM, Chesnay Schepler <ch...@apache.org> wrote:
>
> Couldn't he do the same thing in his RichFlatMap?
>
> open the db connection in open(), close it in close(), do stuff within these calls.
>
> On 07.07.2016 10:58, Kostas Kloudas wrote:
>> Hi Simon,
>>
>> If your job reads or writes to a DB, I would suggest to use one of the already existing Flink sources or sinks,
>> as this allows for efficient connection handling and managing.
>>
>> If you want to write intermediate data to a DB from an operator, then I suppose that you should implement
>> your own custom operator that opens a DB connection in the open() method and closes it at close().
>> If you are planning to do so, I think that code of your custom operator would be the same as the StreamFlatMap,
>> with the addition of the openDBConnection method in the open(), and you should also override the close() method
>> of the AbstractUdfStreamOperator to 1) call super.close() and 2) close the db connection.
>>
>> Let me know if this works,
>> Kostas
>>
>>
>>> On Jul 7, 2016, at 10:38 AM, simon peyer <si...@soom-it.ch> wrote:
>>>
>>> Hi guys
>>>
>>> Is there a easy way to handle external DB connections inside a RichFlatMap Function?
>>>
>>> --Thanks Simon
>>
>
Re: Accessing external DB inside RichFlatMap Function
Posted by Chesnay Schepler <ch...@apache.org>.
Couldn't he do the same thing in his RichFlatMap?
open the db connection in open(), close it in close(), do stuff within
these calls.
On 07.07.2016 10:58, Kostas Kloudas wrote:
> Hi Simon,
>
> If your job reads or writes to a DB, I would suggest to use one of the already existing Flink sources or sinks,
> as this allows for efficient connection handling and managing.
>
> If you want to write intermediate data to a DB from an operator, then I suppose that you should implement
> your own custom operator that opens a DB connection in the open() method and closes it at close().
> If you are planning to do so, I think that code of your custom operator would be the same as the StreamFlatMap,
> with the addition of the openDBConnection method in the open(), and you should also override the close() method
> of the AbstractUdfStreamOperator to 1) call super.close() and 2) close the db connection.
>
> Let me know if this works,
> Kostas
>
>
>> On Jul 7, 2016, at 10:38 AM, simon peyer <si...@soom-it.ch> wrote:
>>
>> Hi guys
>>
>> Is there a easy way to handle external DB connections inside a RichFlatMap Function?
>>
>> --Thanks Simon
>
Re: Accessing external DB inside RichFlatMap Function
Posted by Kostas Kloudas <k....@data-artisans.com>.
Hi Simon,
If your job reads or writes to a DB, I would suggest to use one of the already existing Flink sources or sinks,
as this allows for efficient connection handling and managing.
If you want to write intermediate data to a DB from an operator, then I suppose that you should implement
your own custom operator that opens a DB connection in the open() method and closes it at close().
If you are planning to do so, I think that code of your custom operator would be the same as the StreamFlatMap,
with the addition of the openDBConnection method in the open(), and you should also override the close() method
of the AbstractUdfStreamOperator to 1) call super.close() and 2) close the db connection.
Let me know if this works,
Kostas
> On Jul 7, 2016, at 10:38 AM, simon peyer <si...@soom-it.ch> wrote:
>
> Hi guys
>
> Is there a easy way to handle external DB connections inside a RichFlatMap Function?
>
> --Thanks Simon