You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "xuzifu666 (via GitHub)" <gi...@apache.org> on 2024/07/13 12:03:26 UTC

[PR] [spark] Support MarkPartitionDoneProcedure in Spark [paimon]

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

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   Support MarkPartitionDoneProcedure in Spark
   
   <!-- Linking this pull request to the issue -->
   Linked issue: close #xxx
   
   <!-- 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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/partition/actions/PartitionMarkDoneAction.java:
##########
@@ -16,31 +16,38 @@
  * limitations under the License.
  */
 
-package org.apache.paimon.flink.sink.partition;
+package org.apache.paimon.partition.actions;
 
 import org.apache.paimon.CoreOptions;
 import org.apache.paimon.metastore.MetastoreClient;
 import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.StringUtils;
 
 import java.io.Closeable;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
 import static org.apache.paimon.CoreOptions.METASTORE_PARTITIONED_TABLE;
-import static org.apache.paimon.flink.FlinkConnectorOptions.PARTITION_MARK_DONE_ACTION;
 import static org.apache.paimon.utils.Preconditions.checkArgument;
 import static org.apache.paimon.utils.Preconditions.checkNotNull;
 
 /** Action to mark partitions done. */
 public interface PartitionMarkDoneAction extends Closeable {
 
+    String PARTITION_MARK_DONE_ACTION = "partition.mark-done-action";
+    String DEFAULT_MARK_DONE_ACTION = "success-file";
+
     void markDone(String partition) throws Exception;
 
     static List<PartitionMarkDoneAction> createActions(
             FileStoreTable fileStoreTable, CoreOptions options) {
-        return Arrays.asList(options.toConfiguration().get(PARTITION_MARK_DONE_ACTION).split(","))
-                .stream()
+        String markdoneAction =
+                StringUtils.isBlank((options.toConfiguration().get(PARTITION_MARK_DONE_ACTION)))

Review Comment:
   Because in Flink handle logic would process in default value in PARTITION_MARK_DONE_ACTION conf if it is not set,but the config is in Flink module not in core or spark moudle,so keep the common logic like this way.



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/actions/AddDonePartitionAction.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.actions;
+
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.metastore.MetastoreClient;
+
+import org.apache.paimon.shade.guava30.com.google.common.collect.Iterators;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.apache.paimon.utils.PartitionPathUtils.extractPartitionSpecFromPath;
+
+/** A {@link PartitionMarkDoneAction} which add ".done" partition. */
+public class AddDonePartitionAction implements PartitionMarkDoneAction {

Review Comment:
   Please reuse classed in Flink. You should move classes to core and reuse them.



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/MarkPartitionDoneProcedure.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.paimon.CoreOptions;
+import org.apache.paimon.partition.actions.AddDonePartitionAction;
+import org.apache.paimon.partition.actions.MarkPartitionDoneEventAction;
+import org.apache.paimon.partition.actions.PartitionMarkDoneAction;
+import org.apache.paimon.partition.actions.SuccessFileMarkDoneAction;
+import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.IOUtils;
+import org.apache.paimon.utils.PartitionPathUtils;
+
+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 java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.apache.paimon.partition.actions.PartitionMarkDoneAction.createMetastoreClient;
+import static org.apache.paimon.utils.ParameterUtils.getPartitions;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.spark.sql.types.DataTypes.StringType;
+
+/**
+ * Partition mark done procedure. Usage:
+ *
+ * <pre><code>
+ *  CALL sys.mark_partition_done('tableId', 'partition1;partition2')
+ * </code></pre>
+ */
+public class MarkPartitionDoneProcedure extends BaseProcedure {
+
+    private static final ProcedureParameter[] PARAMETERS =
+            new ProcedureParameter[] {
+                ProcedureParameter.required("table", StringType),
+                ProcedureParameter.required("partitions", StringType)
+            };
+
+    @Override
+    public ProcedureParameter[] parameters() {
+        return PARAMETERS;
+    }
+
+    @Override
+    public StructType outputType() {
+        return OUTPUT_TYPE;
+    }
+
+    private static final StructType OUTPUT_TYPE =
+            new StructType(
+                    new StructField[] {
+                        new StructField("result", DataTypes.BooleanType, true, Metadata.empty())
+                    });
+
+    protected MarkPartitionDoneProcedure(TableCatalog tableCatalog) {
+        super(tableCatalog);
+    }
+
+    @Override
+    public InternalRow[] call(InternalRow args) {
+        Identifier tableIdent = toIdentifier(args.getString(0), PARAMETERS[0].name());
+        String partitionStr = args.getString(1);
+        String[] partitions = partitionStr.split(";");
+
+        return modifyPaimonTable(
+                tableIdent,
+                table -> {
+                    checkArgument(
+                            table instanceof FileStoreTable,
+                            "Only FileStoreTable supports mark_partition_done procedure. The table type is '%s'.",
+                            table.getClass().getName());
+
+                    FileStoreTable fileStoreTable = (FileStoreTable) table;
+                    CoreOptions coreOptions = fileStoreTable.coreOptions();
+                    List<PartitionMarkDoneAction> actions =
+                            PartitionMarkDoneAction.createActions(fileStoreTable, coreOptions);
+
+                    List<String> partitionPaths =
+                            PartitionPathUtils.generatePartitionPaths(
+                                    getPartitions(partitions),
+                                    fileStoreTable.store().partitionType());
+
+                    markDone(partitionPaths, actions);
+
+                    IOUtils.closeAllQuietly(actions);
+                    InternalRow outputRow = newInternalRow(true);
+                    return new InternalRow[] {outputRow};
+                });
+    }
+
+    public static void markDone(List<String> partitions, List<PartitionMarkDoneAction> actions) {
+        for (String partition : partitions) {
+            try {
+                for (PartitionMarkDoneAction action : actions) {
+                    action.markDone(partition);
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    static List<PartitionMarkDoneAction> createActions(
+            FileStoreTable fileStoreTable, CoreOptions options) {
+        return Arrays.asList(

Review Comment:
   Please reuse method too.



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/partition/actions/PartitionMarkDoneAction.java:
##########
@@ -16,31 +16,38 @@
  * limitations under the License.
  */
 
-package org.apache.paimon.flink.sink.partition;
+package org.apache.paimon.partition.actions;
 
 import org.apache.paimon.CoreOptions;
 import org.apache.paimon.metastore.MetastoreClient;
 import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.StringUtils;
 
 import java.io.Closeable;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
 import static org.apache.paimon.CoreOptions.METASTORE_PARTITIONED_TABLE;
-import static org.apache.paimon.flink.FlinkConnectorOptions.PARTITION_MARK_DONE_ACTION;
 import static org.apache.paimon.utils.Preconditions.checkArgument;
 import static org.apache.paimon.utils.Preconditions.checkNotNull;
 
 /** Action to mark partitions done. */
 public interface PartitionMarkDoneAction extends Closeable {
 
+    String PARTITION_MARK_DONE_ACTION = "partition.mark-done-action";
+    String DEFAULT_MARK_DONE_ACTION = "success-file";
+
     void markDone(String partition) throws Exception;
 
     static List<PartitionMarkDoneAction> createActions(
             FileStoreTable fileStoreTable, CoreOptions options) {
-        return Arrays.asList(options.toConfiguration().get(PARTITION_MARK_DONE_ACTION).split(","))
-                .stream()
+        String markdoneAction =
+                StringUtils.isBlank((options.toConfiguration().get(PARTITION_MARK_DONE_ACTION)))

Review Comment:
   Why we need to handle blank?



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-common/src/main/java/org/apache/paimon/CoreOptions.java:
##########
@@ -1028,6 +1028,25 @@ public class CoreOptions implements Serializable {
                             "Parameter string for the constructor of class #. "
                                     + "Callback class should parse the parameter by itself.");
 
+    public static final ConfigOption<String> PARTITION_MARK_DONE_ACTION =

Review Comment:
   OK,would move it to core_configuration.html



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/partition/actions/PartitionMarkDoneAction.java:
##########
@@ -16,31 +16,38 @@
  * limitations under the License.
  */
 
-package org.apache.paimon.flink.sink.partition;
+package org.apache.paimon.partition.actions;
 
 import org.apache.paimon.CoreOptions;
 import org.apache.paimon.metastore.MetastoreClient;
 import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.StringUtils;
 
 import java.io.Closeable;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
 import static org.apache.paimon.CoreOptions.METASTORE_PARTITIONED_TABLE;
-import static org.apache.paimon.flink.FlinkConnectorOptions.PARTITION_MARK_DONE_ACTION;
 import static org.apache.paimon.utils.Preconditions.checkArgument;
 import static org.apache.paimon.utils.Preconditions.checkNotNull;
 
 /** Action to mark partitions done. */
 public interface PartitionMarkDoneAction extends Closeable {
 
+    String PARTITION_MARK_DONE_ACTION = "partition.mark-done-action";
+    String DEFAULT_MARK_DONE_ACTION = "success-file";
+
     void markDone(String partition) throws Exception;
 
     static List<PartitionMarkDoneAction> createActions(
             FileStoreTable fileStoreTable, CoreOptions options) {
-        return Arrays.asList(options.toConfiguration().get(PARTITION_MARK_DONE_ACTION).split(","))
-                .stream()
+        String markdoneAction =
+                StringUtils.isBlank((options.toConfiguration().get(PARTITION_MARK_DONE_ACTION)))

Review Comment:
   Move PARTITION_MARK_DONE_ACTION from FlinkConnectorOptions to CoreOptions for flink and spark modules.



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-common/src/main/java/org/apache/paimon/CoreOptions.java:
##########
@@ -1028,6 +1028,25 @@ public class CoreOptions implements Serializable {
                             "Parameter string for the constructor of class #. "
                                     + "Callback class should parse the parameter by itself.");
 
+    public static final ConfigOption<String> PARTITION_MARK_DONE_ACTION =

Review Comment:
   OK,had move it from flink_connector_configuration.html  to core_configuration.html @JingsongLi 



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/partition/actions/PartitionMarkDoneAction.java:
##########
@@ -16,31 +16,38 @@
  * limitations under the License.
  */
 
-package org.apache.paimon.flink.sink.partition;
+package org.apache.paimon.partition.actions;
 
 import org.apache.paimon.CoreOptions;
 import org.apache.paimon.metastore.MetastoreClient;
 import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.StringUtils;
 
 import java.io.Closeable;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
 import static org.apache.paimon.CoreOptions.METASTORE_PARTITIONED_TABLE;
-import static org.apache.paimon.flink.FlinkConnectorOptions.PARTITION_MARK_DONE_ACTION;
 import static org.apache.paimon.utils.Preconditions.checkArgument;
 import static org.apache.paimon.utils.Preconditions.checkNotNull;
 
 /** Action to mark partitions done. */
 public interface PartitionMarkDoneAction extends Closeable {
 
+    String PARTITION_MARK_DONE_ACTION = "partition.mark-done-action";
+    String DEFAULT_MARK_DONE_ACTION = "success-file";
+
     void markDone(String partition) throws Exception;
 
     static List<PartitionMarkDoneAction> createActions(
             FileStoreTable fileStoreTable, CoreOptions options) {
-        return Arrays.asList(options.toConfiguration().get(PARTITION_MARK_DONE_ACTION).split(","))
-                .stream()
+        String markdoneAction =
+                StringUtils.isBlank((options.toConfiguration().get(PARTITION_MARK_DONE_ACTION)))

Review Comment:
   Because in Flink handle logic would process in default value in PARTITION_MARK_DONE_ACTION conf if it is not set,but the config is in Flink module not in core or spark moudle,so keep the common logic like this way to avoid NPE in flink ut.



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/actions/AddDonePartitionAction.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.actions;
+
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.metastore.MetastoreClient;
+
+import org.apache.paimon.shade.guava30.com.google.common.collect.Iterators;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.apache.paimon.utils.PartitionPathUtils.extractPartitionSpecFromPath;
+
+/** A {@link PartitionMarkDoneAction} which add ".done" partition. */
+public class AddDonePartitionAction implements PartitionMarkDoneAction {

Review Comment:
   OK,would change it as the advice. Thanks @JingsongLi 



-- 
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] Support MarkPartitionDoneProcedure in Spark [paimon]

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


##########
paimon-common/src/main/java/org/apache/paimon/CoreOptions.java:
##########
@@ -1028,6 +1028,25 @@ public class CoreOptions implements Serializable {
                             "Parameter string for the constructor of class #. "
                                     + "Callback class should parse the parameter by itself.");
 
+    public static final ConfigOption<String> PARTITION_MARK_DONE_ACTION =

Review Comment:
   Regenerate doc?



-- 
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