2

The following code snippet is taken from this blog post:

val sensorTable = ??? // can be a CSV file, Kafka topic, database, or ...

// register the table source
tEnv.registerTableSource("sensors", sensorTable)

I would like to read data from a relational database. Does Flink have a TableSource for JDBC databases?

Fabian Hueske
  • 18,707
  • 2
  • 44
  • 49
Amit Dass
  • 41
  • 6

1 Answers1

5

In its current version (1.4.0, Dec. 2017), Flink does not provide a built-in TableSource to ingest data from a relational database.

However, there is a JDBCInputFormat that can be used. You can either

  • use it to read the data from the database using the DataSet API and register the DataSet as a Table or
  • implement a JdbcTableSource that wraps the JdbcInputFormat. A simple implementation of a JdbcTableSource should be easy to achieve. Implementing support for parallel reads, projection or filter push-down, requires more effort.
Fabian Hueske
  • 18,707
  • 2
  • 44
  • 49
  • Please share if any scala reference code for this . I am using Flink 1.3 version . – Amit Dass Dec 14 '17 at 12:56
  • [Starting with Flink 1.12 the DataSet API has been soft deprecated.](https://nightlies.apache.org/flink/flink-docs-release-1.17/docs/dev/dataset/overview/) – yokus Aug 27 '23 at 18:59