-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Support rename tag action and procedure #4277
Changes from all commits
c1f27b4
586e6f6
f2b6d43
bd6abed
de20828
355c33c
bca053a
44e80c7
993d569
f888282
eb1a5b1
b074e40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,24 @@ public void createTag( | |
} | ||
} | ||
|
||
public void renameTag(String tagName, String targetTagName) { | ||
try { | ||
if (!tagExists(tagName)) { | ||
throw new RuntimeException( | ||
String.format("The specified tag name [%s] does not exist.", tagName)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The specified tag name [%s] does not exist ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (tagExists(targetTagName)) { | ||
throw new RuntimeException( | ||
String.format( | ||
"The specified target tag name [%s] existed, please set a non-existent tag name.", | ||
targetTagName)); | ||
} | ||
fileIO.rename(tagPath(tagName), tagPath(targetTagName)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** Make sure the tagNames are ALL tags of one snapshot. */ | ||
public void deleteAllTagsOfOneSnapshot( | ||
List<String> tagNames, TagDeletion tagDeletion, SnapshotManager snapshotManager) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 targetTagName; | ||
|
||
public RenameTagAction( | ||
String warehouse, | ||
String databaseName, | ||
String tableName, | ||
Map<String, String> catalogConfig, | ||
String tagName, | ||
String targetTagName) { | ||
super(warehouse, databaseName, tableName, catalogConfig); | ||
this.tagName = tagName; | ||
this.targetTagName = targetTagName; | ||
} | ||
|
||
@Override | ||
public void run() throws Exception { | ||
if (StringUtils.isEmpty(tagName) || StringUtils.isEmpty(targetTagName)) { | ||
throw new RuntimeException( | ||
String.format( | ||
"The specified tag name [%s] or target tag name [%s] cannot be empty.", | ||
tagName, targetTagName)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String.format("The specified tag name [%s] or target tag name [%s] cannot be empty.", tagName, targetName) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
table.renameTag(tagName, targetTagName); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 RenameTagActionFactory}. */ | ||
public class RenameTagActionFactory implements ActionFactory { | ||
|
||
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"; | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Optional<Action> create(MultipleParameterToolAdapter params) { | ||
checkRequiredArgument(params, TAG_NAME); | ||
checkRequiredArgument(params, TARGET_TAG_NAME); | ||
|
||
Tuple3<String, String, String> tablePath = getTablePath(params); | ||
Map<String, String> catalogConfig = optionalConfigMap(params, CATALOG_CONF); | ||
String tagName = params.get(TAG_NAME); | ||
String targetTagName = params.get(TARGET_TAG_NAME); | ||
|
||
RenameTagAction action = | ||
new RenameTagAction( | ||
tablePath.f0, | ||
tablePath.f1, | ||
tablePath.f2, | ||
catalogConfig, | ||
tagName, | ||
targetTagName); | ||
return Optional.of(action); | ||
} | ||
|
||
@Override | ||
public void printHelp() { | ||
System.out.println("Action \"rename_tag\" rename a tag with a new tag name."); | ||
System.out.println(); | ||
|
||
System.out.println("Syntax:"); | ||
System.out.println( | ||
" rename_tag --warehouse <warehouse_path> --tag_name <tag_name> " | ||
+ "--target_tag_name <target_tag_name>"); | ||
System.out.println(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create tag procedure? |
||
* | ||
* <pre><code> | ||
* CALL sys.rename_tag('tableId', 'tagName', 'targetTagName') | ||
* </code></pre> | ||
*/ | ||
public class RenameTagProcedure extends ProcedureBase { | ||
private static final String IDENTIFIER = "rename_tag"; | ||
|
||
@ProcedureHint( | ||
argument = { | ||
@ArgumentHint(name = "table", type = @DataTypeHint("STRING")), | ||
@ArgumentHint(name = "tagName", type = @DataTypeHint("STRING")), | ||
@ArgumentHint(name = "targetTagName", type = @DataTypeHint("STRING")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a empty line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}) | ||
public String[] call( | ||
ProcedureContext procedureContext, String tableId, String tagName, String targetTagName) | ||
throws Catalog.TableNotExistException { | ||
Table table = catalog.getTable(Identifier.fromString(tableId)); | ||
table.renameTag(tagName, targetTagName); | ||
String ret = String.format("Rename [%s] to [%s] successfully.", tagName, targetTagName); | ||
return new String[] {ret}; | ||
} | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_name
will be better ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done