World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
title: "Flink Connector: JDBC Catalog" slug: "/flink-connector/flink-catalog-jdbc" keyword: "flink connector jdbc catalog" license: "This software is licensed under the Apache License version 2."
Introduction
This document provides a comprehensive guide on configuring and using Apache Gravitino Flink connector to access the JDBC catalog managed by the Gravitino server.
Capabilities
JDBC Types
- MYSQL
- POSTGRESQL
Getting Started
Prerequisites
Place the following JAR files in the lib directory of your Flink installation:
- The Flink JDBC connector JAR that matches your Flink minor version
- The Gravitino Flink connector runtime JAR that matches your Flink minor version
- JDBC driver
| Flink version | Flink JDBC connector version | Gravitino runtime artifact |
|---|---|---|
| 1.19 | 3.3.0-1.19 |
gravitino-flink-connector-runtime-1.19_2.12-${gravitino-version}.jar |
| 1.20 | 3.3.0-1.20 |
gravitino-flink-connector-runtime-1.20_2.12-${gravitino-version}.jar |
| 2.1 | 4.1.0-2.1 |
gravitino-flink-connector-runtime-2.1-${gravitino-version}.jar |
| 2.2 | 4.1.0-2.2 |
gravitino-flink-connector-runtime-2.2-${gravitino-version}.jar |
For Flink 2.x, flink-connector-jdbc is split into core and per-database artifacts. Place all three JARs from the matching row in the classpath instead of a single combined JAR:
| Flink version | Core artifact | MySQL artifact | PostgreSQL artifact |
|---|---|---|---|
| 2.1 | flink-connector-jdbc-core-4.1.0-2.1.jar |
flink-connector-jdbc-mysql-4.1.0-2.1.jar |
flink-connector-jdbc-postgres-4.1.0-2.1.jar |
| 2.2 | flink-connector-jdbc-core-4.1.0-2.2.jar |
flink-connector-jdbc-mysql-4.1.0-2.2.jar |
flink-connector-jdbc-postgres-4.1.0-2.2.jar |
Next, when you create the JDBC catalog in Gravitino, add the flink.bypass.default-database property with the value of the default database name.
flink.bypass.default-database=db
For a PostgreSQL catalog, a Flink "database" corresponds to a PostgreSQL schema, not the PostgreSQL database itself. flink.bypass.default-database sets the schema Flink uses after USE CATALOG (for example, public) and falls back to jdbc-database when not set. The JDBC connection always targets jdbc-database, or the database in jdbc-url when jdbc-database is not set. SHOW TABLES FROM <schema> and table scans address tables within that database using the schema name.
:::note
flink.bypass.default-database does not select the PostgreSQL database to connect to. If you previously set it to a PostgreSQL database name for that purpose, set jdbc-database instead.
:::
If Flink must reach the database through a different address than the Gravitino server, set flink.bypass.base-url in the form jdbc:<dialect>://<host>:<port> (for example, jdbc:postgresql://127.0.0.1:5432/). It overrides the base-url derived from jdbc-url, and Flink validates it like a base-url set on a Flink JDBC catalog.
SQL Example
-- Suppose jdbc_catalog is the JDBC catalog name managed by Gravitino
USE CATALOG jdbc_catalog;
SHOW DATABASES;
-- +------------------+
-- | database name |
-- +------------------+
-- | mysql |
-- +------------------+
CREATE DATABASE jdbc_database;
-- [INFO] Execute statement succeed.
SHOW DATABASES;
-- +------------------+
-- | database name |
-- +------------------+
-- | mysql |
-- | jdbc_database |
-- +------------------+
USE jdbc_database;
-- [INFO] Execute statement succeed.
SET 'execution.runtime-mode' = 'batch';
-- [INFO] Execute statement succeed.
SET 'sql-client.execution.result-mode' = 'tableau';
-- [INFO] Execute statement succeed.
USE jdbc_database;
-- [INFO] Execute statement succeed.
SHOW TABLES;
-- Empty set
CREATE TABLE jdbc_table_a (
aa BIGINT NOT NULL PRIMARY KEY NOT ENFORCED,
bb BIGINT
);
-- [INFO] Execute statement succeed.
SHOW TABLES;
-- +--------------+
-- | table name |
-- +--------------+
-- | jdbc_table_a |
-- +--------------+
-- 1 row in set
INSERT INTO jdbc_table_a VALUES(1,2);
SELECT * FROM jdbc_table_a;
-- +----+----+
-- | aa | bb |
-- +----+----+
-- | 1 | 2 |
-- +----+----+
-- 1 row in set
INSERT INTO jdbc_table_a VALUES(2,3);
-- [INFO] Submitting SQL update statement to the cluster...
-- [INFO] SQL update statement has been successfully submitted to the cluster:
-- Job ID: bc320828d49b97b684ed9f622f1b8aca
INSERT INTO jdbc_table_a VALUES(1,4);
-- [INFO] Submitting SQL update statement to the cluster...
-- [INFO] SQL update statement has been successfully submitted to the cluster:
-- Job ID: bc320828d49b97b684ed9f622f1b8aca
SELECT * FROM jdbc_table_a;
-- +----+----+
-- | aa | bb |
-- +----+----+
-- | 1 | 4 |
-- | 2 | 3 |
-- +----+----+
-- 2 rows in set
Catalog Properties
Gravitino Flink connector will transform below property names which are defined in catalog properties to Flink JDBC connector configuration.
| Gravitino catalog property name | Flink JDBC connector configuration | Description |
|---|---|---|
jdbc-url |
base-url |
JDBC URL for the catalog. flink.bypass.base-url overrides the derived base-url. |
username |
username |
Username of the account |
password |
password |
Password of the account |
flink.bypass.default-database |
default-database |
Default database. For PostgreSQL, the default schema; falls back to jdbc-database. |
jdbc-database |
(see above) | The PostgreSQL database the catalog connects to. Optional when jdbc-url contains the database. |