Re: DB connection and query inside map function
Posted by
Fabian Hueske-2 on
Nov 28, 2016; 8:50am
URL: http://deprecated-apache-flink-user-mailing-list-archive.369.s1.nabble.com/DB-connection-and-query-inside-map-function-tp10342p10344.html
Hi Anastasios,
that's certainly possible. The most straight-forward approach would be a synchronous call to the database.
Because only one request is active at the same time, you do not need a thread pool.
You can establish the connection in the open() method of a RichMapFunction. The problem with this approach is that the synchronous requests can significantly increase the latency.
Doing the calls asynchronously and using a thread pool is not very easy because this would need to be integrated with Flink's checkpointing mechanism.
In fact, there is an effort to add a special Map operator that supports asynchronous calls (see FLIP-12 [1]).
We expect this to be included in the next minor release, Flink 1.2.
Hope this helps,
Fabian