• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flink JDBC Driver

Flink JDBC driver is a Java library for accessing and manipulating Apache Flink clusters by connecting to a Flink SQL gateway as the JDBC server.

This project is at an early stage. Feel free to file an issue if you meet any problems or have any suggestions.

Usage

Before using Flink JDBC driver, you need to start a Flink SQL gateway as the JDBC server and binds it with your Flink cluster. We now assume that you have a gateway started and connected to a running Flink cluster.

Use with a JDBC Tool

Use with Beeline

Beeline is the command line tool for accessing Apache Hive, but it also supports general JDBC drivers. To install Hive and beeline, see Hive documentation.

  1. Download flink-jdbc-driver-(VERSION).jar from the download page and add it to $HIVE_HOME/lib.
  2. Run beeline and connect to a Flink SQL gateway. You can specify the planner (blink or old) in the query parameter of the url. As Flink SQL gateway currently ignores user names and passwords, just leave them empty.
    beeline> !connect jdbc:flink://localhost:8083?planner=blink
    
  3. Execute any statement you want.

Sample Commands

Beeline version 2.2.0 by Apache Hive
beeline> !connect jdbc:flink://localhost:8083?planner=blink
Connecting to jdbc:flink://localhost:8083?planner=blink
Enter username for jdbc:flink://localhost:8083?planner=blink: 
Enter password for jdbc:flink://localhost:8083?planner=blink: 
Connected to: Apache Flink (version 1.10.0)
Driver: Flink Driver (version 0.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:flink://localhost:8083> CREATE TABLE T(
. . . . . . . . . . . . . . . >   a INT,
. . . . . . . . . . . . . . . >   b VARCHAR(10)
. . . . . . . . . . . . . . . > ) WITH (
. . . . . . . . . . . . . . . >   'connector.type' = 'filesystem',
. . . . . . . . . . . . . . . >   'connector.path' = 'file:///tmp/T.csv',
. . . . . . . . . . . . . . . >   'format.type' = 'csv',
. . . . . . . . . . . . . . . >   'format.derive-schema' = 'true'
. . . . . . . . . . . . . . . > );
No rows affected (0.158 seconds)
0: jdbc:flink://localhost:8083> INSERT INTO T VALUES (1, 'Hi'), (2, 'Hello');
No rows affected (4.747 seconds)
0: jdbc:flink://localhost:8083> SELECT * FROM T;
+----+--------+--+
| a  |   b    |
+----+--------+--+
| 1  | Hi     |
| 2  | Hello  |
+----+--------+--+
2 rows selected (0.994 seconds)
0: jdbc:flink://localhost:8083> 

Use with Tableau

Tableau is an interactive data visualization software. It supports Other Database (JDBC) connection from version 2018.3. You'll need Tableau with version >= 2018.3 to use Flink JDBC driver. For general usage of Other Database (JDBC) in Tableau, see Tableau documentation.

  1. Download flink-jdbc-driver-(VERSION).jar from the download page and add it to Tableau driver path.
    • Windows: C:\Program Files\Tableau\Drivers
    • Mac: ~/Library/Tableau/Drivers
    • Linux: /opt/tableau/tableau_driver/jdbc
  2. Select Other Database (JDBC) under Connect and fill in the url of Flink SQL gateway. You can specify the planner (blink or old) in the query parameter of the url. Select SQL92 dialect and leave user name and password empty.
  3. Hit Login button and use Tableau as usual.

Use with other JDBC Tools

Flink JDBC driver is a library for accessing Flink clusters through the JDBC API. Any tool supporting JDBC API can be used with Flink JDBC driver and Flink SQL gateway. See the documentation of your desired tool on how to use a JDBC driver.

Use with Java

Flink JDBC driver is a library for accessing Flink clusters through the JDBC API. For the general usage of JDBC in Java, see JDBC tutorial or Oracle JDBC documentation.

  1. Download flink-jdbc-driver-(VERSION).jar from the download page and add it to your classpath.
  2. Connect to a Flink SQL gateway in your Java code. You can specify the planner (blink or old) in the query parameter of the url.
  3. Execute any statement you want.

Sample.java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Sample {
	public static void main(String[] args) throws Exception {
		Connection connection = DriverManager.getConnection("jdbc:flink://localhost:8083?planner=blink");
		Statement statement = connection.createStatement();

		statement.executeUpdate("CREATE TABLE T(\n" +
			"  a INT,\n" +
			"  b VARCHAR(10)\n" +
			") WITH (\n" +
			"  'connector.type' = 'filesystem',\n" +
			"  'connector.path' = 'file:///tmp/T.csv',\n" +
			"  'format.type' = 'csv',\n" +
			"  'format.derive-schema' = 'true'\n" +
			")");
		statement.executeUpdate("INSERT INTO T VALUES (1, 'Hi'), (2, 'Hello')");
		ResultSet rs = statement.executeQuery("SELECT * FROM T");
		while (rs.next()) {
			System.out.println(rs.getInt(1) + ", " + rs.getString(2));
		}

		statement.close();
		connection.close();
	}
}

Output

1, Hi
2, Hello

More Repositories

1

flink-cdc-connectors

CDC Connectors for Apache Flinkยฎ
Java
4,956
star
2

flink-sql-cookbook

The Apache Flink SQL Cookbook is a curated collection of examples, patterns, and use cases of Apache Flink SQL. Many of the recipes are completely self-contained and can be run in Ververica Platform as is.
Dockerfile
842
star
3

flink-training-exercises

Java
552
star
4

sql-training

Java
543
star
5

flink-sql-gateway

Java
489
star
6

stateful-functions

Stateful Functions for Apache Flink
Java
276
star
7

flink-sql-benchmark

Java
102
star
8

ververica-platform-playground

Instructions for getting started with Ververica Platform on minikube.
Shell
89
star
9

frocksdb

C++
61
star
10

flink-statefun-workshop

Python
44
star
11

jupyter-vvp

Jupyter Integration for Flink SQL via Ververica Platform
Python
41
star
12

flink-training-troubleshooting

Java
40
star
13

lab-fraud-detection

Demo code for implementing and showcasing a Fraud Detection Engine with Apache Flink.
Java
30
star
14

streaming-ledger

Serializable ACID transactions on streaming data
Java
22
star
15

lab-flink-latency

Lab for testing different Flink job latency optimization techniques covered in a Flink Forward 2021 talk
Java
22
star
16

lab-flink-repository-analytics

Java
18
star
17

lab-sql-vs-datastream

Lab project to showcase Flink's performance differences between using a SQL query and implementing the same logic via the DataStream API
Java
13
star
18

flink-ecosystem

Ecosystem website for Apache Flink
TypeScript
12
star
19

tpc-ds-generators

Binaries for TPC-DS data generators
8
star
20

acwern

Flink visualization library for blogposts
TypeScript
6
star
21

ForSt

A Persistent Key-Value Store designed for Streaming processing
C++
4
star
22

demo-vvp-via-azure-pipelines

Java
3
star
23

pyflink-docs

pyflink documentation
Python
2
star
24

lab-vvp-pyflink

Java
2
star
25

flink-emr-terraform

Terraform module for creating AWS EMR Flink clusters.
HCL
1
star