Skip to content
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

[spark] Replace create existing tag semantic with replace_tag #4346

Merged
merged 5 commits into from
Oct 31, 2024

Conversation

askwang
Copy link
Contributor

@askwang askwang commented Oct 18, 2024

Purpose

In default way, the create_tag procedure for an existing tag means to update it or fail, it's semantic is not very accurate, replace it with repalce_tag procedure.

before semantic

CALL paimon.sys.create_tag(table => 'test.T', tag => 'test_tag', snapshot => 1)")

-- success. update it
CALL paimon.sys.create_tag(table => 'test.T', tag => 'test_tag', snapshot => 1, time_retained => '1 d')")

-- failed
CALL paimon.sys.create_tag(table => 'test.T', tag => 'test_tag', snapshot => 2)")

after semantic

CALL paimon.sys.create_tag(table => 'test.T', tag => 'test_tag', snapshot => 1)")

-- failed
CALL paimon.sys.create_tag(table => 'test.T', tag => 'test_tag', snapshot => 1, time_retained => '1 d')")

-- success. use replace to update
CALL paimon.sys.replace_tag(table => 'test.T', tag => 'test_tag', snapshot => 2, time_retained => '1 d')")

Tests

API and Format

Documentation

Copy link
Contributor

@wwj6591812 wwj6591812 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1、I think update_tag may be better?
2、You alse need modify flink action&& procedure and doc.

@@ -121,6 +121,19 @@ This section introduce all available spark procedures about paimon.
CALL sys.rename_tag(table => 'default.T', tag_name => 'tag1', target_tag_name => 'tag2')
</td>
</tr>
<tr>
<td>replace_tag</td>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think update_tag may be better?

Replace an existing tag with new tag info. Arguments:
<li>table: the target table identifier. Cannot be empty.</li>
<li>tag: name of the existed tag. Cannot be empty.</li>
<li>snapshot(Long): id of the snapshot which the tag is based on.</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1、snapshotId
2、It is optional.

<li>table: the target table identifier. Cannot be empty.</li>
<li>tag: name of the existed tag. Cannot be empty.</li>
<li>snapshot(Long): id of the snapshot which the tag is based on.</li>
<li>time_retained: The maximum time retained for the existing tag.</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2、It is optional.

public void replaceTag(String tagName, @Nullable Duration timeRetained) {
Snapshot latestSnapshot = snapshotManager().latestSnapshot();
SnapshotNotExistException.checkNotNull(
latestSnapshot, "Cannot create tag because latest snapshot doesn't exist.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can not update tag because latest snapshot doesn't exist.

findSnapshot(fromSnapshotId),
tagName,
timeRetained,
store().createTagCallbacks());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you should think this case:
If user update a tag, but he don't want call createTagCallbacks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good, replace the existing tag is no need to call callback again.

@@ -120,6 +120,12 @@ default String fullName() {
@Experimental
void renameTag(String tagName, String targetTagName);

@Experimental
void replaceTag(String tagName, Duration timeRetained);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

接口方法【replaceTag】必须使用javadoc注释


public void createOrReplaceTag(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createOrUpdateTag

new StructField[] {
new StructField("result", DataTypes.BooleanType, true, Metadata.empty())
});
public class CreateTagProcedure extends CreateOrReplaceTagBaseProcedure {

protected CreateTagProcedure(TableCatalog tableCatalog) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not private?

import java.time.Duration;

/** A procedure to replace a tag. */
public class ReplaceTagTagProcedure extends CreateOrReplaceTagBaseProcedure {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateTagProcedure

/** A procedure to replace a tag. */
public class ReplaceTagTagProcedure extends CreateOrReplaceTagBaseProcedure {

protected ReplaceTagTagProcedure(TableCatalog tableCatalog) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not private?

@askwang
Copy link
Contributor Author

askwang commented Oct 21, 2024

addressed comments, thanks for review @wwj6591812
A little difference, keep the name 'replace_tag' not change. I think it's name is ok, and iceberg also uses 'replace tag' to update tag. what do you think?

@wwj6591812
Copy link
Contributor

addressed comments, thanks for review @wwj6591812 A little difference, keep the name 'replace_tag' not change. I think it's name is ok, and iceberg also uses 'replace tag' to update tag. what do you think?

ok

}

@Override
public void replaceTag(String tagName, long fromSnapshotId, @Nullable Duration timeRetained) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just create a replaceTag(String tagName, @Nullable Long fromSnapshotId, @Nullable Duration timeRetained)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

@JingsongLi JingsongLi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@JingsongLi JingsongLi merged commit e2acdc2 into apache:master Oct 31, 2024
13 checks passed
hang8929201 pushed a commit to hang8929201/paimon that referenced this pull request Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants