当前位置:网站首页>Flink SQL (III) connects to the external system system and JDBC
Flink SQL (III) connects to the external system system and JDBC
2022-07-26 13:54:00 【ambitfly】
file system
Another very common type of external system is the file system (File System) 了 .Flink Provides a connection to the file system Connector , Support reading and writing data from local or distributed file systems . This connector is built into Flink Medium , So there is no need to introduce additional dependencies to use it .
Here is an example of connecting to a file system :
CREATE TABLE MyTable (
column_name1 INT,
column_name2 STRING,
...
part_name1 INT,
part_name2 STRING
) PARTITIONED BY (part_name1, part_name2) WITH (
'connector' = 'filesystem', -- Connector type
'path' = '...', -- File path
'format' = '...' -- File format
)
Here it is WITH Before using PARTITIONED BY Partition the data . File system connector support Access to partition files .
JDBC
The relational data table itself is SQL Where it was first applied , Therefore, we also hope to read and write table data directly to the relational database .Flink Provided JDBC The connector can be connected through JDBC The driver (driver) To any relational type Database read and write data , such as MySQL、PostgreSQL、Derby etc. .
As TableSink When writing data to the database , The mode of operation depends on how the table is created DDL Whether the primary key is defined (primary key). If there is a primary key , that JDBC The connector will be inserted with an update (Upsert) mode , You can send a message to the external database according to the specified key (key) Update (UPDATE) And delete (DELETE) operation , If there is no primary key defined , Then we will add (Append) Run in mode , Update and delete operations are not supported .
Introduce dependencies
Want to be in Flink Used in program JDBC The connector , The following dependencies need to be introduced :
<dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-connector-jdbc_${scala.binary.version}</artifactId> <version>${flink.version}</version> </dependency>Besides , To connect to a specific database , We also use to introduce related drive dependencies , such as MySQL:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency>establish JDBC surface
establish JDBC The method of the table is the same as before Upsert Kafka Be the same in essentials while differing in minor points . Here is a concrete example :
-- Create a connection to MySQL Of surface CREATE TABLE MyTable ( id BIGINT, name STRING, age INT, status BOOLEAN, PRIMARY KEY (id) NOT ENFORCED ) WITH ( 'connector' = 'jdbc', 'url' = 'jdbc:mysql://localhost:3306/mydatabase', 'table-name' = 'users' ); -- Put another table T Data written to MyTable In the table INSERT INTO MyTable SELECT id, name, age, status FROM T; Here we create the table DDL The primary key is defined in , So the data will be in Upsert Mode write to MySQL In the table ; And then MySQL The connection of , It's through WITH In Clause url Defined . Pay attention to writing MySQL The real table name in is users, and MyTable It's registered in Flink Tables in the table environment .
边栏推荐
- 2022-07-26日报:Alphafold DB数据库建立一周年,官推盘点亮点研究
- Polymorphic case - making drinks
- Pytoch learning notes (III) use, modification, training (cpu/gpu) and verification of the model
- Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation
- POM file details
- Add a display horizontal line between idea methods
- The difference between V-model and.Sync modifier
- Team research and development from ants' foraging process (Reprint)
- Understand the meaning of length in MySQL data types
- Red * is added to the input box to indicate mandatory items
猜你喜欢
Control the probability of random winning [C | random]

Pytoch learning notes (I) installation and use of common functions

白帽子揭秘:互联网千亿黑产吓退马斯克

In 2022, we "sent away" so many Internet products in only one month

天翼云Web应用防火墙(边缘云版)支持检测和拦截Apache Spark shell命令注入漏洞

.net6 encounter with the League of heroes - create a game assistant according to the official LCU API

上一次听到易趣,还是上一次

Tdsql-c serverless: help start-ups achieve cost reduction and efficiency increase

【着色器实现Overlay重新覆盖变装效果_Shader效果第九篇】

聚力打造四个“高地”,携手合作伙伴共铸国云!
随机推荐
Ten thousand words long article, talking about the blueprint of enterprise digital modeling
[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve
Time complexity analysis of bubble sorting
聚力打造四个“高地”,携手合作伙伴共铸国云!
redis学习笔记
Parent class reference to child class (parent class reference points to child class object)
C语言_结构体和数组的结合
Win11+vs2019 configuration yolox
[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
Comparison between SIGMOD function and softmax function
官宣!艾德韦宣集团与百度希壤达成深度共创合作
重押海外:阿里、京东、顺丰再拼“内力”
Sequence traversal of binary tree (implemented in C language)
Difference between base addressing and index addressing
Technology sharing | gtid that needs to be configured carefully_ mode
MySQL's practice of SQL analysis and optimization from the index principle
Algorithm -- continuous sequence (kotlin)
Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation
The.Net webapi uses groupname to group controllers to render the swagger UI
Circular queue (implemented in C language)