You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "Aitozi (via GitHub)" <gi...@apache.org> on 2025/02/28 06:49:31 UTC

[PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Aitozi opened a new pull request, #5185:
URL: https://github.com/apache/paimon/pull/5185

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   Linked issue: close #5181
   
   <!-- What is the purpose of the change -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "Aitozi (via GitHub)" <gi...@apache.org>.
Aitozi commented on code in PR #5185:
URL: https://github.com/apache/paimon/pull/5185#discussion_r1974911813


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/WriteIntoPaimonTable.scala:
##########
@@ -83,10 +84,19 @@ case class WriteIntoPaimonTable(
     val commitMessages = writer.write(data)
     writer.commit(commitMessages)
 
-    markDoneIfNeeded(commitMessages)
+    preFinish(commitMessages)
     Seq.empty
   }
 
+  private def preFinish(commitMessages: Seq[CommitMessage]): Unit = {
+    val coreOptions = table.coreOptions();
+    if (coreOptions.tagCreationMode() == TagCreationMode.BATCH) {
+      val tagCreation = new TagBatchCreation(table)

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "Aitozi (via GitHub)" <gi...@apache.org>.
Aitozi commented on code in PR #5185:
URL: https://github.com/apache/paimon/pull/5185#discussion_r1974912194


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/WriteIntoPaimonTable.scala:
##########
@@ -83,10 +84,19 @@ case class WriteIntoPaimonTable(
     val commitMessages = writer.write(data)
     writer.commit(commitMessages)
 
-    markDoneIfNeeded(commitMessages)
+    preFinish(commitMessages)
     Seq.empty
   }
 
+  private def preFinish(commitMessages: Seq[CommitMessage]): Unit = {
+    val coreOptions = table.coreOptions();
+    if (coreOptions.tagCreationMode() == TagCreationMode.BATCH) {
+      val tagCreation = new TagBatchCreation(table)
+      tagCreation.createTag()
+    }
+    markDoneIfNeeded(commitMessages)
+  }
+
   private def markDoneIfNeeded(commitMessages: Seq[CommitMessage]): Unit = {
     val coreOptions = table.coreOptions()
     if (coreOptions.toConfiguration.get(CoreOptions.PARTITION_MARK_DONE_WHEN_END_INPUT)) {

Review Comment:
   this option is used several times, I think it's ok here



##########
paimon-core/src/main/java/org/apache/paimon/tag/TagBatchCreation.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.tag;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.operation.TagDeletion;
+import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.SnapshotManager;
+import org.apache.paimon.utils.TagManager;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/** Tag creation for batch mode. */
+public class TagBatchCreation {
+
+    private static final String BATCH_WRITE_TAG_PREFIX = "batch-write-";
+    private final FileStoreTable table;
+    private final CoreOptions options;
+    private final TagManager tagManager;
+    private final SnapshotManager snapshotManager;
+    private final TagDeletion tagDeletion;
+
+    public TagBatchCreation(FileStoreTable table) {
+        this.table = table;
+        this.snapshotManager = table.snapshotManager();
+        this.tagManager = table.tagManager();
+        this.tagDeletion = table.store().newTagDeletion();
+        this.options = table.coreOptions();
+    }
+
+    public void createTag() {
+        Snapshot snapshot = snapshotManager.latestSnapshot();
+        if (snapshot == null) {
+            return;
+        }
+        Instant instant = Instant.ofEpochMilli(snapshot.timeMillis());
+        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
+        String tagName =
+                options.tagBatchCustomizedName() != null
+                        ? options.tagBatchCustomizedName()
+                        : BATCH_WRITE_TAG_PREFIX
+                                + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        try {
+            // If the tag already exists, delete the tag
+            tagManager.deleteTag(
+                    tagName, tagDeletion, snapshotManager, table.store().createTagCallbacks());
+            // Create a new tag
+            tagManager.createTag(
+                    snapshot,
+                    tagName,
+                    table.coreOptions().tagDefaultTimeRetained(),
+                    table.store().createTagCallbacks(),
+                    false);
+            // Expire the tag
+            expireTag();
+        } catch (Exception e) {
+            if (tagManager.tagExists(tagName)) {
+                tagManager.deleteTag(
+                        tagName, tagDeletion, snapshotManager, table.store().createTagCallbacks());
+            }

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "LinMingQiang (via GitHub)" <gi...@apache.org>.
LinMingQiang commented on code in PR #5185:
URL: https://github.com/apache/paimon/pull/5185#discussion_r1974905954


##########
paimon-core/src/main/java/org/apache/paimon/tag/TagBatchCreation.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.tag;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.operation.TagDeletion;
+import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.SnapshotManager;
+import org.apache.paimon.utils.TagManager;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/** Tag creation for batch mode. */
+public class TagBatchCreation {
+
+    private static final String BATCH_WRITE_TAG_PREFIX = "batch-write-";
+    private final FileStoreTable table;
+    private final CoreOptions options;
+    private final TagManager tagManager;
+    private final SnapshotManager snapshotManager;
+    private final TagDeletion tagDeletion;
+
+    public TagBatchCreation(FileStoreTable table) {
+        this.table = table;
+        this.snapshotManager = table.snapshotManager();
+        this.tagManager = table.tagManager();
+        this.tagDeletion = table.store().newTagDeletion();
+        this.options = table.coreOptions();
+    }
+
+    public void createTag() {
+        Snapshot snapshot = snapshotManager.latestSnapshot();
+        if (snapshot == null) {
+            return;
+        }
+        Instant instant = Instant.ofEpochMilli(snapshot.timeMillis());
+        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
+        String tagName =
+                options.tagBatchCustomizedName() != null
+                        ? options.tagBatchCustomizedName()
+                        : BATCH_WRITE_TAG_PREFIX
+                                + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        try {
+            // If the tag already exists, delete the tag
+            tagManager.deleteTag(
+                    tagName, tagDeletion, snapshotManager, table.store().createTagCallbacks());
+            // Create a new tag
+            tagManager.createTag(
+                    snapshot,
+                    tagName,
+                    table.coreOptions().tagDefaultTimeRetained(),
+                    table.store().createTagCallbacks(),
+                    false);
+            // Expire the tag
+            expireTag();
+        } catch (Exception e) {
+            if (tagManager.tagExists(tagName)) {
+                tagManager.deleteTag(
+                        tagName, tagDeletion, snapshotManager, table.store().createTagCallbacks());
+            }

Review Comment:
   Waring-Logs should be printed here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "LinMingQiang (via GitHub)" <gi...@apache.org>.
LinMingQiang commented on code in PR #5185:
URL: https://github.com/apache/paimon/pull/5185#discussion_r1974903080


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/WriteIntoPaimonTable.scala:
##########
@@ -83,10 +84,19 @@ case class WriteIntoPaimonTable(
     val commitMessages = writer.write(data)
     writer.commit(commitMessages)
 
-    markDoneIfNeeded(commitMessages)
+    preFinish(commitMessages)
     Seq.empty
   }
 
+  private def preFinish(commitMessages: Seq[CommitMessage]): Unit = {
+    val coreOptions = table.coreOptions();
+    if (coreOptions.tagCreationMode() == TagCreationMode.BATCH) {
+      val tagCreation = new TagBatchCreation(table)
+      tagCreation.createTag()
+    }
+    markDoneIfNeeded(commitMessages)
+  }
+
   private def markDoneIfNeeded(commitMessages: Seq[CommitMessage]): Unit = {
     val coreOptions = table.coreOptions()
     if (coreOptions.toConfiguration.get(CoreOptions.PARTITION_MARK_DONE_WHEN_END_INPUT)) {

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "LinMingQiang (via GitHub)" <gi...@apache.org>.
LinMingQiang commented on PR #5185:
URL: https://github.com/apache/paimon/pull/5185#issuecomment-2689976479

   +1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #5185:
URL: https://github.com/apache/paimon/pull/5185


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "LinMingQiang (via GitHub)" <gi...@apache.org>.
LinMingQiang commented on code in PR #5185:
URL: https://github.com/apache/paimon/pull/5185#discussion_r1974902393


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/WriteIntoPaimonTable.scala:
##########
@@ -83,10 +84,19 @@ case class WriteIntoPaimonTable(
     val commitMessages = writer.write(data)
     writer.commit(commitMessages)
 
-    markDoneIfNeeded(commitMessages)
+    preFinish(commitMessages)
     Seq.empty
   }
 
+  private def preFinish(commitMessages: Seq[CommitMessage]): Unit = {
+    val coreOptions = table.coreOptions();
+    if (coreOptions.tagCreationMode() == TagCreationMode.BATCH) {
+      val tagCreation = new TagBatchCreation(table)

Review Comment:
   Maybe a little more concise : `if (table.coreOptions().tagCreationMode() == TagCreationMode.BATCH) `
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "LinMingQiang (via GitHub)" <gi...@apache.org>.
LinMingQiang commented on code in PR #5185:
URL: https://github.com/apache/paimon/pull/5185#discussion_r1974917434


##########
paimon-core/src/main/java/org/apache/paimon/tag/TagBatchCreation.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.tag;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.operation.TagDeletion;
+import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.SnapshotManager;
+import org.apache.paimon.utils.TagManager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/** Tag creation for batch mode. */
+public class TagBatchCreation {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TagBatchCreation.class);
+
+    private static final String BATCH_WRITE_TAG_PREFIX = "batch-write-";
+    private final FileStoreTable table;
+    private final CoreOptions options;
+    private final TagManager tagManager;
+    private final SnapshotManager snapshotManager;
+    private final TagDeletion tagDeletion;
+
+    public TagBatchCreation(FileStoreTable table) {
+        this.table = table;
+        this.snapshotManager = table.snapshotManager();
+        this.tagManager = table.tagManager();
+        this.tagDeletion = table.store().newTagDeletion();
+        this.options = table.coreOptions();
+    }
+
+    public void createTag() {
+        Snapshot snapshot = snapshotManager.latestSnapshot();
+        if (snapshot == null) {
+            return;
+        }
+        Instant instant = Instant.ofEpochMilli(snapshot.timeMillis());
+        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
+        String tagName =
+                options.tagBatchCustomizedName() != null
+                        ? options.tagBatchCustomizedName()
+                        : BATCH_WRITE_TAG_PREFIX
+                                + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        try {
+            // If the tag already exists, delete the tag
+            tagManager.deleteTag(
+                    tagName, tagDeletion, snapshotManager, table.store().createTagCallbacks());
+            // Create a new tag
+            tagManager.createTag(
+                    snapshot,
+                    tagName,
+                    table.coreOptions().tagDefaultTimeRetained(),
+                    table.store().createTagCallbacks(),
+                    false);
+        } catch (Exception e) {
+            LOG.warn("Failed to create tag", e);

Review Comment:
   Suggestion : `Failed to create tag '${tagname}' from '${snapshot}', you can create this tag manually.`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Enable TagCreationMode#batch for spark writer [paimon]

Posted by "LinMingQiang (via GitHub)" <gi...@apache.org>.
LinMingQiang commented on code in PR #5185:
URL: https://github.com/apache/paimon/pull/5185#discussion_r1974914356


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/WriteIntoPaimonTable.scala:
##########
@@ -83,10 +84,19 @@ case class WriteIntoPaimonTable(
     val commitMessages = writer.write(data)
     writer.commit(commitMessages)
 
-    markDoneIfNeeded(commitMessages)
+    preFinish(commitMessages)
     Seq.empty
   }
 
+  private def preFinish(commitMessages: Seq[CommitMessage]): Unit = {
+    val coreOptions = table.coreOptions();
+    if (coreOptions.tagCreationMode() == TagCreationMode.BATCH) {
+      val tagCreation = new TagBatchCreation(table)
+      tagCreation.createTag()
+    }
+    markDoneIfNeeded(commitMessages)
+  }
+
   private def markDoneIfNeeded(commitMessages: Seq[CommitMessage]): Unit = {
     val coreOptions = table.coreOptions()
     if (coreOptions.toConfiguration.get(CoreOptions.PARTITION_MARK_DONE_WHEN_END_INPUT)) {

Review Comment:
   My mistake.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org