From c1f27b475fba92761a09e88b2c4dfde92f196bb3 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 14:58:52 +0800 Subject: [PATCH 01/12] [core] Support rename tag procedure --- .../privilege/PrivilegedFileStoreTable.java | 6 ++ .../paimon/table/AbstractFileStoreTable.java | 5 + .../paimon/table/DelegatedFileStoreTable.java | 5 + .../org/apache/paimon/table/FormatTable.java | 5 + .../apache/paimon/table/ReadonlyTable.java | 8 ++ .../java/org/apache/paimon/table/Table.java | 3 + .../org/apache/paimon/utils/TagManager.java | 16 ++++ .../sql/CreateAndDeleteTagProcedureTest.scala | 10 +- .../apache/paimon/spark/SparkProcedures.java | 2 + .../spark/procedure/RenameTagProcedure.java | 95 +++++++++++++++++++ 10 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RenameTagProcedure.java diff --git a/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedFileStoreTable.java index 6842f014245c..717e2e9d93c8 100644 --- a/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedFileStoreTable.java @@ -121,6 +121,12 @@ public void createTag(String tagName, Duration timeRetained) { wrapped.createTag(tagName, timeRetained); } + @Override + public void renameTag(String tagName, String newTagName) { + privilegeChecker.assertCanInsert(identifier); + wrapped.renameTag(tagName, newTagName); + } + @Override public void createTag(String tagName, long fromSnapshotId, Duration timeRetained) { privilegeChecker.assertCanInsert(identifier); diff --git a/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java index a98f368c5f33..da72212471af 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java @@ -571,6 +571,11 @@ private void createTag(String tagName, Snapshot fromSnapshot, @Nullable Duration tagManager().createTag(fromSnapshot, tagName, timeRetained, store().createTagCallbacks()); } + @Override + public void renameTag(String tagName, String newTagName) { + tagManager().renameTag(tagName, newTagName); + } + @Override public void deleteTag(String tagName) { tagManager() diff --git a/paimon-core/src/main/java/org/apache/paimon/table/DelegatedFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/table/DelegatedFileStoreTable.java index dc758a1af796..8c0fcd183661 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/DelegatedFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/DelegatedFileStoreTable.java @@ -182,6 +182,11 @@ public void createTag(String tagName, long fromSnapshotId, Duration timeRetained wrapped.createTag(tagName, fromSnapshotId, timeRetained); } + @Override + public void renameTag(String tagName, String newTagName) { + wrapped.renameTag(tagName, newTagName); + } + @Override public void deleteTag(String tagName) { wrapped.deleteTag(tagName); diff --git a/paimon-core/src/main/java/org/apache/paimon/table/FormatTable.java b/paimon-core/src/main/java/org/apache/paimon/table/FormatTable.java index efd4a00d0627..0bef58b509ec 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/FormatTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/FormatTable.java @@ -266,6 +266,11 @@ default void createTag(String tagName, Duration timeRetained) { throw new UnsupportedOperationException(); } + @Override + default void renameTag(String tagName, String newTagName) { + throw new UnsupportedOperationException(); + } + @Override default void deleteTag(String tagName) { throw new UnsupportedOperationException(); diff --git a/paimon-core/src/main/java/org/apache/paimon/table/ReadonlyTable.java b/paimon-core/src/main/java/org/apache/paimon/table/ReadonlyTable.java index 82edaa667c2a..989fd7592201 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/ReadonlyTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/ReadonlyTable.java @@ -189,6 +189,14 @@ default void createTag(String tagName, Duration timeRetained) { this.getClass().getSimpleName())); } + @Override + default void renameTag(String tagName, String newTagName) { + throw new UnsupportedOperationException( + String.format( + "Readonly Table %s does not support renameTag.", + this.getClass().getSimpleName())); + } + @Override default void deleteTag(String tagName) { throw new UnsupportedOperationException( diff --git a/paimon-core/src/main/java/org/apache/paimon/table/Table.java b/paimon-core/src/main/java/org/apache/paimon/table/Table.java index d542732e24c4..89bd197da0ce 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/Table.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/Table.java @@ -117,6 +117,9 @@ default String fullName() { @Experimental void createTag(String tagName, Duration timeRetained); + @Experimental + void renameTag(String tagName, String newTagName); + /** Delete a tag by name. */ @Experimental void deleteTag(String tagName); diff --git a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java index f6e69fb281a7..33e5323f0c53 100644 --- a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java +++ b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java @@ -144,6 +144,22 @@ public void createTag( } } + public void renameTag(String tagName, String newTagName) { + try { + if (!tagExists(tagName)) { + throw new RuntimeException(String.format("tag: %s is not exists", tagName)); + } + if (tagExists(newTagName)) { + throw new RuntimeException( + String.format( + "tag: %s existed, please set a non-existent tag name", tagName)); + } + fileIO.rename(tagPath(tagName), tagPath(newTagName)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + /** Make sure the tagNames are ALL tags of one snapshot. */ public void deleteAllTagsOfOneSnapshot( List tagNames, TagDeletion tagDeletion, SnapshotManager snapshotManager) { diff --git a/paimon-spark/paimon-spark-3.4/src/test/scala/org/apache/paimon/spark/sql/CreateAndDeleteTagProcedureTest.scala b/paimon-spark/paimon-spark-3.4/src/test/scala/org/apache/paimon/spark/sql/CreateAndDeleteTagProcedureTest.scala index c4b861b29752..eecd94cd9dba 100644 --- a/paimon-spark/paimon-spark-3.4/src/test/scala/org/apache/paimon/spark/sql/CreateAndDeleteTagProcedureTest.scala +++ b/paimon-spark/paimon-spark-3.4/src/test/scala/org/apache/paimon/spark/sql/CreateAndDeleteTagProcedureTest.scala @@ -75,8 +75,16 @@ class CreateAndDeleteTagProcedureTest extends PaimonSparkTestBase with StreamTes checkAnswer( spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"), Row("test_tag") :: Nil) + // test rename_tag checkAnswer( - spark.sql("CALL paimon.sys.delete_tag(table => 'test.T', tag => 'test_tag')"), + spark.sql( + "CALL paimon.sys.rename_tag(table => 'test.T', tag => 'test_tag', new_tag => 'test_tag_1')"), + Row(true) :: Nil) + checkAnswer( + spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"), + Row("test_tag_1") :: Nil) + checkAnswer( + spark.sql("CALL paimon.sys.delete_tag(table => 'test.T', tag => 'test_tag_1')"), Row(true) :: Nil) checkAnswer(spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"), Nil) checkAnswer( diff --git a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkProcedures.java b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkProcedures.java index b8e43c19c8a6..1d5bd9df2f86 100644 --- a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkProcedures.java +++ b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkProcedures.java @@ -34,6 +34,7 @@ import org.apache.paimon.spark.procedure.Procedure; import org.apache.paimon.spark.procedure.ProcedureBuilder; import org.apache.paimon.spark.procedure.RemoveOrphanFilesProcedure; +import org.apache.paimon.spark.procedure.RenameTagProcedure; import org.apache.paimon.spark.procedure.RepairProcedure; import org.apache.paimon.spark.procedure.ResetConsumerProcedure; import org.apache.paimon.spark.procedure.RollbackProcedure; @@ -61,6 +62,7 @@ private static Map> initProcedureBuilders() { ImmutableMap.builder(); procedureBuilders.put("rollback", RollbackProcedure::builder); procedureBuilders.put("create_tag", CreateTagProcedure::builder); + procedureBuilders.put("rename_tag", RenameTagProcedure::builder); procedureBuilders.put( "create_tag_from_timestamp", CreateTagFromTimestampProcedure::builder); procedureBuilders.put("delete_tag", DeleteTagProcedure::builder); diff --git a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RenameTagProcedure.java b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RenameTagProcedure.java new file mode 100644 index 000000000000..9007dadb34e0 --- /dev/null +++ b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RenameTagProcedure.java @@ -0,0 +1,95 @@ +/* + * 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.paimon.spark.procedure; + +import org.apache.spark.sql.catalyst.InternalRow; +import org.apache.spark.sql.connector.catalog.Identifier; +import org.apache.spark.sql.connector.catalog.TableCatalog; +import org.apache.spark.sql.types.DataTypes; +import org.apache.spark.sql.types.Metadata; +import org.apache.spark.sql.types.StructField; +import org.apache.spark.sql.types.StructType; + +import static org.apache.spark.sql.types.DataTypes.StringType; + +/** + * Rename Tag Procedure. Usage: + * + *

+ *  CALL sys.rename_tag(tag => 'tag0', new_tag => 'tag1')
+ * 
+ */ +public class RenameTagProcedure extends BaseProcedure { + + private static final ProcedureParameter[] PARAMETERS = + new ProcedureParameter[] { + ProcedureParameter.required("table", StringType), + ProcedureParameter.required("tag", StringType), + ProcedureParameter.required("new_tag", StringType) + }; + + private static final StructType OUTPUT_TYPE = + new StructType( + new StructField[] { + new StructField("result", DataTypes.BooleanType, true, Metadata.empty()) + }); + + protected RenameTagProcedure(TableCatalog tableCatalog) { + super(tableCatalog); + } + + @Override + public ProcedureParameter[] parameters() { + return PARAMETERS; + } + + @Override + public StructType outputType() { + return OUTPUT_TYPE; + } + + @Override + public InternalRow[] call(InternalRow args) { + Identifier tableIdent = toIdentifier(args.getString(0), PARAMETERS[0].name()); + String tag = args.getString(1); + String newTag = args.getString(2); + + return modifyPaimonTable( + tableIdent, + table -> { + table.renameTag(tag, newTag); + InternalRow outputRow = newInternalRow(true); + return new InternalRow[] {outputRow}; + }); + } + + public static ProcedureBuilder builder() { + return new BaseProcedure.Builder() { + @Override + public RenameTagProcedure doBuild() { + return new RenameTagProcedure(tableCatalog()); + } + }; + } + + @Override + public String description() { + return "RenameTagProcedure"; + } +} From 586e6f6403324707009a2ffa6e1c595cdd4ce99f Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 16:19:08 +0800 Subject: [PATCH 02/12] add flink and action --- .../flink/action/RenameActionFactory.java | 71 ++++++++++++++ .../paimon/flink/action/RenameTagAction.java | 49 ++++++++++ .../flink/procedure/RenameTagProcedure.java | 58 +++++++++++ .../org.apache.paimon.factories.Factory | 2 + .../paimon/flink/action/TagActionITCase.java | 95 +++++++++++++++++++ .../procedure/CreateTagsProcedureITCase.java | 26 ++++- 6 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionFactory.java create mode 100644 paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java create mode 100644 paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionFactory.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionFactory.java new file mode 100644 index 000000000000..fdf2045d36c0 --- /dev/null +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionFactory.java @@ -0,0 +1,71 @@ +/* + * 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.paimon.flink.action; + +import org.apache.flink.api.java.tuple.Tuple3; + +import java.util.Map; +import java.util.Optional; + +/** Factory to create {@link RenameActionFactory}. */ +public class RenameActionFactory implements ActionFactory { + + public static final String IDENTIFIER = "rename_tag"; + + private static final String TAG_NAME = "tag_name"; + private static final String NEW_TAG_NAME = "new_tag_name"; + + @Override + public String identifier() { + return IDENTIFIER; + } + + @Override + public Optional create(MultipleParameterToolAdapter params) { + checkRequiredArgument(params, TAG_NAME); + checkRequiredArgument(params, NEW_TAG_NAME); + + Tuple3 tablePath = getTablePath(params); + Map catalogConfig = optionalConfigMap(params, CATALOG_CONF); + String tagName = params.get(TAG_NAME); + String newTagName = params.get(NEW_TAG_NAME); + + RenameTagAction action = + new RenameTagAction( + tablePath.f0, + tablePath.f1, + tablePath.f2, + catalogConfig, + tagName, + newTagName); + return Optional.of(action); + } + + @Override + public void printHelp() { + System.out.println("Action \"rename_tag\" rename a tag with a new tagname."); + System.out.println(); + + System.out.println("Syntax:"); + System.out.println( + " rename_tag --warehouse --tag_name " + + "--new_tag_name "); + System.out.println(); + } +} diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java new file mode 100644 index 000000000000..994e5f0d7fee --- /dev/null +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java @@ -0,0 +1,49 @@ +/* + * 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.paimon.flink.action; + +import org.apache.paimon.utils.StringUtils; + +import java.util.Map; + +/** Rename Tag action for Flink. */ +public class RenameTagAction extends TableActionBase { + private final String tagName; + private final String newTagName; + + public RenameTagAction( + String warehouse, + String databaseName, + String tableName, + Map catalogConfig, + String tagName, + String newTagName) { + super(warehouse, databaseName, tableName, catalogConfig); + this.tagName = tagName; + this.newTagName = newTagName; + } + + @Override + public void run() throws Exception { + if (StringUtils.isEmpty(tagName) || StringUtils.isEmpty(newTagName)) { + throw new RuntimeException(String.format("tagName or newTagName can not be empty")); + } + table.renameTag(tagName, newTagName); + } +} diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java new file mode 100644 index 000000000000..a60b2c4ad9c4 --- /dev/null +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java @@ -0,0 +1,58 @@ +/* + * 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.paimon.flink.procedure; + +import org.apache.paimon.catalog.Catalog; +import org.apache.paimon.catalog.Identifier; +import org.apache.paimon.table.Table; + +import org.apache.flink.table.annotation.ArgumentHint; +import org.apache.flink.table.annotation.DataTypeHint; +import org.apache.flink.table.annotation.ProcedureHint; +import org.apache.flink.table.procedure.ProcedureContext; + +/** + * Create tag procedure. Usage: + * + *

+ *  CALL sys.rename_tag('tableId', 'tagName', 'newTagName')
+ * 
+ */ +public class RenameTagProcedure extends ProcedureBase { + public static final String IDENTIFIER = "rename_tag"; + + @ProcedureHint( + argument = { + @ArgumentHint(name = "table", type = @DataTypeHint("STRING")), + @ArgumentHint(name = "tagName", type = @DataTypeHint("STRING")), + @ArgumentHint(name = "newTagName", type = @DataTypeHint("STRING")) + }) + public String[] call( + ProcedureContext procedureContext, String tableId, String tagName, String newTagName) + throws Catalog.TableNotExistException { + Table table = catalog.getTable(Identifier.fromString(tableId)); + table.renameTag(tagName, newTagName); + return new String[] {"Success"}; + } + + @Override + public String identifier() { + return IDENTIFIER; + } +} diff --git a/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory b/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory index 9eb450d33508..4ac87fa9f450 100644 --- a/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory +++ b/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory @@ -36,6 +36,7 @@ org.apache.paimon.flink.action.MarkPartitionDoneActionFactory org.apache.paimon.flink.action.CreateBranchActionFactory org.apache.paimon.flink.action.DeleteBranchActionFactory org.apache.paimon.flink.action.FastForwardActionFactory +org.apache.paimon.flink.action.RenameActionFactory org.apache.paimon.flink.action.RepairActionFactory org.apache.paimon.flink.action.RewriteFileIndexActionFactory org.apache.paimon.flink.action.ExpireSnapshotsActionFactory @@ -67,6 +68,7 @@ org.apache.paimon.flink.procedure.privilege.DropPrivilegedUserProcedure org.apache.paimon.flink.procedure.privilege.GrantPrivilegeToUserProcedure org.apache.paimon.flink.procedure.privilege.RevokePrivilegeFromUserProcedure org.apache.paimon.flink.procedure.RepairProcedure +org.apache.paimon.flink.procedure.RenameTagProcedure org.apache.paimon.flink.procedure.FastForwardProcedure org.apache.paimon.flink.procedure.MarkPartitionDoneProcedure org.apache.paimon.flink.procedure.CloneProcedure diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/TagActionITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/TagActionITCase.java index aa98de38715b..fb6d5dfe88f8 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/TagActionITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/TagActionITCase.java @@ -240,6 +240,101 @@ public void testCreateAndDeleteTag(String invoker) throws Exception { assertThat(tagManager.tagExists("tag3")).isFalse(); } + @ParameterizedTest(name = "{0}") + @ValueSource(strings = {"action", "procedure_indexed", "procedure_named"}) + public void testRenameTag(String invoker) throws Exception { + init(warehouse); + + RowType rowType = + RowType.of( + new DataType[] {DataTypes.BIGINT(), DataTypes.STRING()}, + new String[] {"k", "v"}); + FileStoreTable table = + createFileStoreTable( + rowType, + Collections.emptyList(), + Collections.singletonList("k"), + Collections.emptyList(), + Collections.emptyMap()); + + StreamWriteBuilder writeBuilder = table.newStreamWriteBuilder().withCommitUser(commitUser); + write = writeBuilder.newWrite(); + commit = writeBuilder.newCommit(); + + // 3 snapshots + writeData(rowData(1L, BinaryString.fromString("Hi"))); + writeData(rowData(2L, BinaryString.fromString("Hello"))); + writeData(rowData(3L, BinaryString.fromString("Paimon"))); + + TagManager tagManager = new TagManager(table.fileIO(), table.location()); + switch (invoker) { + case "action": + createAction( + CreateTagAction.class, + "create_tag", + "--warehouse", + warehouse, + "--database", + database, + "--table", + tableName, + "--tag_name", + "tag2") + .run(); + break; + case "procedure_indexed": + executeSQL( + String.format( + "CALL sys.create_tag('%s.%s', 'tag2', 2)", database, tableName)); + break; + case "procedure_named": + executeSQL( + String.format( + "CALL sys.create_tag(`table` => '%s.%s', tag => 'tag2', snapshot_id => cast(2 as bigint))", + database, tableName)); + break; + default: + throw new UnsupportedOperationException(invoker); + } + assertThat(tagManager.tagExists("tag2")).isTrue(); + + switch (invoker) { + case "action": + createAction( + RenameTagAction.class, + "rename_tag", + "--warehouse", + warehouse, + "--database", + database, + "--table", + tableName, + "--tag_name", + "tag2", + "--new_tag_name", + "tag3") + .run(); + break; + case "procedure_indexed": + executeSQL( + String.format( + "CALL sys.rename_tag('%s.%s', 'tag2', 'tag3')", + database, tableName)); + break; + case "procedure_named": + executeSQL( + String.format( + "CALL sys.rename_tag(`table` => '%s.%s', tagName => 'tag2', newTagName => 'tag3')", + database, tableName)); + break; + default: + throw new UnsupportedOperationException(invoker); + } + + assertThat(tagManager.tagExists("tag2")).isFalse(); + assertThat(tagManager.tagExists("tag3")).isTrue(); + } + @ParameterizedTest(name = "{0}") @ValueSource(strings = {"action", "procedure_indexed", "procedure_named"}) public void testCreateLatestTag(String invoker) throws Exception { diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/CreateTagsProcedureITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/CreateTagsProcedureITCase.java index aef952b6c561..d882eef27df2 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/CreateTagsProcedureITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/CreateTagsProcedureITCase.java @@ -27,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; -/** IT Case for {@link CreateTagProcedure}. */ +/** IT Case for {@link CreateTagsProcedureITCase}. */ public class CreateTagsProcedureITCase extends CatalogITCaseBase { @Test @@ -58,6 +58,30 @@ public void testCreateTags() { .containsExactlyInAnyOrder("+I[k, 2024-01-01]"); } + @Test + public void testRenameTag() { + sql( + "CREATE TABLE T (" + + " k STRING," + + " dt STRING," + + " PRIMARY KEY (k, dt) NOT ENFORCED" + + ") PARTITIONED BY (dt) WITH (" + + " 'bucket' = '1'" + + ")"); + sql("insert into T values('k', '2024-01-01')"); + sql("insert into T values('k2', '2024-01-02')"); + + sql("CALL sys.create_tag('default.T', 'tag1')"); + + assertThat(sql("select tag_name from `T$tags`").stream().map(Row::toString)) + .containsExactlyInAnyOrder("+I[tag1]"); + + sql("CALL sys.rename_tag('default.T', 'tag1', 'tag2')"); + + assertThat(sql("select tag_name from `T$tags`").stream().map(Row::toString)) + .containsExactlyInAnyOrder("+I[tag2]"); + } + @Test public void testThrowSnapshotNotExistException() { sql( From f2b6d43273f2c010f68990a6e53714ac74f39199 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 16:23:24 +0800 Subject: [PATCH 03/12] add doc --- docs/content/spark/procedures.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/content/spark/procedures.md b/docs/content/spark/procedures.md index 9f6e061c1df2..c4ddaa8d1b03 100644 --- a/docs/content/spark/procedures.md +++ b/docs/content/spark/procedures.md @@ -109,6 +109,21 @@ This section introduce all available spark procedures about paimon. CALL sys.create_tag_from_timestamp(`table` => 'default.T', `tag` => 'my_tag', `timestamp` => 1724404318750, time_retained => '1 d') + + rename_tag + + Rename tag to new tag name. Arguments: +
  • table: the target table identifier. Cannot be empty.
  • +
  • tag_name: name of the tag. Cannot be empty.
  • +
  • new_tag_name: the new tag name to rename.
  • + + + -- based on snapshot 10 with 1d
    + CALL sys.create_tag(table => 'default.T', tag => 'my_tag', snapshot => 10, time_retained => '1 d')

    + -- based on the latest snapshot
    + CALL sys.create_tag(table => 'default.T', tag => 'my_tag') + + delete_tag From bd6abed5231f96d5654d8d972db19b3519ff7ca3 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 16:30:52 +0800 Subject: [PATCH 04/12] add more case --- .../procedure/CreateAndDeleteTagProcedureTest.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/procedure/CreateAndDeleteTagProcedureTest.scala b/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/procedure/CreateAndDeleteTagProcedureTest.scala index 296680919264..b697e234abe3 100644 --- a/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/procedure/CreateAndDeleteTagProcedureTest.scala +++ b/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/procedure/CreateAndDeleteTagProcedureTest.scala @@ -110,10 +110,20 @@ class CreateAndDeleteTagProcedureTest extends PaimonSparkTestBase with StreamTes spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"), Row("test_tag_1") :: Row("test_tag_2") :: Nil) + // test rename_tag + checkAnswer( + spark.sql( + "CALL paimon.sys.rename_tag(table => 'test.T', tag => 'test_tag_1', new_tag => 'test_tag_3')"), + Row(true) :: Nil + ) + checkAnswer( + spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"), + Row("test_tag_2") :: Row("test_tag_3") :: Nil) + // delete test_tag_1 and test_tag_2 checkAnswer( spark.sql( - "CALL paimon.sys.delete_tag(table => 'test.T', tag => 'test_tag_1,test_tag_2')"), + "CALL paimon.sys.delete_tag(table => 'test.T', tag => 'test_tag_2,test_tag_3')"), Row(true) :: Nil) checkAnswer(spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"), Nil) From de208281f476eab0e3dba0fa360d4482056cd06d Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 17:33:39 +0800 Subject: [PATCH 05/12] fix doc --- docs/content/spark/procedures.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/content/spark/procedures.md b/docs/content/spark/procedures.md index c4ddaa8d1b03..3a449d0e73cd 100644 --- a/docs/content/spark/procedures.md +++ b/docs/content/spark/procedures.md @@ -119,9 +119,7 @@ This section introduce all available spark procedures about paimon. -- based on snapshot 10 with 1d
    - CALL sys.create_tag(table => 'default.T', tag => 'my_tag', snapshot => 10, time_retained => '1 d')

    - -- based on the latest snapshot
    - CALL sys.create_tag(table => 'default.T', tag => 'my_tag') + CALL sys.rename_tag(table => 'default.T', tag_name => 'tag1', new_tag_name => 'tag2') From 355c33c35ba52064a6190dae8774bd80e53bc12f Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 17:34:09 +0800 Subject: [PATCH 06/12] fix doc --- docs/content/spark/procedures.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/content/spark/procedures.md b/docs/content/spark/procedures.md index 3a449d0e73cd..48567b41a3a7 100644 --- a/docs/content/spark/procedures.md +++ b/docs/content/spark/procedures.md @@ -118,7 +118,6 @@ This section introduce all available spark procedures about paimon.
  • new_tag_name: the new tag name to rename.
  • - -- based on snapshot 10 with 1d
    CALL sys.rename_tag(table => 'default.T', tag_name => 'tag1', new_tag_name => 'tag2') From bca053af670a24d592c13813f47efcb82f770085 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 19:41:54 +0800 Subject: [PATCH 07/12] address --- docs/content/spark/procedures.md | 4 ++-- .../paimon/privilege/PrivilegedFileStoreTable.java | 4 ++-- .../paimon/table/AbstractFileStoreTable.java | 4 ++-- .../paimon/table/DelegatedFileStoreTable.java | 4 ++-- .../java/org/apache/paimon/table/FormatTable.java | 2 +- .../org/apache/paimon/table/ReadonlyTable.java | 2 +- .../main/java/org/apache/paimon/table/Table.java | 2 +- .../java/org/apache/paimon/utils/TagManager.java | 6 +++--- ...ionFactory.java => RenameActionTagFactory.java} | 14 +++++++------- .../paimon/flink/action/RenameTagAction.java | 12 ++++++------ .../paimon/flink/procedure/RenameTagProcedure.java | 8 ++++---- .../services/org.apache.paimon.factories.Factory | 2 +- .../paimon/flink/action/TagActionITCase.java | 4 ++-- .../sql/CreateAndDeleteTagProcedureTest.scala | 2 +- .../paimon/spark/procedure/RenameTagProcedure.java | 8 ++++---- .../CreateAndDeleteTagProcedureTest.scala | 2 +- 16 files changed, 40 insertions(+), 40 deletions(-) rename paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/{RenameActionFactory.java => RenameActionTagFactory.java} (83%) diff --git a/docs/content/spark/procedures.md b/docs/content/spark/procedures.md index 48567b41a3a7..506d2af2d5f0 100644 --- a/docs/content/spark/procedures.md +++ b/docs/content/spark/procedures.md @@ -115,10 +115,10 @@ This section introduce all available spark procedures about paimon. Rename tag to new tag name. Arguments:
  • table: the target table identifier. Cannot be empty.
  • tag_name: name of the tag. Cannot be empty.
  • -
  • new_tag_name: the new tag name to rename.
  • +
  • target_tag_name: the new tag name to rename.
  • - CALL sys.rename_tag(table => 'default.T', tag_name => 'tag1', new_tag_name => 'tag2') + CALL sys.rename_tag(table => 'default.T', tag_name => 'tag1', target_tag_name => 'tag2') diff --git a/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedFileStoreTable.java index 717e2e9d93c8..4eb1a1a90c8c 100644 --- a/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedFileStoreTable.java @@ -122,9 +122,9 @@ public void createTag(String tagName, Duration timeRetained) { } @Override - public void renameTag(String tagName, String newTagName) { + public void renameTag(String tagName, String targetTagName) { privilegeChecker.assertCanInsert(identifier); - wrapped.renameTag(tagName, newTagName); + wrapped.renameTag(tagName, targetTagName); } @Override diff --git a/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java index da72212471af..171b7325a91d 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java @@ -572,8 +572,8 @@ private void createTag(String tagName, Snapshot fromSnapshot, @Nullable Duration } @Override - public void renameTag(String tagName, String newTagName) { - tagManager().renameTag(tagName, newTagName); + public void renameTag(String tagName, String targetTagName) { + tagManager().renameTag(tagName, targetTagName); } @Override diff --git a/paimon-core/src/main/java/org/apache/paimon/table/DelegatedFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/table/DelegatedFileStoreTable.java index 8c0fcd183661..5d6331aa414e 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/DelegatedFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/DelegatedFileStoreTable.java @@ -183,8 +183,8 @@ public void createTag(String tagName, long fromSnapshotId, Duration timeRetained } @Override - public void renameTag(String tagName, String newTagName) { - wrapped.renameTag(tagName, newTagName); + public void renameTag(String tagName, String targetTagName) { + wrapped.renameTag(tagName, targetTagName); } @Override diff --git a/paimon-core/src/main/java/org/apache/paimon/table/FormatTable.java b/paimon-core/src/main/java/org/apache/paimon/table/FormatTable.java index 0bef58b509ec..3224131d4afd 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/FormatTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/FormatTable.java @@ -267,7 +267,7 @@ default void createTag(String tagName, Duration timeRetained) { } @Override - default void renameTag(String tagName, String newTagName) { + default void renameTag(String tagName, String targetTagName) { throw new UnsupportedOperationException(); } diff --git a/paimon-core/src/main/java/org/apache/paimon/table/ReadonlyTable.java b/paimon-core/src/main/java/org/apache/paimon/table/ReadonlyTable.java index 989fd7592201..4ae593b5577f 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/ReadonlyTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/ReadonlyTable.java @@ -190,7 +190,7 @@ default void createTag(String tagName, Duration timeRetained) { } @Override - default void renameTag(String tagName, String newTagName) { + default void renameTag(String tagName, String targetTagName) { throw new UnsupportedOperationException( String.format( "Readonly Table %s does not support renameTag.", diff --git a/paimon-core/src/main/java/org/apache/paimon/table/Table.java b/paimon-core/src/main/java/org/apache/paimon/table/Table.java index 89bd197da0ce..613dfca3158a 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/Table.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/Table.java @@ -118,7 +118,7 @@ default String fullName() { void createTag(String tagName, Duration timeRetained); @Experimental - void renameTag(String tagName, String newTagName); + void renameTag(String tagName, String targetTagName); /** Delete a tag by name. */ @Experimental diff --git a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java index 33e5323f0c53..41b62f83a99b 100644 --- a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java +++ b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java @@ -144,17 +144,17 @@ public void createTag( } } - public void renameTag(String tagName, String newTagName) { + public void renameTag(String tagName, String targetTagName) { try { if (!tagExists(tagName)) { throw new RuntimeException(String.format("tag: %s is not exists", tagName)); } - if (tagExists(newTagName)) { + if (tagExists(targetTagName)) { throw new RuntimeException( String.format( "tag: %s existed, please set a non-existent tag name", tagName)); } - fileIO.rename(tagPath(tagName), tagPath(newTagName)); + fileIO.rename(tagPath(tagName), tagPath(targetTagName)); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionFactory.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionTagFactory.java similarity index 83% rename from paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionFactory.java rename to paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionTagFactory.java index fdf2045d36c0..cfa8157a623e 100644 --- a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionFactory.java +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionTagFactory.java @@ -23,13 +23,13 @@ import java.util.Map; import java.util.Optional; -/** Factory to create {@link RenameActionFactory}. */ -public class RenameActionFactory implements ActionFactory { +/** Factory to create {@link RenameActionTagFactory}. */ +public class RenameActionTagFactory implements ActionFactory { public static final String IDENTIFIER = "rename_tag"; private static final String TAG_NAME = "tag_name"; - private static final String NEW_TAG_NAME = "new_tag_name"; + private static final String TARGET_TAG_NAME = "target_tag_name"; @Override public String identifier() { @@ -39,12 +39,12 @@ public String identifier() { @Override public Optional create(MultipleParameterToolAdapter params) { checkRequiredArgument(params, TAG_NAME); - checkRequiredArgument(params, NEW_TAG_NAME); + checkRequiredArgument(params, TARGET_TAG_NAME); Tuple3 tablePath = getTablePath(params); Map catalogConfig = optionalConfigMap(params, CATALOG_CONF); String tagName = params.get(TAG_NAME); - String newTagName = params.get(NEW_TAG_NAME); + String targetTagName = params.get(TARGET_TAG_NAME); RenameTagAction action = new RenameTagAction( @@ -53,7 +53,7 @@ public Optional create(MultipleParameterToolAdapter params) { tablePath.f2, catalogConfig, tagName, - newTagName); + targetTagName); return Optional.of(action); } @@ -65,7 +65,7 @@ public void printHelp() { System.out.println("Syntax:"); System.out.println( " rename_tag --warehouse --tag_name " - + "--new_tag_name "); + + "--target_tag_name "); System.out.println(); } } diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java index 994e5f0d7fee..5cebcab956af 100644 --- a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java @@ -25,7 +25,7 @@ /** Rename Tag action for Flink. */ public class RenameTagAction extends TableActionBase { private final String tagName; - private final String newTagName; + private final String targetTagName; public RenameTagAction( String warehouse, @@ -33,17 +33,17 @@ public RenameTagAction( String tableName, Map catalogConfig, String tagName, - String newTagName) { + String targetTagName) { super(warehouse, databaseName, tableName, catalogConfig); this.tagName = tagName; - this.newTagName = newTagName; + this.targetTagName = targetTagName; } @Override public void run() throws Exception { - if (StringUtils.isEmpty(tagName) || StringUtils.isEmpty(newTagName)) { - throw new RuntimeException(String.format("tagName or newTagName can not be empty")); + if (StringUtils.isEmpty(tagName) || StringUtils.isEmpty(targetTagName)) { + throw new RuntimeException(String.format("tagName or targetTagName can not be empty")); } - table.renameTag(tagName, newTagName); + table.renameTag(tagName, targetTagName); } } diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java index a60b2c4ad9c4..721462d1d577 100644 --- a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java @@ -31,7 +31,7 @@ * Create tag procedure. Usage: * *
    
    - *  CALL sys.rename_tag('tableId', 'tagName', 'newTagName')
    + *  CALL sys.rename_tag('tableId', 'tagName', 'targetTagName')
      * 
    */ public class RenameTagProcedure extends ProcedureBase { @@ -41,13 +41,13 @@ public class RenameTagProcedure extends ProcedureBase { argument = { @ArgumentHint(name = "table", type = @DataTypeHint("STRING")), @ArgumentHint(name = "tagName", type = @DataTypeHint("STRING")), - @ArgumentHint(name = "newTagName", type = @DataTypeHint("STRING")) + @ArgumentHint(name = "targetTagName", type = @DataTypeHint("STRING")) }) public String[] call( - ProcedureContext procedureContext, String tableId, String tagName, String newTagName) + ProcedureContext procedureContext, String tableId, String tagName, String targetTagName) throws Catalog.TableNotExistException { Table table = catalog.getTable(Identifier.fromString(tableId)); - table.renameTag(tagName, newTagName); + table.renameTag(tagName, targetTagName); return new String[] {"Success"}; } diff --git a/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory b/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory index 4ac87fa9f450..862dd6c521bc 100644 --- a/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory +++ b/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory @@ -36,7 +36,7 @@ org.apache.paimon.flink.action.MarkPartitionDoneActionFactory org.apache.paimon.flink.action.CreateBranchActionFactory org.apache.paimon.flink.action.DeleteBranchActionFactory org.apache.paimon.flink.action.FastForwardActionFactory -org.apache.paimon.flink.action.RenameActionFactory +org.apache.paimon.flink.action.RenameActionTagFactory org.apache.paimon.flink.action.RepairActionFactory org.apache.paimon.flink.action.RewriteFileIndexActionFactory org.apache.paimon.flink.action.ExpireSnapshotsActionFactory diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/TagActionITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/TagActionITCase.java index fb6d5dfe88f8..7310a68df7a2 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/TagActionITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/TagActionITCase.java @@ -311,7 +311,7 @@ public void testRenameTag(String invoker) throws Exception { tableName, "--tag_name", "tag2", - "--new_tag_name", + "--target_tag_name", "tag3") .run(); break; @@ -324,7 +324,7 @@ public void testRenameTag(String invoker) throws Exception { case "procedure_named": executeSQL( String.format( - "CALL sys.rename_tag(`table` => '%s.%s', tagName => 'tag2', newTagName => 'tag3')", + "CALL sys.rename_tag(`table` => '%s.%s', tagName => 'tag2', targetTagName => 'tag3')", database, tableName)); break; default: diff --git a/paimon-spark/paimon-spark-3.4/src/test/scala/org/apache/paimon/spark/sql/CreateAndDeleteTagProcedureTest.scala b/paimon-spark/paimon-spark-3.4/src/test/scala/org/apache/paimon/spark/sql/CreateAndDeleteTagProcedureTest.scala index eecd94cd9dba..3f59e897ec6c 100644 --- a/paimon-spark/paimon-spark-3.4/src/test/scala/org/apache/paimon/spark/sql/CreateAndDeleteTagProcedureTest.scala +++ b/paimon-spark/paimon-spark-3.4/src/test/scala/org/apache/paimon/spark/sql/CreateAndDeleteTagProcedureTest.scala @@ -78,7 +78,7 @@ class CreateAndDeleteTagProcedureTest extends PaimonSparkTestBase with StreamTes // test rename_tag checkAnswer( spark.sql( - "CALL paimon.sys.rename_tag(table => 'test.T', tag => 'test_tag', new_tag => 'test_tag_1')"), + "CALL paimon.sys.rename_tag(table => 'test.T', tag => 'test_tag', target_tag => 'test_tag_1')"), Row(true) :: Nil) checkAnswer( spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"), diff --git a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RenameTagProcedure.java b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RenameTagProcedure.java index 9007dadb34e0..73c0dc35374d 100644 --- a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RenameTagProcedure.java +++ b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RenameTagProcedure.java @@ -32,7 +32,7 @@ * Rename Tag Procedure. Usage: * *
    
    - *  CALL sys.rename_tag(tag => 'tag0', new_tag => 'tag1')
    + *  CALL sys.rename_tag(tag => 'tag0', target_tag => 'tag1')
      * 
    */ public class RenameTagProcedure extends BaseProcedure { @@ -41,7 +41,7 @@ public class RenameTagProcedure extends BaseProcedure { new ProcedureParameter[] { ProcedureParameter.required("table", StringType), ProcedureParameter.required("tag", StringType), - ProcedureParameter.required("new_tag", StringType) + ProcedureParameter.required("target_tag", StringType) }; private static final StructType OUTPUT_TYPE = @@ -68,12 +68,12 @@ public StructType outputType() { public InternalRow[] call(InternalRow args) { Identifier tableIdent = toIdentifier(args.getString(0), PARAMETERS[0].name()); String tag = args.getString(1); - String newTag = args.getString(2); + String targetTag = args.getString(2); return modifyPaimonTable( tableIdent, table -> { - table.renameTag(tag, newTag); + table.renameTag(tag, targetTag); InternalRow outputRow = newInternalRow(true); return new InternalRow[] {outputRow}; }); diff --git a/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/procedure/CreateAndDeleteTagProcedureTest.scala b/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/procedure/CreateAndDeleteTagProcedureTest.scala index b697e234abe3..3dc90db0016a 100644 --- a/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/procedure/CreateAndDeleteTagProcedureTest.scala +++ b/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/procedure/CreateAndDeleteTagProcedureTest.scala @@ -113,7 +113,7 @@ class CreateAndDeleteTagProcedureTest extends PaimonSparkTestBase with StreamTes // test rename_tag checkAnswer( spark.sql( - "CALL paimon.sys.rename_tag(table => 'test.T', tag => 'test_tag_1', new_tag => 'test_tag_3')"), + "CALL paimon.sys.rename_tag(table => 'test.T', tag => 'test_tag_1', target_tag => 'test_tag_3')"), Row(true) :: Nil ) checkAnswer( From 44e80c7f3aef4413a75bcdccfb0b01ad92495eb4 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 19:45:24 +0800 Subject: [PATCH 08/12] address msg --- .../src/main/java/org/apache/paimon/utils/TagManager.java | 3 +-- .../java/org/apache/paimon/flink/action/RenameTagAction.java | 5 ++++- .../apache/paimon/flink/procedure/RenameTagProcedure.java | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java index 41b62f83a99b..94a6aeab3679 100644 --- a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java +++ b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java @@ -151,8 +151,7 @@ public void renameTag(String tagName, String targetTagName) { } if (tagExists(targetTagName)) { throw new RuntimeException( - String.format( - "tag: %s existed, please set a non-existent tag name", tagName)); + String.format("The specified tag name [%s] does not exist.", tagName)); } fileIO.rename(tagPath(tagName), tagPath(targetTagName)); } catch (IOException e) { diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java index 5cebcab956af..3b12b4c119a1 100644 --- a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagAction.java @@ -42,7 +42,10 @@ public RenameTagAction( @Override public void run() throws Exception { if (StringUtils.isEmpty(tagName) || StringUtils.isEmpty(targetTagName)) { - throw new RuntimeException(String.format("tagName or targetTagName can not be empty")); + throw new RuntimeException( + String.format( + "The specified tag name [%s] or target tag name [%s] cannot be empty.", + tagName, targetTagName)); } table.renameTag(tagName, targetTagName); } diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java index 721462d1d577..2ad98e72df23 100644 --- a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java @@ -48,7 +48,8 @@ public String[] call( throws Catalog.TableNotExistException { Table table = catalog.getTable(Identifier.fromString(tableId)); table.renameTag(tagName, targetTagName); - return new String[] {"Success"}; + String ret = String.format("Rename [%s] to [%s] successfully.", tagName, targetTagName); + return new String[] {ret}; } @Override From 993d569d36341a7074db1118d747c1c006318b51 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 19:51:20 +0800 Subject: [PATCH 09/12] address --- .../paimon/flink/procedure/CreateTagsProcedureITCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/CreateTagsProcedureITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/CreateTagsProcedureITCase.java index d882eef27df2..77e2b74c5d50 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/CreateTagsProcedureITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/CreateTagsProcedureITCase.java @@ -27,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; -/** IT Case for {@link CreateTagsProcedureITCase}. */ +/** IT Case for {@link CreateTagProcedure}. */ public class CreateTagsProcedureITCase extends CatalogITCaseBase { @Test From f88828221255534e13b8c9e29bd5ceb44f007cc5 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 20:42:33 +0800 Subject: [PATCH 10/12] address msg --- .../src/main/java/org/apache/paimon/utils/TagManager.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java index 94a6aeab3679..90a5054b4e47 100644 --- a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java +++ b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java @@ -147,11 +147,14 @@ public void createTag( public void renameTag(String tagName, String targetTagName) { try { if (!tagExists(tagName)) { - throw new RuntimeException(String.format("tag: %s is not exists", tagName)); + throw new RuntimeException( + String.format("The specified tag name [%s] does not exist.", tagName)); } if (tagExists(targetTagName)) { throw new RuntimeException( - String.format("The specified tag name [%s] does not exist.", tagName)); + String.format( + "The specified target tag name [%s] does not exist.", + targetTagName)); } fileIO.rename(tagPath(tagName), tagPath(targetTagName)); } catch (IOException e) { From eb1a5b1aad99a845ce40ecbe63648e01b8628eb8 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 29 Sep 2024 20:52:14 +0800 Subject: [PATCH 11/12] address msg --- .../src/main/java/org/apache/paimon/utils/TagManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java index 90a5054b4e47..8aecb1ab70ac 100644 --- a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java +++ b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java @@ -153,7 +153,7 @@ public void renameTag(String tagName, String targetTagName) { if (tagExists(targetTagName)) { throw new RuntimeException( String.format( - "The specified target tag name [%s] does not exist.", + "The specified target tag name [%s] existed, please set a non-existent tag name.", targetTagName)); } fileIO.rename(tagPath(tagName), tagPath(targetTagName)); From b074e4043a3c3668ff24f6de08c561135972b6a7 Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Tue, 1 Oct 2024 11:10:59 +0800 Subject: [PATCH 12/12] address --- docs/content/spark/procedures.md | 4 ++-- ...eActionTagFactory.java => RenameTagActionFactory.java} | 8 ++++---- .../apache/paimon/flink/procedure/RenameTagProcedure.java | 2 +- .../META-INF/services/org.apache.paimon.factories.Factory | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) rename paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/{RenameActionTagFactory.java => RenameTagActionFactory.java} (92%) diff --git a/docs/content/spark/procedures.md b/docs/content/spark/procedures.md index 506d2af2d5f0..1557fd6a7ee5 100644 --- a/docs/content/spark/procedures.md +++ b/docs/content/spark/procedures.md @@ -112,10 +112,10 @@ This section introduce all available spark procedures about paimon. rename_tag - Rename tag to new tag name. Arguments: + Rename a tag with a new tag name. Arguments:
  • table: the target table identifier. Cannot be empty.
  • tag_name: name of the tag. Cannot be empty.
  • -
  • target_tag_name: the new tag name to rename.
  • +
  • target_tag_name: the new tag name to rename. Cannot be empty.
  • CALL sys.rename_tag(table => 'default.T', tag_name => 'tag1', target_tag_name => 'tag2') diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionTagFactory.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagActionFactory.java similarity index 92% rename from paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionTagFactory.java rename to paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagActionFactory.java index cfa8157a623e..84f174d39bbb 100644 --- a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameActionTagFactory.java +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RenameTagActionFactory.java @@ -23,10 +23,10 @@ import java.util.Map; import java.util.Optional; -/** Factory to create {@link RenameActionTagFactory}. */ -public class RenameActionTagFactory implements ActionFactory { +/** Factory to create {@link RenameTagActionFactory}. */ +public class RenameTagActionFactory implements ActionFactory { - public static final String IDENTIFIER = "rename_tag"; + private static final String IDENTIFIER = "rename_tag"; private static final String TAG_NAME = "tag_name"; private static final String TARGET_TAG_NAME = "target_tag_name"; @@ -59,7 +59,7 @@ public Optional create(MultipleParameterToolAdapter params) { @Override public void printHelp() { - System.out.println("Action \"rename_tag\" rename a tag with a new tagname."); + System.out.println("Action \"rename_tag\" rename a tag with a new tag name."); System.out.println(); System.out.println("Syntax:"); diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java index 2ad98e72df23..5476e807be71 100644 --- a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/RenameTagProcedure.java @@ -35,7 +35,7 @@ * */ public class RenameTagProcedure extends ProcedureBase { - public static final String IDENTIFIER = "rename_tag"; + private static final String IDENTIFIER = "rename_tag"; @ProcedureHint( argument = { diff --git a/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory b/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory index 862dd6c521bc..3ae35ade54bb 100644 --- a/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory +++ b/paimon-flink/paimon-flink-common/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory @@ -36,7 +36,7 @@ org.apache.paimon.flink.action.MarkPartitionDoneActionFactory org.apache.paimon.flink.action.CreateBranchActionFactory org.apache.paimon.flink.action.DeleteBranchActionFactory org.apache.paimon.flink.action.FastForwardActionFactory -org.apache.paimon.flink.action.RenameActionTagFactory +org.apache.paimon.flink.action.RenameTagActionFactory org.apache.paimon.flink.action.RepairActionFactory org.apache.paimon.flink.action.RewriteFileIndexActionFactory org.apache.paimon.flink.action.ExpireSnapshotsActionFactory