This repository contains a functional prototype integrating Apache Flink with the new Apache IoTDB 2.0 Table Model.
Existing Flink-IoTDB connectors rely on the legacy Tree Model (root.sg.d1). With the release of IoTDB 2.0, a new Table Model was introduced to support standard SQL (INSERT, SELECT). This project demonstrates how to bridge Flink DataStreams with IoTDB's Table dialect, enabling SQL-based data ingestion and extraction.
The standard IoTDB Session API defaults to the Tree Model. Attempting to execute SQL queries (e.g., CREATE TABLE, SELECT * FROM table) using the legacy session results in syntax errors (e.g., Expecting ROOT path) because the dialect is incompatible.
This PoC implements a custom Flink SourceFunction that utilizes the TableSessionBuilder. This builder explicitly initializes the client-server handshake using the SQL dialect, allowing Flink to:
- Connect to IoTDB in Table Mode.
- Execute standard SQL queries (
SELECT * FROM machines). - Stream the
SessionDataSetrows into the Flink processing engine.
-
src/main/java/FlinkIoTDBTableSource.java- The core implementation.
- Implements Flink's
SourceFunction. - Manages the
ITableSessionlifecycle. - Streams data from IoTDB to Flink.
-
src/main/java/IoTDBDataGenerator.java- A utility script to initialize the Database and Table (
factory_db,machines). - Inserts sample mock data to verify the read operation.
- A utility script to initialize the Database and Table (
- Apache IoTDB 2.0+
- Apache Flink 1.18 libraries
- Java 8 or 11+
-
Open Command Prompt (cmd).
-
Navigate to your IoTDB
sbinfolder:cd C:\Users\.....................\apache-iotdb-2.0.6-all-bin\sbin\windows -
Fix PowerShell Path (Important): If your system cannot find PowerShell, run this command to temporarily set the path:
set PATH=%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%PATH%
(This ensures the start script can locate PowerShell to launch the server.)
-
Verify PowerShell: Type
powershelland press Enter. If it opens, typeexitto return to cmd. -
Start the Server: Run the standalone script:
start-standalone.bat
You should see:
Apache IoTDB 2.0+ (ConfigNode & DataNode running)
-
Open IntelliJ IDEA.
-
Click New Project.
-
Select Maven (on the left) and click Create.
-
Name the project:
IoTDB_Table_Test. -
Add Libraries (pom.xml): Open
pom.xmland add the following dependencies inside the<dependencies>section:<dependencies> <dependency> <groupId>org.apache.iotdb</groupId> <artifactId>iotdb-session</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-streaming-java</artifactId> <version>1.18.0</version> </dependency> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-clients</artifactId> <version>1.18.0</version> </dependency> </dependencies>
-
Generate Data: Run
IoTDBDataGenerator.main(). It will create the tablemachinesand insert mock data.>>> Connected explicitly in Table Mode! >>> Table Created! >>> Data Inserted via SQL! -
Start Flink Job: Run
FlinkIoTDBTableSource.main(). Watch the console for the streamed output:>>> Starting Flink Job... FLINK READ: 0 1770215090044 drill_01 warehouse_A 45.5 true
Below is the execution log verifying the data flow from IoTDB Table Mode to Flink.



