主要解读:
1.Paimon和Hadoop 的包放到 lib
2.此处2中格式均可以: 'warehouse'='file:/tmp/paimon' 'warehouse'='file:///tmp/paimon'
3.数据持久化到了2中文件,断开连接。插入目标表任务不会中断,这个任务生命周期应该是服务器级别的流任务。再次连接后,创建catalog即可读取 word_count,但 word_table 再次连接后没有该表,这个应该是会话级别。
4. 可以在2中路径下看到持久化的文件和文件的组织形式。
Quick Start #
This documentation is a guide for using Paimon in Flink.
Jars #
Paimon currently supports Flink 1.19, 1.18, 1.17, 1.16, 1.15. We recommend the latest Flink version for a better experience.
Download the jar file with corresponding version.
Currently, paimon provides two types jar: one of which(the bundled jar) is used for read/write data, and the other(action jar) for operations such as manually compaction,
Version Type Jar
Flink 1.19 Bundled Jar paimon-flink-1.19-0.8.2.jar
Flink 1.18 Bundled Jar paimon-flink-1.18-0.8.2.jar
Flink 1.17 Bundled Jar paimon-flink-1.17-0.8.2.jar
Flink 1.16 Bundled Jar paimon-flink-1.16-0.8.2.jar
Flink 1.15 Bundled Jar paimon-flink-1.15-0.8.2.jar
Flink Action Action Jar paimon-flink-action-0.8.2.jar
You can also manually build bundled jar from the source code.
To build from source code, clone the git repository.
Build bundled jar with the following command.
mvn clean install -DskipTests
You can find the bundled jar in ./paimon-flink/paimon-flink-
Start #
Step 1: Download Flink
If you haven’t downloaded Flink, you can download Flink, then extract the archive with the following command.
tar -xzf flink-*.tgz
Step 2: Copy Paimon Bundled Jar
Copy paimon bundled jar to the lib directory of your Flink home.
cp paimon-flink-*.jar <FLINK_HOME>/lib/
Step 3: Copy Hadoop Bundled Jar
If the machine is in a hadoop environment, please ensure the value of the environment variable HADOOP_CLASSPATH include path to the common Hadoop libraries, you do not need to use the following pre-bundled Hadoop jar.
Download Pre-bundled Hadoop jar and copy the jar file to the lib directory of your Flink home.
cp flink-shaded-hadoop-2-uber-*.jar <FLINK_HOME>/lib/
Step 4: Start a Flink Local Cluster
In order to run multiple Flink jobs at the same time, you need to modify the cluster configuration in <FLINK_HOME>/conf/flink-conf.yaml.
taskmanager.numberOfTaskSlots: 2
To start a local cluster, run the bash script that comes with Flink:
<FLINK_HOME>/bin/start-cluster.sh
You should be able to navigate to the web UI at localhost:8081 to view the Flink dashboard and see that the cluster is up and running.
You can now start Flink SQL client to execute SQL scripts.
<FLINK_HOME>/bin/sql-client.sh
Step 5: Create a Catalog and a Table
Catalog
-- if you're trying out Paimon in a distributed environment,
-- the warehouse path should be set to a shared file system, such as HDFS or OSS
CREATE CATALOG my_catalog WITH (
'type'='paimon',
'warehouse'='file:/tmp/paimon'
);
USE CATALOG my_catalog;
-- create a word count table
CREATE TABLE word_count (
word STRING PRIMARY KEY NOT ENFORCED,
cnt BIGINT
);
Generic-Catalog
Step 6: Write Data
-- create a word data generator table
CREATE TEMPORARY TABLE word_table (
word STRING
) WITH (
'connector' = 'datagen',
'fields.word.length' = '1'
);
-- paimon requires checkpoint interval in streaming mode
SET 'execution.checkpointing.interval' = '10 s';
-- write streaming data to dynamic table
INSERT INTO word_count SELECT word, COUNT(*) FROM word_table GROUP BY word;
Step 7: OLAP Query
-- use tableau result mode
SET 'sql-client.execution.result-mode' = 'tableau';
-- switch to batch mode
RESET 'execution.checkpointing.interval';
SET 'execution.runtime-mode' = 'batch';
-- olap query the table
SELECT * FROM word_count;
You can execute the query multiple times and observe the changes in the results.
Step 8: Streaming Query
-- switch to streaming mode
SET 'execution.runtime-mode' = 'streaming';
-- track the changes of table and calculate the count interval statistics
SELECT interval
, COUNT(*) AS interval_cnt FROM
(SELECT cnt / 10000 AS interval
FROM word_count) GROUP BY interval
;
Step 9: Exit
Cancel streaming job in localhost:8081, then execute the following SQL script to exit Flink SQL client.
-- uncomment the following line if you want to drop the dynamic table and clear the files
-- DROP TABLE word_count;
-- exit sql-client
EXIT;
Stop the Flink local cluster.
./bin/stop-cluster.sh
Use Flink Managed Memory #
Paimon tasks can create memory pools based on executor memory which will be managed by Flink executor, such as managed memory in Flink task manager. It will improve the stability and performance of sinks by managing writer buffers for multiple tasks through executor.
The following properties can be set if using Flink managed memory:
Option Default Description
sink.use-managed-memory-allocator false If true, flink sink will use managed memory for merge tree; otherwise, it will create an independent memory allocator, which means each task allocates and manages its own memory pool (heap memory), if there are too many tasks in one Executor, it may cause performance issues and even OOM.
sink.managed.writer-buffer-memory 256M Weight of writer buffer in managed memory, Flink will compute the memory size, for writer according to the weight, the actual memory used depends on the running environment. Now the memory size defined in this property are equals to the exact memory allocated to write buffer in runtime.
Use In SQL Users can set memory weight in SQL for Flink Managed Memory, then Flink sink operator will get the memory pool size and create allocator for Paimon writer.
INSERT INTO paimon_table /*+ OPTIONS('sink.use-managed-memory-allocator'='true', 'sink.managed.writer-buffer-memory'='256M') */
SELECT * FROM ....;
Setting dynamic options #
When interacting with the Paimon table, table options can be tuned without changing the options in the catalog. Paimon will extract job-level dynamic options and take effect in the current session. The dynamic option’s key format is paimon.${catalogName}.${dbName}.${tableName}.${config_key}. The catalogName/dbName/tableName can be *, which means matching all the specific parts.
For example:
-- set scan.timestamp-millis=1697018249000 for the table mycatalog.default.T
SET 'paimon.mycatalog.default.T.scan.timestamp-millis' = '1697018249000';
SELECT * FROM T;
-- set scan.timestamp-millis=1697018249000 for the table default.T in any catalog
SET 'paimon.*.default.T.scan.timestamp-millis' = '1697018249000';
SELECT * FROM T;
Edit This Page
Copyright © 2024 The Apache Software Foundation. Apache Paimon, Paimon, and its feather logo are trademarks of The Apache Software Foundation.