1
Gather your connection details
To connect to ClickHouse with HTTP(S) you need this information:The details for your ClickHouse Cloud service are available in the ClickHouse Cloud console.
Select a service and click Connect:Choose HTTPS. Connection details are displayed in an example
curl command.If you’re using self-managed ClickHouse, the connection details are set by your ClickHouse administrator.2
Download and run Apache NiFi
For a new setup, download the binary from https://nifi.apache.org/download.html and start by running./bin/nifi.sh start3
Download the ClickHouse JDBC driver
- Visit the ClickHouse JDBC driver release page on GitHub and look for the latest JDBC release version
- In the release version, click on “Show all xx assets” and look for the JAR file containing the keyword “shaded” or “all”, for example,
clickhouse-jdbc-0.5.0-all.jar - Place the JAR file in a folder accessible by Apache NiFi and take note of the absolute path
4
Add DBCPConnectionPool Controller Service and configure its properties
- To configure a Controller Service in Apache NiFi, visit the NiFi Flow Configuration page by clicking on the “gear” button
-
Select the Controller Services tab and add a new Controller Service by clicking on the
+button at the top right -
Search for
DBCPConnectionPooland click on the “Add” button -
The newly added
DBCPConnectionPoolwill be in an Invalid state by default. Click on the “gear” button to start configuring - Under the “Properties” section, input the following values
- In the Settings section, change the name of the Controller Service to “ClickHouse JDBC” for easy reference
-
Activate the
DBCPConnectionPoolController Service by clicking on the “lightning” button and then the “Enable” button
- Check the Controller Services tab and ensure that the Controller Service is enabled
5
Read from a table using the ExecuteSQL processor
-
Add an
ExecuteSQLprocessor, along with the appropriate upstream and downstream processors -
Under the “Properties” section of the
ExecuteSQLprocessor, input the following values -
Start the
ExecuteSQLprocessor -
To confirm that the query has been processed successfully, inspect one of the
FlowFilein the output queue -
Switch view to “formatted” to view the result of the output
FlowFile
6
Write to a table using MergeRecord and PutDatabaseRecord processor
-
To write multiple rows in a single insert, we first need to merge multiple records into a single record. This can be done using the
MergeRecordprocessor -
Under the “Properties” section of the
MergeRecordprocessor, input the following values -
To confirm that multiple records are merged into one, examine the input and output of the
MergeRecordprocessor. Note that the output is an array of multiple input records Input Output -
Under the “Properties” section of the
PutDatabaseRecordprocessor, input the following values -
To confirm that each insert contains multiple rows, check that the row count in the table is incrementing by at least the value of “Minimum Number of Records” defined in
MergeRecord. - Congratulations - you have successfully loaded your data into ClickHouse using Apache NiFi !