Apache Paimon is a unified data lake format for streaming and batch processing that supports high-throughput writes and low-latency queries. This topic describes how to read and write Paimon tables in EMR Serverless Spark.
Prerequisites
A workspace is created. Create a workspace.
Procedure
Step 1: Create an SQL session
-
Go to the Sessions page.
-
Log on to the EMR console.
-
In the left-side navigation pane, choose EMR Serverless > Spark.
-
On the Spark page, click the name of the target workspace.
-
On the EMR Serverless Spark page, click Sessions in the left-side navigation pane.
-
-
On the SQL Sessions page, click Create SQL Session.
-
On the Create SQL Session page, configure the parameters in the Spark Configuration section and click Create. Manage SQL sessions.
Spark reads and writes Paimon tables through catalogs. Select a catalog type based on your scenario. Manage data catalogs.
Data catalog
When using a data catalog, no session parameters are required. Click Catalogs on the Add Catalog page, then select the data catalog in your Spark SQL development environment.
NoteWe recommend EMR engine versions esr-4.3.0 or later, esr-3.3.0 or later, or esr-2.7.0 or later.
Custom catalog
Data Lake Formation (DLF)
spark.sql.catalog.<catalogName> org.apache.paimon.spark.SparkCatalog spark.sql.catalog.<catalogName>.metastore rest spark.sql.catalog.<catalogName>.uri http://cn-hangzhou-vpc.dlf.aliyuncs.com spark.sql.catalog.<catalogName>.warehouse <catalog_name> spark.sql.catalog.<catalogName>.token.provider dlf spark.sql.catalog.<catalogName>.dlf.access-key-id <access_key_id> spark.sql.catalog.<catalogName>.dlf.access-key-secret <access_key_secret>Parameters:
Parameter
Description
Example value
spark.sql.catalog.<catalogName>The catalog implementation.
Fixed value:
org.apache.paimon.spark.SparkCatalogspark.sql.catalog.<catalogName>.metastoreThe metadata storage method. Set to
restto use the DLF REST API.Fixed value:
restspark.sql.catalog.<catalogName>.uriThe DLF URI. Format:
http://<endpoint>-vpc.dlf.aliyuncs.com.http://cn-hangzhou-vpc.dlf.aliyuncs.comspark.sql.catalog.<catalogName>.warehouseThe warehouse path. For DLF, set this to the catalog name.
<catalog_name>spark.sql.catalog.<catalogName>.token.providerThe authentication provider. Set to
dlffor DLF.Fixed value:
dlfspark.sql.catalog.<catalogName>.dlf.access-key-idThe AccessKey ID of your Alibaba Cloud account or RAM user.
<access_key_id>spark.sql.catalog.<catalogName>.dlf.access-key-secretThe AccessKey secret of your Alibaba Cloud account or RAM user.
<access_key_secret>DLF-Legacy
The metadata is stored in DLF 1.0.
spark.sql.catalog.<catalogName> org.apache.paimon.spark.SparkCatalog spark.sql.catalog.<catalogName>.metastore dlf spark.sql.catalog.<catalogName>.dlf.catalog.id <catalog_name> spark.sql.catalog.<catalogName>.dlf.catalog.endpoint dlf-vpc.cn-hangzhou.aliyuncs.comParameters:
Parameter
Description
Example value
spark.sql.catalog.<catalogName>The catalog implementation.
Fixed value:
org.apache.paimon.spark.SparkCatalogspark.sql.catalog.<catalogName>.metastoreThe metadata storage method. Set to
dlfto use DLF as the metastore.Fixed value:
dlfspark.sql.catalog.<catalogName>.dlf.catalog.idThe name of the catalog in DLF.
<catalog_name>spark.sql.catalog.<catalogName>.dlf.catalog.endpointThe DLF endpoint. Select a DLF endpoint based on your region.
dlf-vpc.cn-hangzhou.aliyuncs.comHive Metastore
The metadata is stored in a specified Hive Metastore.
spark.sql.catalog.<catalogName> org.apache.paimon.spark.SparkCatalog spark.sql.catalog.<catalogName>.metastore hive spark.sql.catalog.<catalogName>.uri thrift://<yourHMSUri>:<port>Parameters:
Parameter
Description
Example value
spark.sql.catalog.<catalogName>The catalog implementation.
Fixed value:
org.apache.paimon.spark.SparkCatalogspark.sql.catalog.<catalogName>.metastoreThe metastore type. Set to
hiveto use a Hive Metastore.Fixed value:
hivespark.sql.catalog.<catalogName>.uriThe Hive Metastore URI. Format:
thrift://<IP address of Hive metastore>:9083.<IP address of Hive metastore>is the internal IP address of the Hive Metastore service. To use an external metastore, see Connect to an External Hive Metastore Service.thrift://192.168.**.**:9083File system
The metadata is stored in a file system.
spark.sql.catalog.<catalogName> org.apache.paimon.spark.SparkCatalog spark.sql.catalog.<catalogName>.metastore filesystem spark.sql.catalog.<catalogName>.warehouse oss://<yourBucketName>/warehouseParameters:
Parameter
Description
Example value
spark.sql.catalog.<catalogName>The catalog implementation.
Fixed value:
org.apache.paimon.spark.SparkCatalogspark.sql.catalog.<catalogName>.metastoreThe metastore type. Set to
filesystemto use a file system as the metastore.Fixed value:
filesystemspark.sql.catalog.<catalogName>.warehouseThe warehouse path. In this example,
<yourBucketName>is the name of an OSS bucket.oss://my-bucket/warehouseYou can configure multiple catalogs simultaneously, such as DLF, DLF 1.0, and Hive. Example:
# Configure a DLF catalog spark.sql.catalog.<catalogName> org.apache.paimon.spark.SparkCatalog spark.sql.catalog.<catalogName>.metastore rest spark.sql.catalog.<catalogName>.uri http://cn-hangzhou-vpc.dlf.aliyuncs.com spark.sql.catalog.<catalogName>.warehouse <catalog_name> spark.sql.catalog.<catalogName>.token.provider dlf spark.sql.catalog.<catalogName>.dlf.access-key-id <access_key_id> spark.sql.catalog.<catalogName>.dlf.access-key-secret <access_key_secret> # Configure a DLF 1.0 catalog spark.sql.catalog.<catalogName> org.apache.paimon.spark.SparkCatalog spark.sql.catalog.<catalogName>.metastore dlf spark.sql.catalog.<catalogName>.dlf.catalog.id <catalog_name> spark.sql.catalog.<catalogName>.dlf.catalog.endpoint dlf-vpc.cn-hangzhou.aliyuncs.com # Configure a hive1 catalog spark.sql.catalog.<catalogName> org.apache.paimon.spark.SparkCatalog spark.sql.catalog.<catalogName>.metastore hive spark.sql.catalog.<catalogName>.uri thrift://<yourHMSUri-1>:<port> # Configure a hive2 catalog spark.sql.catalog.<catalogName> org.apache.paimon.spark.SparkCatalog spark.sql.catalog.<catalogName>.metastore hive spark.sql.catalog.<catalogName>.uri thrift://<yourHMSUri-2>:<port>
Step 2: Read and write Paimon tables
-
Go to the SQL development page.
On the EMR Serverless Spark page, click Data Development in the left-side navigation pane.
-
On the Development tab, click the
icon. -
In the Create dialog box, enter a name such as
users_task, keep the default type as SparkSQL, and then click OK. -
Copy the following code to the new Spark SQL tab (users_task).
Paimon catalog
-- Create a database. CREATE DATABASE IF NOT EXISTS paimon.ss_paimon_db; -- Create a Paimon table. CREATE TABLE paimon.ss_paimon_db.paimon_tbl (id INT, name STRING) USING paimon; -- Write data to the Paimon table. INSERT INTO paimon.ss_paimon_db.paimon_tbl VALUES (1, "a"), (2, "b"), (3, "c"); -- Query the write results from the Paimon table. SELECT * FROM paimon.ss_paimon_db.paimon_tbl ORDER BY id; -- Delete the database. DROP DATABASE paimon.ss_paimon_db CASCADE; -
Select a database from the database drop-down list and the SQL session you created from the session drop-down list.
-
Click Run to execute the job. The job returns the following output.

FAQ
Related documentation
-
For a complete example of the SQL task development and orchestration process, see Quick Start for SparkSQL development.
-
For Paimon usage and configuration details, see the official Paimon documentation.
-
To use an external metastore service, see Connect to an External Hive Metastore Service.