MaxCompute allows you to create a Paimon external table to map to a Paimon table directory stored in Object Storage Service (OSS) and access the data within. This topic describes how to create a Paimon external table and access it with MaxCompute.
Overview
Apache Paimon is a lakehouse storage format for both streaming and batch processing that provides high-throughput writes and low-latency queries. It is fully integrated with common computing engines such as Spark, Hive, and Trino, as well as with Realtime Compute for Apache Flink and E-MapReduce. You can use Apache Paimon to quickly build a data lake on OSS and connect it to MaxCompute for data lake analytics. The metadata filtering feature further improves query performance by skipping unnecessary OSS directory files in read jobs.
Limitations
-
Schema limitations
Paimon external tables do not automatically update their schemas to reflect schema changes in the underlying Paimon files.
-
Table property limitations
-
You cannot set cluster properties on a Paimon external table.
-
You cannot set a primary key.
-
Paimon external tables do not support the pass-through of Paimon table properties.
-
-
Data write, update, and query operations
-
You can use
INSERT INTOorINSERT OVERWRITEstatements to write data to a Paimon external table. -
Writing data to dynamic bucket tables and cross-partition tables is not supported.
-
UPDATEandDELETEoperations are not supported on Paimon external tables. -
Time-travel queries that access historical data versions are not supported for Paimon external tables.
-
Do not write data directly to Paimon external tables. Instead, use methods such as UNLOAD to export data to OSS.
-
-
MaxCompute and OSS must be in the same region.
-
For more information, see Supported data types.
Create a Paimon external table
Syntax
For details about the syntax for creating external tables in different formats, see OSS external tables.
CREATE EXTERNAL TABLE [if NOT EXISTS] <mc_oss_extable_name>
(
<col_name> <data_type>,
...
)
[COMMENT <table_comment>]
[PARTITIONED BY (<col_name> <data_type>, ...)]
STORED BY 'org.apache.paimon.hive.PaimonStorageHandler'
WITH serdeproperties (
'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
)
LOCATION '<oss_location>';
Common parameters
For more information about common parameters, see Basic syntax parameters.
Write data
For details about the write syntax in MaxCompute, see Write syntax.
Query and analyze data
-
The data sharding (split) logic for Paimon tables is different from that for native MaxCompute tables. The Paimon format has its own internal mechanisms for file organization and sharding, which do not fully align with MaxCompute parameters.
-
For the SELECT syntax, see Query syntax.
-
To optimize query plans, see Query optimization.
-
For more information about bad row skipping, see BadRowSkipping.
Example
Step 1: Prerequisites
-
You have created a MaxCompute project.
-
You have prepared an OSS bucket and directory. For more information, see Create a bucket and Manage directories.
Ensure your bucket is in the same region as your MaxCompute project.
-
Grant permissions.
-
You have permission to access OSS. You can access an OSS external table by using an Alibaba Cloud account, a RAM user, or a RAM role. For more information about how to grant permissions, see STS-mode authorization for OSS.
-
You have the CreateTable permission in the MaxCompute project. For more information about table-related permissions, see MaxCompute permissions.
-
Step 2: Prepare data in Flink
Create a Paimon catalog and a Paimon table, and then insert data into the table.
If you already have Paimon table data in OSS, you can skip this step.
-
Create a Paimon filesystem catalog
-
Log on to the Flink console, and select a region in the upper-left corner.
-
Click the name of the target workspace. In the navigation pane on the left, select Catalogs .
-
On the Catalog List page, click Create Catalog on the right. In the Create Catalog dialog box, select Apache Paimon, click Next , and configure the following parameters:
Parameter
Required
Description
metastore
Yes
The metastore type. In this example, select
filesystem.catalog name
Yes
A custom catalog name, such as
paimon-catalog.warehouse
Yes
The warehouse directory in OSS. In this example, the directory is
oss://paimon-fs/paimon-test/.fs.oss.endpoint
Yes
The endpoint of the OSS service. For example, the endpoint for the China (Hangzhou) region is
oss-cn-hangzhou-internal.aliyuncs.com.fs.oss.accessKeyId
Yes
The AccessKey ID used to access OSS.
fs.oss.accessKeySecret
Yes
The AccessKey secret used to access OSS.
-
-
Create a Paimon table
-
Log on to the Flink console, and select a region in the upper-left corner.
-
Click the target workspace name, and then in the navigation pane on the left, select .
-
On the New Script tab, you can click
to create a new query script.Enter and run the following commands:
CREATE TABLE `paimon_catalog`.`default`.test_tbl ( id BIGINT, data STRING, dt STRING, PRIMARY KEY (dt, id) NOT ENFORCED ) PARTITIONED BY (dt); INSERT INTO `paimon-catalog`.`default`.test_tbl VALUES (1,'CCC','2024-07-18'), (2,'DDD','2024-07-18');
-
-
For SQL jobs that finish automatically, such as those that run an
INSERT INTO ... VALUES ...statement, perform the following operations:-
Click the target workspace name. In the navigation pane on the left, select .
-
On the Deployments page, click the name of the target job to open its Configuration page.
-
In the Parameters section, click Edit, and in Other Configuration set the
execution.checkpointing.checkpoints-after-tasks-finish.enabled: truecode and save.For more information about how to configure runtime parameters for a job, see Configure job deployment information.
-
Step 3: Create a Paimon external table
Run the following SQL statement in MaxCompute to create a Paimon external table:
CREATE EXTERNAL TABLE oss_extable_paimon_pt
(
id BIGINT,
data STRING
)
PARTITIONED BY (dt STRING )
STORED BY 'org.apache.paimon.hive.PaimonStorageHandler'
WITH serdeproperties (
'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
)
LOCATION 'oss://oss-cn-<your region>-internal.aliyuncs.com/<table_path>'
;
In the preceding statement, table_path is the path to the Paimon table that you created in Flink, such as paimon-fs/paimon-test/default.db/test_tbl. To find this path, perform the following steps:
-
Log on to the Flink console, and select a region in the upper-left corner.
-
Click the name of the target workspace. In the navigation pane on the left, select Catalogs .
-
On the Catalogs page, click default under the target Catalog, and on the default page, click View in the Actions column of the target table.
-
On the Table Schema tab, find the value of the parameter in the PropertiesPath section. For the table_path, use only the portion of the path that follows
oss://.
Step 4: Load partition data
If the OSS external table that you created is a partitioned table, you must load its partitions. For more information, see OSS external tables.
MSCK REPAIR TABLE oss_extable_paimon_pt ADD PARTITIONS;
Step 5: Query the Paimon external table
Run the following commands in MaxCompute to query the oss_extable_paimon_pt Paimon external table.
SET odps.sql.common.table.planner.ext.hive.bridge = true;
SET odps.sql.hive.compatible = true;
SELECT * FROM oss_extable_paimon_pt WHERE dt='2024-07-18';
The following result is returned:
+------------+------------+------------+
| id | data | dt |
+------------+------------+------------+
| 1 | CCC | 2024-07-18 |
| 2 | DDD | 2024-07-18 |
+------------+------------+------------+
If the schema in the Paimon files differs from the external table schema:
-
Column count mismatch: If the Paimon files contain fewer columns than the external table DDL, MaxCompute reads the missing columns as NULL. If the files contain more columns, MaxCompute ignores them.
-
Column type mismatch: You cannot read data from a Paimon STRING column into a MaxCompute INT column. Reading data from an INT column into a STRING column is supported but not recommended.
Supported data types
For more information about MaxCompute data types, see Data type editions 1.0 and 2.0.
|
Paimon data type |
MaxCompute 2.0 data type |
Read/write support |
Description |
|
TINYINT |
TINYINT |
|
8-bit signed integer. |
|
SMALLINT |
SMALLINT |
|
16-bit signed integer. |
|
INT |
INT |
|
32-bit signed integer. |
|
BIGINT |
BIGINT |
|
64-bit signed integer. |
|
BINARY(MAX_LENGTH) |
BINARY |
|
Binary data type. The current maximum length is 8 MB. |
|
FLOAT |
FLOAT |
|
32-bit binary floating-point number. |
|
DOUBLE |
DOUBLE |
|
64-bit binary floating-point number. |
|
DECIMAL(precision,scale) |
DECIMAL(precision,scale) |
|
Exact decimal numeric type. The default is
|
|
VARCHAR(n) |
VARCHAR(n) |
|
Variable-length character type. n specifies the length and ranges from 1 to 65,535. |
|
CHAR(n) |
CHAR(n) |
|
Fixed-length character type. n specifies the length and ranges from 1 to 255. |
|
VARCHAR(MAX_LENGTH) |
STRING |
|
String type. The current maximum length is 8 MB. |
|
DATE |
DATE |
|
Date type. The format is |
|
TIME, TIME(p) |
Not supported |
|
The Paimon TIME data type represents a time without a time zone, consisting of hours, minutes, and seconds, with nanosecond precision. TIME(p) specifies the fractional-second precision from 0 to 9. The default value is 0. No corresponding type exists in MaxCompute. |
|
TIMESTAMP, TIMESTAMP(p) |
TIMESTAMP_NTZ |
|
A timestamp type without a time zone that is accurate to the nanosecond. To read this data type, you must disable the native JNI bridge by running the following command: |
|
TIMESTAMP WITH LOCAL TIME_ZONE(9) |
TIMESTAMP |
|
|
|
TIMESTAMP WITH LOCAL TIME_ZONE(9) |
DATETIME |
|
A timestamp type that is accurate to the nanosecond. The format is |
|
BOOLEAN |
BOOLEAN |
|
A BOOLEAN type. |
|
ARRAY |
ARRAY |
|
A complex type. |
|
MAP |
MAP |
|
A complex type. |
|
ROW |
STRUCT |
|
A complex type. |
|
MULTISET<t> |
Not supported |
|
No corresponding type exists in MaxCompute. |
|
VARBINARY, VARBINARY(n), BYTES |
BINARY |
|
A data type of variable-length binary strings. |
Troubleshooting
kSIGABRT error when reading a Paimon external table
-
Error message:
ODPS-0123144: Fuxi job failed - kSIGABRT(errCode:6) at Odps/*****_SQL_0_1_0_job_0/M1@f01b17437.cloud.eo166#3. Detail error msg: CRASH_CORE, maybe caused by jvm crash, please check your java udf/udaf/udtf. | fatalInstance: Odps/*****_SQL_0_1_0_job_0/M1#0_0 -
Cause:
This error occurs when you read a TIMESTAMP_NTZ column in JNI mode.
-
Solution:
Disable the JNI bridge by running the following command before your query:
SET odps.sql.common.table.jni.disable.native=true;
Related articles
You can also use a custom Flink catalog to manage MaxCompute Paimon external tables. This allows you to write data by using Flink and query it in MaxCompute. For more information, see Create a MaxCompute Paimon external table by using Flink.