diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTable.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTable.java index d4c8d1e3321..072949754d3 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTable.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTable.java @@ -20,6 +20,8 @@ import org.apache.seatunnel.api.table.type.SeaTunnelRowType; import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -80,8 +82,9 @@ private CatalogTable( String catalogName) { this.tableId = tableId; this.tableSchema = tableSchema; - this.options = options; - this.partitionKeys = partitionKeys; + // Make sure the options and partitionKeys are mutable + this.options = new HashMap<>(options); + this.partitionKeys = new ArrayList<>(partitionKeys); this.comment = comment; this.catalogName = catalogName; } diff --git a/seatunnel-api/src/test/java/org/apache/seatunnel/api/table/catalog/CatalogTableTest.java b/seatunnel-api/src/test/java/org/apache/seatunnel/api/table/catalog/CatalogTableTest.java new file mode 100644 index 00000000000..6bb0890f212 --- /dev/null +++ b/seatunnel-api/src/test/java/org/apache/seatunnel/api/table/catalog/CatalogTableTest.java @@ -0,0 +1,38 @@ +/* + * 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.seatunnel.api.table.catalog; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +public class CatalogTableTest { + + @Test + public void testCatalogTableModifyOptionsOrPartitionKeys() { + CatalogTable catalogTable = + CatalogTable.of( + TableIdentifier.of("catalog", "database", "table"), + TableSchema.builder().build(), + Collections.emptyMap(), + Collections.emptyList(), + "comment"); + catalogTable.getOptions().put("test", "value"); + catalogTable.getPartitionKeys().add("test"); + } +}