Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#8241] improvement(trino-connector): Support SQL UPDATE/DELETE/MERGE with Hive/Iceberg (#8258)

qbhan718ba4b2a2e3
diff --git a/docs/trino-connector/catalog-hive.md b/docs/trino-connector/catalog-hive.md
index 1a999accfe..d6d9313e0a 100644
--- a/docs/trino-connector/catalog-hive.md
+++ b/docs/trino-connector/catalog-hive.md
@@ -81,11 +81,18 @@ Currently, it doesn't support certain query optimizations, such as pushdown and
### Update
-Not support.
+`UPDATE` is only supported for transactional Hive tables with format ORC. `UPDATE` of partition or bucket columns is not supported.
### Delete
-Not support.
+`DELETE` applied to non-transactional tables is only supported if the table is partitioned and the `WHERE` clause matches entire partitions.
+Transactional Hive tables with ORC format support "row-by-row" deletion, in which the `WHERE` clause may match arbitrary sets of rows.
+
+### Merge
+
+`MERGE` is only supported for ACID tables.
+
+See also [more limitation](https://trino.io/docs/current/connector/hive.html#data-management).
## Schema and table properties
@@ -250,7 +257,7 @@ WITH (
Insert data into the table `table_01`:
```sql
-INSERT INTO hive_test.database_01.table_01 (name, salary) VALUES ('ice', 12, 22);
+INSERT INTO hive_test.database_01.table_01 (name, salary, month) VALUES ('ice', 12, 22);
```
Insert data into the table `table_01` from select:
@@ -259,6 +266,53 @@ Insert data into the table `table_01` from select:
INSERT INTO hive_test.database_01.table_01 (name, salary, month) SELECT * FROM hive_test.database_01.table_01;
```
+Delete data from the table `table_01` with an entire partition:
+
+```sql
+DELETE FROM hive_test.database_01.table_01 WHERE month=22;
+```
+
+If an ACID table is defined in the schema `hive_test.database_01` as follows:
+
+```sql
+CREATE TABLE database_01.test_acid
+(
+ id INT,
+ name STRING,
+ salary INT
+)
+CLUSTERED BY (id) INTO 4 BUCKETS
+STORED AS ORC
+TBLPROPERTIES ('transactional'='true');
+```
+
+Update data into table `test_acid`:
+
+```sql
+UPDATE hive_test.database_01.test_acid SET name='bob' WHERE id=1;
+```
+
+Delete data from table `test_acid`:
+
+```sql
+DELETE FROM hive_test.database_01.test_acid WHERE id=1;
+```
+
+Merge data into table `test_acid`:
+
+```sql
+MERGE INTO hive_test.database_01.test_acid t USING hive_test.database_01.table_01 s
+ ON (t.name = s.name)
+ WHEN MATCHED AND s.name = 'bob'
+ THEN DELETE
+ WHEN MATCHED
+ THEN UPDATE
+ SET salary = s.salary + t.salary
+ WHEN NOT MATCHED
+ THEN INSERT (id, name, salary)
+ VALUES (3, s.name, s.salary);
+```
+
### Querying data
Query the `table_01` table:
diff --git a/docs/trino-connector/catalog-iceberg.md b/docs/trino-connector/catalog-iceberg.md
index 13b5c9c8d3..8fa63bfb6f 100644
--- a/docs/trino-connector/catalog-iceberg.md
+++ b/docs/trino-connector/catalog-iceberg.md
@@ -62,11 +62,16 @@ Currently, it doesn't support certain query optimizations, such as pushdown and
### Update
-Not support.
+`UPDATE` is only supported for table using v2 or higher of the Iceberg specification.
### Delete
-Not support.
+Support the deletion of entire partitions and deletion of individual rows for table using v2 or higher of the Iceberg specification.
+See also [Delete limitation](https://trino.io/docs/current/connector/iceberg.html#data-management).
+
+### Merge
+
+`MERGE` is only supported for table using v2 or higher of the Iceberg specification.
## Table and Schema properties
@@ -192,6 +197,33 @@ Insert data into the table `table_01` from select:
INSERT INTO iceberg_test.database_01.table_01 (name, salary) SELECT * FROM iceberg_test.database_01.table_01;
```
+Update data into the table `table_01`:
+
+```sql
+UPDATE iceberg_test.database_01.table_01 SET name='ice_update' WHERE salary=12;
+```
+
+Delete data into the table `table_01`:
+
+```sql
+DELETE FROM iceberg_test.database_01.table_01 WHERE name='ice';
+```
+
+Merge data into the table `table_01`:
+
+```sql
+MERGE INTO iceberg_test.database_01.table_01 t USING iceberg_test.database_01.table_02 s
+ ON (t.name = s.name)
+ WHEN MATCHED AND s.name = 'bob'
+ THEN DELETE
+ WHEN MATCHED
+ THEN UPDATE
+ SET salary = s.salary + t.salary
+ WHEN NOT MATCHED
+ THEN INSERT (name, salary)
+ VALUES (s.name, s.salary);
+```
+
### Querying data
Query the `table_01` table:
diff --git a/docs/trino-connector/catalog-mysql.md b/docs/trino-connector/catalog-mysql.md
index 5a7a15528f..5aa24a1413 100644
--- a/docs/trino-connector/catalog-mysql.md
+++ b/docs/trino-connector/catalog-mysql.md
@@ -42,6 +42,10 @@ Only `UPDATE` statements with constant assignments and predicates are supported.
If the `WHERE` clause is specified, only the matching rows are deleted. Otherwise, all rows from the table are deleted. See also [DELETE limitation](https://trino.io/docs/current/connector/mysql.html#delete-limitation).
+## Merge
+
+Not support.
+
## Table and Schema properties
MySQL's schemas cannot support properties.
@@ -218,13 +222,13 @@ Insert data into the table `table_01` from select:
INSERT INTO mysql_test.database_01.table_01 (name, salary) SELECT * FROM "test.mysql_test".database_01.table_01;
```
-Update the table `table_01`:
+Update data into the table `table_01`:
```sql
UPDATE mysql_test.database_01.table_01 SET name = 'ice_update' WHERE salary = 12;
```
-Delete the table `table_01`:
+Delete data from the table `table_01`:
```sql
DELETE FROM mysql_test.database_01.table_01 WHERE salary = 12;
diff --git a/docs/trino-connector/catalog-postgresql.md b/docs/trino-connector/catalog-postgresql.md
index 32320188b3..15b95bcc42 100644
--- a/docs/trino-connector/catalog-postgresql.md
+++ b/docs/trino-connector/catalog-postgresql.md
@@ -53,6 +53,10 @@ Only `UPDATE` statements with constant assignments and predicates are supported.
If the `WHERE` clause is specified, only the matching rows are deleted. Otherwise, all rows from the table are deleted. See also [DELETE limitation](https://trino.io/docs/current/connector/postgresql.html#delete-limitation).
+## Merge
+
+Not support.
+
## Table and Schema properties
PostgreSQL's tables and schemas cannot support properties.
@@ -148,13 +152,13 @@ Insert data into the table `table_01` from select:
INSERT INTO postgresql_test.database_01.table_01 (name, salary) SELECT * FROM postgresql_test.database_01.table_01;
```
-Update the table `table_01`:
+Update data into the table `table_01`:
```sql
UPDATE postgresql_test.database_01.table_01 SET name = 'ice_update' WHERE salary = 12;
```
-Delete the table `table_01`:
+Delete data from the table `table_01`:
```sql
DELETE FROM postgresql_test.database_01.table_01 WHERE salary = 12;
diff --git a/docs/trino-connector/sql-support.md b/docs/trino-connector/sql-support.md
index d569d7eace..6e97b1de04 100644
--- a/docs/trino-connector/sql-support.md
+++ b/docs/trino-connector/sql-support.md
@@ -31,6 +31,7 @@ The connector provides read access and write access to data and metadata stored
- [INSERT INTO SELECT](https://trino.io/docs/current/sql/insert.html)
- [UPDATE](https://trino.io/docs/current/sql/update.html)
- [DELETE](https://trino.io/docs/current/sql/delete.html)
+- [MERGE](https://trino.io/docs/current/sql/merge.html)
### Schema and table management
diff --git a/integration-test-common/docker-script/docker-compose.yaml b/integration-test-common/docker-script/docker-compose.yaml
index 875e67e320..1620b53a7e 100644
--- a/integration-test-common/docker-script/docker-compose.yaml
+++ b/integration-test-common/docker-script/docker-compose.yaml
@@ -25,6 +25,8 @@ services:
container_name: trino-ci-hive
environment:
- HADOOP_USER_NAME=anonymous
+ - HIVE_RUNTIME_VERSION=${HIVE_RUNTIME_VERSION:-hive2}
+ - TRINO_CONNECTOR_TEST=${TRINO_CONNECTOR_TEST:-false}
entrypoint: /bin/bash /tmp/hive/init.sh
volumes:
- ./init/hive:/tmp/hive
diff --git a/integration-test-common/docker-script/init/hive/init.sh b/integration-test-common/docker-script/init/hive/init.sh
index 35d9a8ccfc..a348fe332a 100755
--- a/integration-test-common/docker-script/init/hive/init.sh
+++ b/integration-test-common/docker-script/init/hive/init.sh
@@ -19,4 +19,20 @@
IP=$(hostname -I | awk '{print $1}')
sed -i "s|<value>hdfs://__REPLACE__HOST_NAME:9000|<value>hdfs://${IP}:9000|g" ${HIVE_TMP_CONF_DIR}/hive-site.xml
-/bin/bash /usr/local/sbin/start.sh
+if [[ "$TRINO_CONNECTOR_TEST" == "true" ]]
+then
+ echo "Trino connector test will create Hive ACID table."
+ /bin/bash /usr/local/sbin/start.sh &
+ # wait Hive metastore server start
+ until (ps -ef | grep -q "HiveMetaStore") && \
+ (ss -tuln | grep -q ':9083'); do
+ sleep 3
+ done
+ # create Hive ACID table
+ hive -f /tmp/hive/init.sql
+ # persist the container
+ tail -f /dev/null
+else
+ /bin/bash /usr/local/sbin/start.sh
+fi
+
diff --git a/integration-test-common/docker-script/init/hive/init.sql b/integration-test-common/docker-script/init/hive/init.sql
new file mode 100644
index 0000000000..f602234fc2
--- /dev/null
+++ b/integration-test-common/docker-script/init/hive/init.sql
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+CREATE DATABASE gt_hive_test_acid;
+SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+SET hive.support.concurrency=true;
+CREATE TABLE gt_hive_test_acid.test_update
+(
+ id INT,
+ name STRING,
+ salary INT
+)
+CLUSTERED BY (id) INTO 4 BUCKETS
+STORED AS ORC
+TBLPROPERTIES ('transactional'='true');
+CREATE TABLE gt_hive_test_acid.test_delete
+(
+ id INT,
+ name STRING,
+ salary INT
+)
+CLUSTERED BY (id) INTO 4 BUCKETS
+STORED AS ORC
+TBLPROPERTIES ('transactional'='true');
+CREATE TABLE gt_hive_test_acid.test_merge
+(
+ id INT,
+ name STRING,
+ salary INT
+)
+CLUSTERED BY (id) INTO 4 BUCKETS
+STORED AS ORC
+TBLPROPERTIES ('transactional'='true');
diff --git a/integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/TrinoITContainers.java b/integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/TrinoITContainers.java
index 531d4308ad..13e08b4369 100644
--- a/integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/TrinoITContainers.java
+++ b/integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/TrinoITContainers.java
@@ -49,15 +49,22 @@ public class TrinoITContainers implements AutoCloseable {
}
public void launch(int gravitinoServerPort) throws Exception {
- launch(gravitinoServerPort, 0);
+ launch(gravitinoServerPort, "hive2", false, 0);
}
- public void launch(int gravitinoServerPort, int trinoWokerNum) throws Exception {
+ public void launch(
+ int gravitinoServerPort,
+ String hiveRuntimeVersion,
+ boolean isTrinoConnectorTest,
+ int trinoWorkerNum)
+ throws Exception {
shutdown();
Map<String, String> env = new HashMap<>();
- env.put("TRINO_WORKER_NUM", String.valueOf(trinoWokerNum));
+ env.put("TRINO_WORKER_NUM", String.valueOf(trinoWorkerNum));
env.put("GRAVITINO_SERVER_PORT", String.valueOf(gravitinoServerPort));
+ env.put("HIVE_RUNTIME_VERSION", hiveRuntimeVersion);
+ env.put("TRINO_CONNECTOR_TEST", String.valueOf(isTrinoConnectorTest));
if (System.getProperty("gravitino.log.path") != null) {
env.put("GRAVITINO_LOG_PATH", System.getProperty("gravitino.log.path"));
}
diff --git a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryITBase.java b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryITBase.java
index 6dfad3aad1..2a54df2980 100644
--- a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryITBase.java
+++ b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryITBase.java
@@ -86,7 +86,25 @@ public class TrinoQueryITBase {
gravitinoUri = String.format("http://127.0.0.1:%d", baseIT.getGravitinoServerPort());
trinoITContainers = ContainerSuite.getTrinoITContainers();
- trinoITContainers.launch(baseIT.getGravitinoServerPort(), trinoWorkerNum);
+
+ /**
+ * When connecting to a Hive metastore version 3.x, the Hive connector supports reading from
+ * and writing to insert-only and ACID tables, with full support for partitioning and
+ * bucketing
+ */
+ String hiveRuntimeVersion = "hive3";
+
+ /**
+ * Only Trino connector test will create Hive ACID table when deploy Hive with
+ * `/integration-test-common/docker-script/init/hive/init.sh`
+ */
+ Boolean isTrinoConnectorTest = true;
+
+ trinoITContainers.launch(
+ baseIT.getGravitinoServerPort(),
+ hiveRuntimeVersion,
+ isTrinoConnectorTest,
+ trinoWorkerNum);
trinoUri = trinoITContainers.getTrinoUri();
hiveMetastoreUri = trinoITContainers.getHiveMetastoreUri();
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00015_update_table.sql b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00015_update_table.sql
new file mode 100644
index 0000000000..31f9a83892
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00015_update_table.sql
@@ -0,0 +1,8 @@
+-- Table create by integration-test-common/docker-script/init/hive/init.sql
+INSERT INTO gt_hive.gt_hive_test_acid.test_update VALUES (1, 'bob', 12), (2, 'tom', 13);
+
+SELECT * FROM gt_hive.gt_hive_test_acid.test_update ORDER BY id;
+
+UPDATE gt_hive.gt_hive_test_acid.test_update SET name='bob_update' WHERE id=1;
+
+SELECT * FROM gt_hive.gt_hive_test_acid.test_update ORDER BY id;
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00015_update_table.txt b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00015_update_table.txt
new file mode 100644
index 0000000000..e746c34aec
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00015_update_table.txt
@@ -0,0 +1,9 @@
+INSERT: 2 rows
+
+"1","bob","12"
+"2","tom","13"
+
+UPDATE: 1 row
+
+"1","bob_update","12"
+"2","tom","13"
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00016_delete_table.sql b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00016_delete_table.sql
new file mode 100644
index 0000000000..1854a93e7c
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00016_delete_table.sql
@@ -0,0 +1,38 @@
+-- Test delete with ACID table
+-- Table create by integration-test-common/docker-script/init/hive/init.sql
+INSERT INTO gt_hive.gt_hive_test_acid.test_delete VALUES (1, 'bob', 12), (2, 'tom', 13);
+
+SELECT * FROM gt_hive.gt_hive_test_acid.test_delete ORDER BY id;
+
+DELETE FROM gt_hive.gt_hive_test_acid.test_delete WHERE id=1;
+
+SELECT * FROM gt_hive.gt_hive_test_acid.test_delete ORDER BY id;
+
+DELETE FROM gt_hive.gt_hive_test_acid.test_delete;
+
+SELECT COUNT(*) FROM gt_hive.gt_hive_test_acid.test_delete;
+
+-- Test delete with partition table
+CREATE SCHEMA gt_hive.gt_hive_test_delete;
+
+CREATE TABLE gt_hive.gt_hive_test_delete.tb01 (
+ id int,
+ name varchar,
+ dt varchar
+) WITH (partitioned_by = ARRAY['dt']);
+
+INSERT INTO gt_hive.gt_hive_test_delete.tb01 values (1, 'bob', '2025-08-27'), (2, 'tom', '2025-08-27'), (3, 'nancy', '2025-08-28');
+
+SELECT * FROM gt_hive.gt_hive_test_delete.tb01 ORDER BY id;
+
+DELETE FROM gt_hive.gt_hive_test_delete.tb01 where dt='2025-08-27';
+
+SELECT * FROM gt_hive.gt_hive_test_delete.tb01 ORDER BY id;
+
+DELETE FROM gt_hive.gt_hive_test_delete.tb01;
+
+SELECT COUNT(*) FROM gt_hive.gt_hive_test_delete.tb01;
+
+DROP TABLE gt_hive.gt_hive_test_delete.tb01;
+
+DROP SCHEMA gt_hive.gt_hive_test_delete;
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00016_delete_table.txt b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00016_delete_table.txt
new file mode 100644
index 0000000000..c39b66307d
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00016_delete_table.txt
@@ -0,0 +1,36 @@
+INSERT: 2 rows
+
+"1","bob","12"
+"2","tom","13"
+
+DELETE: 1 row
+
+"2","tom","13"
+
+DELETE: 1 row
+
+"0"
+
+CREATE SCHEMA
+
+CREATE TABLE
+
+INSERT: 3 rows
+
+"1","bob","2025-08-27"
+"2","tom","2025-08-27"
+"3","nancy","2025-08-28"
+
+DELETE
+""
+
+"3","nancy","2025-08-28"
+
+DELETE
+""
+
+"0"
+
+DROP TABLE
+
+DROP SCHEMA
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00017_merge_table.sql b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00017_merge_table.sql
new file mode 100644
index 0000000000..578ef7ebea
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00017_merge_table.sql
@@ -0,0 +1,32 @@
+-- Table create by integration-test-common/docker-script/init/hive/init.sql
+INSERT INTO gt_hive.gt_hive_test_acid.test_merge VALUES (1, 'bob', 12), (2, 'tom', 13);
+
+SELECT * FROM gt_hive.gt_hive_test_acid.test_merge ORDER BY id;
+
+CREATE SCHEMA gt_hive.gt_hive_test_merge;
+
+CREATE TABLE gt_hive.gt_hive_test_merge.tb01 (
+ name varchar,
+ salary int
+);
+
+INSERT INTO gt_hive.gt_hive_test_merge.tb01(name, salary) VALUES ('bob', 14), ('tom', 12), ('nancy', 17);
+
+SELECT * FROM gt_hive.gt_hive_test_merge.tb01 ORDER BY name;
+
+MERGE INTO gt_hive.gt_hive_test_acid.test_merge t USING gt_hive.gt_hive_test_merge.tb01 s
+ ON (t.name = s.name)
+ WHEN MATCHED AND s.name = 'bob'
+ THEN DELETE
+ WHEN MATCHED
+ THEN UPDATE
+ SET salary = s.salary + t.salary
+ WHEN NOT MATCHED
+ THEN INSERT (id, name, salary)
+ VALUES (3, s.name, s.salary);
+
+SELECT * FROM gt_hive.gt_hive_test_acid.test_merge ORDER BY name;
+
+DROP TABLE gt_hive.gt_hive_test_merge.tb01
+
+DROP SCHEMA gt_hive.gt_hive_test_merge
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00017_merge_table.txt b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00017_merge_table.txt
new file mode 100644
index 0000000000..ca4736f1c6
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/hive/00017_merge_table.txt
@@ -0,0 +1,23 @@
+INSERT: 2 rows
+
+"1","bob","12"
+"2","tom","13"
+
+CREATE SCHEMA
+
+CREATE TABLE
+
+INSERT: 3 rows
+
+"bob","14"
+"nancy","17"
+"tom","12"
+
+MERGE: 3 rows
+
+"3","nancy","17"
+"2","tom","25"
+
+DROP TABLE
+
+DROP SCHEMA
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00008_update_table.sql b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00008_update_table.sql
new file mode 100644
index 0000000000..b66404b70b
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00008_update_table.sql
@@ -0,0 +1,29 @@
+CREATE SCHEMA gt_iceberg_test_update;
+
+CREATE TABLE gt_iceberg_test_update.tb01 (
+ name varchar,
+ salary int
+);
+
+INSERT INTO gt_iceberg_test_update.tb01(name, salary) VALUES ('bob', 14), ('tom', 12);
+
+SELECT * FROM gt_iceberg_test_update.tb01 ORDER BY name;
+
+UPDATE gt_iceberg_test_update.tb01 SET name='bob_update' WHERE salary=14;
+
+SELECT * FROM gt_iceberg_test_update.tb01 ORDER BY name;
+
+CREATE TABLE gt_iceberg_test_update.tb02 (
+ name varchar,
+ salary int
+) WITH (format_version='1');
+
+INSERT INTO gt_iceberg_test_update.tb02(name, salary) VALUES ('bob', 14), ('tom', 12);
+
+UPDATE gt_iceberg_test_update.tb02 SET name='bob_update' WHERE salary=14;
+
+DROP TABLE gt_iceberg_test_update.tb01;
+
+DROP TABLE gt_iceberg_test_update.tb02;
+
+DROP SCHEMA gt_iceberg_test_update;
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00008_update_table.txt b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00008_update_table.txt
new file mode 100644
index 0000000000..450af471dc
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00008_update_table.txt
@@ -0,0 +1,25 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+INSERT: 2 rows
+
+"bob","14"
+"tom","12"
+
+UPDATE: 1 row
+
+"bob_update","14"
+"tom","12"
+
+CREATE TABLE
+
+INSERT: 2 rows
+
+<QUERY_FAILED> Iceberg table updates require at least format version 2
+
+DROP TABLE
+
+DROP TABLE
+
+DROP SCHEMA
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00009_delete_table.sql b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00009_delete_table.sql
new file mode 100644
index 0000000000..ed26cb51d1
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00009_delete_table.sql
@@ -0,0 +1,52 @@
+CREATE SCHEMA gt_iceberg_test_delete;
+
+-- Test row level deletion
+CREATE TABLE gt_iceberg_test_delete.tb01 (
+ name varchar,
+ salary int
+);
+
+INSERT INTO gt_iceberg_test_delete.tb01(name, salary) VALUES ('bob', 14), ('tom', 12);
+
+SELECT * FROM gt_iceberg_test_delete.tb01 ORDER BY name;
+
+DELETE FROM gt_iceberg_test_delete.tb01 WHERE salary=14;
+
+SELECT * FROM gt_iceberg_test_delete.tb01 ORDER BY name;
+
+DELETE FROM gt_iceberg_test_delete.tb01;
+
+SELECT count(*) FROM gt_iceberg_test_delete.tb01;
+
+-- Test deletion by partition
+CREATE TABLE gt_iceberg_test_delete.tb02 (
+ name varchar,
+ salary int
+) with (
+ partitioning = ARRAY['name']
+);
+
+INSERT INTO gt_iceberg_test_delete.tb02(name, salary) VALUES ('bob', 14), ('tom', 12), ('bob', 15);
+
+SELECT * FROM gt_iceberg_test_delete.tb02 ORDER BY salary;
+
+DELETE FROM gt_iceberg_test_delete.tb02 WHERE name='bob';
+
+SELECT * FROM gt_iceberg_test_delete.tb02 ORDER BY name;
+
+CREATE TABLE gt_iceberg_test_delete.tb03 (
+ name varchar,
+ salary int
+) WITH (format_version='1');
+
+INSERT INTO gt_iceberg_test_delete.tb03(name, salary) VALUES ('bob', 14), ('tom', 12);
+
+DELETE FROM gt_iceberg_test_delete.tb03 WHERE name='bob';
+
+DROP TABLE gt_iceberg_test_delete.tb01;
+
+DROP TABLE gt_iceberg_test_delete.tb02;
+
+DROP TABLE gt_iceberg_test_delete.tb03;
+
+DROP SCHEMA gt_iceberg_test_delete;
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00009_delete_table.txt b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00009_delete_table.txt
new file mode 100644
index 0000000000..f9baa1da34
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00009_delete_table.txt
@@ -0,0 +1,42 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+INSERT: 2 rows
+
+"bob","14"
+"tom","12"
+
+DELETE: 1 row
+
+"tom","12"
+
+DELETE: 1 row
+
+"0"
+
+CREATE TABLE
+
+INSERT: 3 rows
+
+"tom","12"
+"bob","14"
+"bob","15"
+
+DELETE: 2 rows
+
+"tom","12"
+
+CREATE TABLE
+
+INSERT: 2 rows
+
+<QUERY_FAILED> Iceberg table updates require at least format version 2
+
+DROP TABLE
+
+DROP TABLE
+
+DROP TABLE
+
+DROP SCHEMA
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00010_merge_table.sql b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00010_merge_table.sql
new file mode 100644
index 0000000000..2325c4828d
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00010_merge_table.sql
@@ -0,0 +1,58 @@
+CREATE SCHEMA gt_iceberg_test_merge;
+
+CREATE TABLE gt_iceberg_test_merge.tb01 (
+ name varchar,
+ salary int
+);
+
+INSERT INTO gt_iceberg_test_merge.tb01(name, salary) VALUES ('bob', 14), ('tom', 12);
+
+SELECT * FROM gt_iceberg_test_merge.tb01 ORDER BY name;
+
+CREATE TABLE gt_iceberg_test_merge.tb02 (
+ name varchar,
+ salary int
+);
+
+INSERT INTO gt_iceberg_test_merge.tb02(name, salary) VALUES ('bob', 15), ('tom', 16), ('nancy', 17);
+
+SELECT * FROM gt_iceberg_test_merge.tb02 ORDER BY name;
+
+MERGE INTO gt_iceberg_test_merge.tb01 t USING gt_iceberg_test_merge.tb02 s
+ ON (t.name = s.name)
+ WHEN MATCHED AND s.name = 'bob'
+ THEN DELETE
+ WHEN MATCHED
+ THEN UPDATE
+ SET salary = s.salary + t.salary
+ WHEN NOT MATCHED
+ THEN INSERT (name, salary)
+ VALUES (s.name, s.salary);
+
+SELECT * FROM gt_iceberg_test_merge.tb01 ORDER BY name;
+
+CREATE TABLE gt_iceberg_test_merge.tb03 (
+ name varchar,
+ salary int
+) WITH (format_version='1');
+
+INSERT INTO gt_iceberg_test_merge.tb03(name, salary) VALUES ('bob', 14), ('tom', 12);
+
+MERGE INTO gt_iceberg_test_merge.tb03 t USING gt_iceberg_test_merge.tb02 s
+ ON (t.name = s.name)
+ WHEN MATCHED AND s.name = 'bob'
+ THEN DELETE
+ WHEN MATCHED
+ THEN UPDATE
+ SET salary = s.salary + t.salary
+ WHEN NOT MATCHED
+ THEN INSERT (name, salary)
+ VALUES (s.name, s.salary);
+
+DROP TABLE gt_iceberg_test_merge.tb01;
+
+DROP TABLE gt_iceberg_test_merge.tb02;
+
+DROP TABLE gt_iceberg_test_merge.tb03;
+
+DROP SCHEMA gt_iceberg_test_merge;
diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00010_merge_table.txt b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00010_merge_table.txt
new file mode 100644
index 0000000000..9ff1537423
--- /dev/null
+++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00010_merge_table.txt
@@ -0,0 +1,35 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+INSERT: 2 rows
+
+"bob","14"
+"tom","12"
+
+CREATE TABLE
+
+INSERT: 3 rows
+
+"bob","15"
+"nancy","17"
+"tom","16"
+
+MERGE: 3 rows
+
+"nancy","17"
+"tom","28"
+
+CREATE TABLE
+
+INSERT: 2 rows
+
+<QUERY_FAILED> Iceberg table updates require at least format version 2
+
+DROP TABLE
+
+DROP TABLE
+
+DROP TABLE
+
+DROP SCHEMA
diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoConnector.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoConnector.java
index 2bd489ec6d..cfb17ab431 100644
--- a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoConnector.java
+++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoConnector.java
@@ -23,6 +23,7 @@ import io.trino.spi.connector.Connector;
import io.trino.spi.connector.ConnectorAccessControl;
import io.trino.spi.connector.ConnectorCapabilities;
import io.trino.spi.connector.ConnectorMetadata;
+import io.trino.spi.connector.ConnectorNodePartitioningProvider;
import io.trino.spi.connector.ConnectorPageSinkProvider;
import io.trino.spi.connector.ConnectorPageSourceProvider;
import io.trino.spi.connector.ConnectorRecordSetProvider;
@@ -162,4 +163,12 @@ public class GravitinoConnector implements Connector {
public Set<ConnectorCapabilities> getCapabilities() {
return catalogConnectorContext.getInternalConnector().getCapabilities();
}
+
+ @Override
+ public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
+ Connector internalConnector = catalogConnectorContext.getInternalConnector();
+ ConnectorNodePartitioningProvider nodePartitioningProvider =
+ internalConnector.getNodePartitioningProvider();
+ return new GravitinoNodePartitioningProvider(nodePartitioningProvider);
+ }
}
diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMergeTableHandle.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMergeTableHandle.java
new file mode 100644
index 0000000000..1b54028d92
--- /dev/null
+++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMergeTableHandle.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.trino.connector;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.trino.spi.connector.ConnectorMergeTableHandle;
+import io.trino.spi.connector.ConnectorTableHandle;
+
+/** The GravitinoMergeTableHandle is used for handling merge operations. */
+public class GravitinoMergeTableHandle
+ implements ConnectorMergeTableHandle, GravitinoHandle<ConnectorMergeTableHandle> {
+
+ private final String schemaName;
+ private final String tableName;
+
+ private HandleWrapper<ConnectorMergeTableHandle> handleWrapper =
+ new HandleWrapper<>(ConnectorMergeTableHandle.class);
+
+ /**
+ * Constructs a new ConnectorMergeTableHandle from a serialized schema name, table name, and
+ * handle string.
+ *
+ * @param schemaName the name of the schema
+ * @param tableName the name of the table
+ * @param handleString the serialized handle string
+ */
+ @JsonCreator
+ public GravitinoMergeTableHandle(
+ @JsonProperty("schemaName") String schemaName,
+ @JsonProperty("tableName") String tableName,
+ @JsonProperty(HANDLE_STRING) String handleString) {
+ this.schemaName = schemaName;
+ this.tableName = tableName;
+ this.handleWrapper = handleWrapper.fromJson(handleString);
+ }
+
+ /**
+ * Constructs a new GravitinoMergeTableHandle from a ConnectorMergeTableHandle.
+ *
+ * @param mergeTableHandle the internal connector merge table handle
+ */
+ public GravitinoMergeTableHandle(
+ String schemaName, String tableName, ConnectorMergeTableHandle mergeTableHandle) {
+ this.schemaName = schemaName;
+ this.tableName = tableName;
+ this.handleWrapper = new HandleWrapper<>(mergeTableHandle);
+ }
+
+ /**
+ * Gets the name of the schema.
+ *
+ * @return the schema name
+ */
+ @JsonProperty
+ public String getSchemaName() {
+ return schemaName;
+ }
+
+ /**
+ * Gets the name of the table.
+ *
+ * @return the table name
+ */
+ @JsonProperty
+ public String getTableName() {
+ return tableName;
+ }
+
+ @JsonProperty
+ @Override
+ public String getHandleString() {
+ return handleWrapper.toJson();
+ }
+
+ @Override
+ public ConnectorMergeTableHandle getInternalHandle() {
+ return handleWrapper.getHandle();
+ }
+
+ @Override
+ public ConnectorTableHandle getTableHandle() {
+ return new GravitinoTableHandle(
+ schemaName, tableName, handleWrapper.getHandle().getTableHandle());
+ }
+}
diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java
index 69a8319520..b1f42f5542 100644
--- a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java
+++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java
@@ -31,10 +31,13 @@ import io.trino.spi.connector.Assignment;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.connector.ColumnMetadata;
import io.trino.spi.connector.ConnectorInsertTableHandle;
+import io.trino.spi.connector.ConnectorMergeTableHandle;
import io.trino.spi.connector.ConnectorMetadata;
import io.trino.spi.connector.ConnectorOutputMetadata;
+import io.trino.spi.connector.ConnectorPartitioningHandle;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.ConnectorTableHandle;
+import io.trino.spi.connector.ConnectorTableLayout;
import io.trino.spi.connector.ConnectorTableMetadata;
import io.trino.spi.connector.ConnectorTableVersion;
import io.trino.spi.connector.Constraint;
@@ -585,6 +588,35 @@ public class GravitinoMetadata implements ConnectorMetadata {
return internalMetadata.getTableStatistics(session, GravitinoHandle.unWrap(tableHandle));
}
+ @Override
+ public Optional<ConnectorPartitioningHandle> getUpdateLayout(
+ ConnectorSession session, ConnectorTableHandle tableHandle) {
+ Optional<ConnectorPartitioningHandle> updateLayout =
+ internalMetadata.getUpdateLayout(session, GravitinoHandle.unWrap(tableHandle));
+ return updateLayout.map(GravitinoPartitioningHandle::new);
+ }
+
+ @Override
+ public ConnectorMergeTableHandle beginMerge(
+ ConnectorSession session, ConnectorTableHandle tableHandle, RetryMode retryMode) {
+ ConnectorMergeTableHandle connectorMergeTableHandle =
+ internalMetadata.beginMerge(session, GravitinoHandle.unWrap(tableHandle), retryMode);
+ SchemaTableName tableName = getTableName(tableHandle);
+
+ return new GravitinoMergeTableHandle(
+ tableName.getSchemaName(), tableName.getTableName(), connectorMergeTableHandle);
+ }
+
+ @Override
+ public void finishMerge(
+ ConnectorSession session,
+ ConnectorMergeTableHandle mergeTableHandle,
+ Collection<Slice> fragments,
+ Collection<ComputedStatistics> computedStatistics) {
+ internalMetadata.finishMerge(
+ session, GravitinoHandle.unWrap(mergeTableHandle), fragments, computedStatistics);
+ }
+
@Override
public Optional<ConnectorTableHandle> applyUpdate(
ConnectorSession session,
@@ -635,6 +667,21 @@ public class GravitinoMetadata implements ConnectorMetadata {
return internalMetadata.executeDelete(session, GravitinoHandle.unWrap(tableHandle));
}
+ @Override
+ public Optional<ConnectorTableLayout> getInsertLayout(
+ ConnectorSession session, ConnectorTableHandle tableHandle) {
+ return internalMetadata
+ .getInsertLayout(session, GravitinoHandle.unWrap(tableHandle))
+ .map(
+ result ->
+ result.getPartitioning().isPresent()
+ ? new ConnectorTableLayout(
+ new GravitinoPartitioningHandle(result.getPartitioning().get()),
+ result.getPartitionColumns(),
+ result.supportsMultipleWritersPerPartition())
+ : new ConnectorTableLayout(result.getPartitionColumns()));
+ }
+
private SchemaTableName getTableName(ConnectorTableHandle tableHandle) {
return ((GravitinoTableHandle) tableHandle).toSchemaTableName();
}
diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoNodePartitioningProvider.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoNodePartitioningProvider.java
new file mode 100644
index 0000000000..8226b70d14
--- /dev/null
+++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoNodePartitioningProvider.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.trino.connector;
+
+import io.trino.spi.connector.BucketFunction;
+import io.trino.spi.connector.ConnectorBucketNodeMap;
+import io.trino.spi.connector.ConnectorNodePartitioningProvider;
+import io.trino.spi.connector.ConnectorPartitioningHandle;
+import io.trino.spi.connector.ConnectorSession;
+import io.trino.spi.connector.ConnectorSplit;
+import io.trino.spi.connector.ConnectorTransactionHandle;
+import io.trino.spi.type.Type;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.ToIntFunction;
+
+/**
+ * This class provides a ConnectorNodePartitioningProvider for Trino to decide data partitioning
+ * strategy.
+ */
+public class GravitinoNodePartitioningProvider implements ConnectorNodePartitioningProvider {
+
+ ConnectorNodePartitioningProvider nodePartitioningProvider;
+
+ /**
+ * Constructs a new GravitinoNodePartitioningProvider with the specified node partition provider.
+ *
+ * @param nodePartitioningProvider the internal connector node partition provider
+ */
+ public GravitinoNodePartitioningProvider(
+ ConnectorNodePartitioningProvider nodePartitioningProvider) {
+ this.nodePartitioningProvider = nodePartitioningProvider;
+ }
+
+ @Override
+ public Optional<ConnectorBucketNodeMap> getBucketNodeMapping(
+ ConnectorTransactionHandle transactionHandle,
+ ConnectorSession session,
+ ConnectorPartitioningHandle partitioningHandle) {
+ return nodePartitioningProvider.getBucketNodeMapping(
+ GravitinoHandle.unWrap(transactionHandle),
+ session,
+ GravitinoHandle.unWrap(partitioningHandle));
+ }
+
+ @Override
+ public ToIntFunction<ConnectorSplit> getSplitBucketFunction(
+ ConnectorTransactionHandle transactionHandle,
+ ConnectorSession session,
+ ConnectorPartitioningHandle partitioningHandle) {
+ return nodePartitioningProvider.getSplitBucketFunction(
+ GravitinoHandle.unWrap(transactionHandle),
+ session,
+ GravitinoHandle.unWrap(partitioningHandle));
+ }
+
+ @Override
+ public BucketFunction getBucketFunction(
+ ConnectorTransactionHandle transactionHandle,
+ ConnectorSession session,
+ ConnectorPartitioningHandle partitioningHandle,
+ List<Type> partitionChannelTypes,
+ int bucketCount) {
+ return nodePartitioningProvider.getBucketFunction(
+ GravitinoHandle.unWrap(transactionHandle),
+ session,
+ GravitinoHandle.unWrap(partitioningHandle),
+ partitionChannelTypes,
+ bucketCount);
+ }
+}
diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoPageSinkProvider.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoPageSinkProvider.java
index 4bf759f530..7122a7f484 100644
--- a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoPageSinkProvider.java
+++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoPageSinkProvider.java
@@ -19,6 +19,8 @@
package org.apache.gravitino.trino.connector;
import io.trino.spi.connector.ConnectorInsertTableHandle;
+import io.trino.spi.connector.ConnectorMergeSink;
+import io.trino.spi.connector.ConnectorMergeTableHandle;
import io.trino.spi.connector.ConnectorOutputTableHandle;
import io.trino.spi.connector.ConnectorPageSink;
import io.trino.spi.connector.ConnectorPageSinkId;
@@ -62,4 +64,17 @@ public class GravitinoPageSinkProvider implements ConnectorPageSinkProvider {
GravitinoHandle.unWrap(insertTableHandle),
pageSinkId);
}
+
+ @Override
+ public ConnectorMergeSink createMergeSink(
+ ConnectorTransactionHandle transactionHandle,
+ ConnectorSession session,
+ ConnectorMergeTableHandle mergeHandle,
+ ConnectorPageSinkId pageSinkId) {
+ return pageSinkProvider.createMergeSink(
+ GravitinoHandle.unWrap(transactionHandle),
+ session,
+ GravitinoHandle.unWrap(mergeHandle),
+ pageSinkId);
+ }
}
diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoPartitioningHandle.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoPartitioningHandle.java
new file mode 100644
index 0000000000..ec7c2d4a7e
--- /dev/null
+++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoPartitioningHandle.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.trino.connector;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.trino.spi.connector.ConnectorPartitioningHandle;
+
+/** The GravitinoPartitioningHandle is used for handling data partitioning strategy. */
+public class GravitinoPartitioningHandle
+ implements ConnectorPartitioningHandle, GravitinoHandle<ConnectorPartitioningHandle> {
+
+ private HandleWrapper<ConnectorPartitioningHandle> handleWrapper =
+ new HandleWrapper<>(ConnectorPartitioningHandle.class);
+
+ /**
+ * Constructs a new ConnectorPartitioningHandle from a serialized handle string.
+ *
+ * @param handleString the serialized handle string
+ */
+ @JsonCreator
+ public GravitinoPartitioningHandle(@JsonProperty(HANDLE_STRING) String handleString) {
+ this.handleWrapper = handleWrapper.fromJson(handleString);
+ }
+
+ /**
+ * Constructs a new GravitinoPartitioningHandle from a ConnectorPartitioningHandle.
+ *
+ * @param partitioningHandle the internal connector partitioning handle
+ */
+ public GravitinoPartitioningHandle(ConnectorPartitioningHandle partitioningHandle) {
+ this.handleWrapper = new HandleWrapper<>(partitioningHandle);
+ }
+
+ @JsonProperty
+ @Override
+ public String getHandleString() {
+ return handleWrapper.toJson();
+ }
+
+ @Override
+ public ConnectorPartitioningHandle getInternalHandle() {
+ return handleWrapper.getHandle();
+ }
+}
diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/util/json/JsonCodec.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/util/json/JsonCodec.java
index 7a7c5559fd..20e6844242 100644
--- a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/util/json/JsonCodec.java
+++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/util/json/JsonCodec.java
@@ -36,6 +36,8 @@ import io.trino.spi.block.Block;
import io.trino.spi.block.BlockEncodingSerde;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.connector.ConnectorInsertTableHandle;
+import io.trino.spi.connector.ConnectorMergeTableHandle;
+import io.trino.spi.connector.ConnectorPartitioningHandle;
import io.trino.spi.connector.ConnectorSplit;
import io.trino.spi.connector.ConnectorTableHandle;
import io.trino.spi.connector.ConnectorTransactionHandle;
@@ -161,6 +163,14 @@ public class JsonCodec {
objectMapper.registerModule(
new AbstractTypedJacksonModule<>(
ConnectorInsertTableHandle.class, nameResolver, classResolver) {});
+
+ objectMapper.registerModule(
+ new AbstractTypedJacksonModule<>(
+ ConnectorMergeTableHandle.class, nameResolver, classResolver) {});
+
+ objectMapper.registerModule(
+ new AbstractTypedJacksonModule<>(
+ ConnectorPartitioningHandle.class, nameResolver, classResolver) {});
}
@SuppressWarnings("deprecation")