You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/05/05 06:51:02 UTC

[GitHub] [hudi] boneanxs opened a new pull request, #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

boneanxs opened a new pull request, #5502:
URL: https://github.com/apache/hudi/pull/5502

   ## *Tips*
   - *Thank you very much for contributing to Apache Hudi.*
   - *Please review https://hudi.apache.org/contribute/how-to-contribute before opening a pull request.*
   
   ## What is the purpose of the pull request
   
   like RDDCustomColumnsSortPartitioner, we can use this partitioner to sort customer columns users specified.
   for example:
   
   ```scala
   df.write.format("hudi")
   .option(HoodieWriteConfig.TABLE_NAME, "test_table")
   .option(OPERATION.key, DataSourceWriteOptions.BULK_INSERT_OPERATION_OPT_VAL)
   .option(RECORDKEY_FIELD.key, "session_id")
   .option(PARTITIONPATH_FIELD.key, "date")
   .option("hoodie.bulkinsert.user.defined.partitioner.class", "org.apache.hudi.execution.bulkinsert.CustomColumnsSortPartitionerWithRows")
   .option("hoodie.bulkinsert.user.defined.partitioner.sort.columns", "page_type")
   .mode(SaveMode.Append)
   .save("hdfs://test/test_table")
   ```
   
   ## Brief change log
   
   *(for example:)*
     - *Modify AnnotationLocation checkstyle rule in checkstyle.xml*
   
   ## Verify this pull request
   
   *(Please pick either of the following options)*
   
   This pull request is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This pull request is already covered by existing tests, such as *(please describe tests)*.
   
   (or)
   
   This change added tests and can be verified as follows:
   
   *(example:)*
   
     - *Added integration tests for end-to-end.*
     - *Added HoodieClientWriteTest to verify the change.*
     - *Manually verified the change by running a job locally.*
   
   ## Committer checklist
   
    - [ ] Has a corresponding JIRA in PR title & commit
    
    - [ ] Commit message is descriptive of the change
    
    - [ ] CI is green
   
    - [ ] Necessary doc changes done or have another open PR
          
    - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.
   


-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] codope commented on a diff in pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
codope commented on code in PR #5502:
URL: https://github.com/apache/hudi/pull/5502#discussion_r880032515


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/CustomColumnsSortPartitionerWithRows.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.hudi.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.BulkInsertPartitioner;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+
+import java.util.Arrays;
+
+/**
+ * A partitioner that does sorting based on specified column values for each spark partitions.
+ */
+public class CustomColumnsSortPartitionerWithRows implements BulkInsertPartitioner<Dataset<Row>> {

Review Comment:
   Rename to `RowCustomColumnsSortPartitioner` to be consistent with `RDDCustomColumnsSortPartitioner`?



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/CustomColumnsSortPartitionerWithRows.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.hudi.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.BulkInsertPartitioner;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+
+import java.util.Arrays;
+
+/**
+ * A partitioner that does sorting based on specified column values for each spark partitions.
+ */
+public class CustomColumnsSortPartitionerWithRows implements BulkInsertPartitioner<Dataset<Row>> {
+
+  private final String[] sortColumnNames;
+
+  public CustomColumnsSortPartitionerWithRows(HoodieWriteConfig config) {
+    this.sortColumnNames = getSortColumnName(config);
+  }
+
+  public CustomColumnsSortPartitionerWithRows(String[] columnNames) {
+    this.sortColumnNames = columnNames;
+  }
+
+  @Override
+  public Dataset<Row> repartitionRecords(Dataset<Row> records, int outputSparkPartitions) {
+    final String[] sortColumns = this.sortColumnNames;
+    return records.coalesce(outputSparkPartitions)

Review Comment:
   Does it handle null values?



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/CustomColumnsSortPartitionerWithRows.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.hudi.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.BulkInsertPartitioner;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+
+import java.util.Arrays;
+
+/**
+ * A partitioner that does sorting based on specified column values for each spark partitions.
+ */
+public class CustomColumnsSortPartitionerWithRows implements BulkInsertPartitioner<Dataset<Row>> {
+
+  private final String[] sortColumnNames;
+
+  public CustomColumnsSortPartitionerWithRows(HoodieWriteConfig config) {
+    this.sortColumnNames = getSortColumnName(config);
+  }
+
+  public CustomColumnsSortPartitionerWithRows(String[] columnNames) {
+    this.sortColumnNames = columnNames;
+  }
+
+  @Override
+  public Dataset<Row> repartitionRecords(Dataset<Row> records, int outputSparkPartitions) {
+    final String[] sortColumns = this.sortColumnNames;
+    return records.coalesce(outputSparkPartitions)
+        .sortWithinPartitions(HoodieRecord.PARTITION_PATH_METADATA_FIELD, sortColumns);
+  }
+
+  @Override
+  public boolean arePartitionRecordsSorted() {
+    return true;
+  }
+
+  private String[] getSortColumnName(HoodieWriteConfig config) {
+    return Arrays.stream(config.getUserDefinedBulkInsertPartitionerSortColumns().split(","))
+        .map(String::trim).toArray(String[]::new);

Review Comment:
   I think would be good to do this change (esp the trim) in `RDDCustomColumnsSortPartitioner`?



-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] boneanxs commented on a diff in pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
boneanxs commented on code in PR #5502:
URL: https://github.com/apache/hudi/pull/5502#discussion_r881177283


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/CustomColumnsSortPartitionerWithRows.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.hudi.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.BulkInsertPartitioner;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+
+import java.util.Arrays;
+
+/**
+ * A partitioner that does sorting based on specified column values for each spark partitions.
+ */
+public class CustomColumnsSortPartitionerWithRows implements BulkInsertPartitioner<Dataset<Row>> {
+
+  private final String[] sortColumnNames;
+
+  public CustomColumnsSortPartitionerWithRows(HoodieWriteConfig config) {
+    this.sortColumnNames = getSortColumnName(config);
+  }
+
+  public CustomColumnsSortPartitionerWithRows(String[] columnNames) {
+    this.sortColumnNames = columnNames;
+  }
+
+  @Override
+  public Dataset<Row> repartitionRecords(Dataset<Row> records, int outputSparkPartitions) {
+    final String[] sortColumns = this.sortColumnNames;
+    return records.coalesce(outputSparkPartitions)

Review Comment:
   Yes, it support null values:
   
   ```scala
   scala> val df1 = Seq(("foo", "test"), ("bar", null), ("foo", "test1"), ("bar", "test")).toDF("k", "v")
   df1: org.apache.spark.sql.DataFrame = [k: string, v: string]
   
   scala> df1.coalesce(1).sortWithinPartitions("k", "v").collect
   res8: Array[org.apache.spark.sql.Row] = Array([bar,null], [bar,test], [foo,test], [foo,test1])
   
   scala> val df2 = Seq((null, "test"), ("bar", null), ("foo", "test1"), ("bar", "test")).toDF("k", "v")
   df2: org.apache.spark.sql.DataFrame = [k: string, v: string]
   
   scala> df2.coalesce(1).sortWithinPartitions("k", "v").collect
   res9: Array[org.apache.spark.sql.Row] = Array([null,test], [bar,null], [bar,test], [foo,test1])
   ```



-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] hudi-bot commented on pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
hudi-bot commented on PR #5502:
URL: https://github.com/apache/hudi/pull/5502#issuecomment-1118399010

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438",
       "triggerID" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9 Azure: [SUCCESS](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] hudi-bot commented on pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
hudi-bot commented on PR #5502:
URL: https://github.com/apache/hudi/pull/5502#issuecomment-1136754239

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438",
       "triggerID" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "triggerType" : "PUSH"
     }, {
       "hash" : "abc9efbeb629e712842e208977a1666a265b4c2a",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8909",
       "triggerID" : "abc9efbeb629e712842e208977a1666a265b4c2a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * abc9efbeb629e712842e208977a1666a265b4c2a Azure: [SUCCESS](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8909) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] codope merged pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
codope merged PR #5502:
URL: https://github.com/apache/hudi/pull/5502


-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] hudi-bot commented on pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
hudi-bot commented on PR #5502:
URL: https://github.com/apache/hudi/pull/5502#issuecomment-1136694689

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438",
       "triggerID" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "triggerType" : "PUSH"
     }, {
       "hash" : "abc9efbeb629e712842e208977a1666a265b4c2a",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8909",
       "triggerID" : "abc9efbeb629e712842e208977a1666a265b4c2a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9 Azure: [SUCCESS](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438) 
   * abc9efbeb629e712842e208977a1666a265b4c2a Azure: [PENDING](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8909) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] hudi-bot commented on pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
hudi-bot commented on PR #5502:
URL: https://github.com/apache/hudi/pull/5502#issuecomment-1118254354

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438",
       "triggerID" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9 Azure: [PENDING](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] hudi-bot commented on pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
hudi-bot commented on PR #5502:
URL: https://github.com/apache/hudi/pull/5502#issuecomment-1118251998

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] boneanxs commented on a diff in pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
boneanxs commented on code in PR #5502:
URL: https://github.com/apache/hudi/pull/5502#discussion_r881254024


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/CustomColumnsSortPartitionerWithRows.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.hudi.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.BulkInsertPartitioner;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+
+import java.util.Arrays;
+
+/**
+ * A partitioner that does sorting based on specified column values for each spark partitions.
+ */
+public class CustomColumnsSortPartitionerWithRows implements BulkInsertPartitioner<Dataset<Row>> {
+
+  private final String[] sortColumnNames;
+
+  public CustomColumnsSortPartitionerWithRows(HoodieWriteConfig config) {
+    this.sortColumnNames = getSortColumnName(config);
+  }
+
+  public CustomColumnsSortPartitionerWithRows(String[] columnNames) {
+    this.sortColumnNames = columnNames;
+  }
+
+  @Override
+  public Dataset<Row> repartitionRecords(Dataset<Row> records, int outputSparkPartitions) {
+    final String[] sortColumns = this.sortColumnNames;
+    return records.coalesce(outputSparkPartitions)
+        .sortWithinPartitions(HoodieRecord.PARTITION_PATH_METADATA_FIELD, sortColumns);
+  }
+
+  @Override
+  public boolean arePartitionRecordsSorted() {
+    return true;
+  }
+
+  private String[] getSortColumnName(HoodieWriteConfig config) {
+    return Arrays.stream(config.getUserDefinedBulkInsertPartitionerSortColumns().split(","))
+        .map(String::trim).toArray(String[]::new);

Review Comment:
   done



-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] hudi-bot commented on pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
hudi-bot commented on PR #5502:
URL: https://github.com/apache/hudi/pull/5502#issuecomment-1136693309

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438",
       "triggerID" : "0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9",
       "triggerType" : "PUSH"
     }, {
       "hash" : "abc9efbeb629e712842e208977a1666a265b4c2a",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "abc9efbeb629e712842e208977a1666a265b4c2a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0e41e6e83512a3a8bc57a0f7b70b0c4fc0fbe2f9 Azure: [SUCCESS](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=8438) 
   * abc9efbeb629e712842e208977a1666a265b4c2a UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

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


[GitHub] [hudi] boneanxs commented on a diff in pull request #5502: [HUDI-4040]Bulk insert: Add customColumnsSortpartitionerWithRows

Posted by GitBox <gi...@apache.org>.
boneanxs commented on code in PR #5502:
URL: https://github.com/apache/hudi/pull/5502#discussion_r881177283


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/CustomColumnsSortPartitionerWithRows.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.hudi.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.BulkInsertPartitioner;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+
+import java.util.Arrays;
+
+/**
+ * A partitioner that does sorting based on specified column values for each spark partitions.
+ */
+public class CustomColumnsSortPartitionerWithRows implements BulkInsertPartitioner<Dataset<Row>> {
+
+  private final String[] sortColumnNames;
+
+  public CustomColumnsSortPartitionerWithRows(HoodieWriteConfig config) {
+    this.sortColumnNames = getSortColumnName(config);
+  }
+
+  public CustomColumnsSortPartitionerWithRows(String[] columnNames) {
+    this.sortColumnNames = columnNames;
+  }
+
+  @Override
+  public Dataset<Row> repartitionRecords(Dataset<Row> records, int outputSparkPartitions) {
+    final String[] sortColumns = this.sortColumnNames;
+    return records.coalesce(outputSparkPartitions)

Review Comment:
   Yes, it support null values:
   
   ```scala
   scala> val df1 = Seq(("foo", "test"), ("bar", null), ("foo", "test1"), ("bar", "test")).toDF("k", "v")
   df1: org.apache.spark.sql.DataFrame = [k: string, v: string]
   
   scala> df1.coalesce(1).sortWithinPartitions("k", "v").collect
   res8: Array[org.apache.spark.sql.Row] = Array([bar,null], [bar,test], [foo,test], [foo,test1])
   ```



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/CustomColumnsSortPartitionerWithRows.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.hudi.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.BulkInsertPartitioner;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+
+import java.util.Arrays;
+
+/**
+ * A partitioner that does sorting based on specified column values for each spark partitions.
+ */
+public class CustomColumnsSortPartitionerWithRows implements BulkInsertPartitioner<Dataset<Row>> {
+
+  private final String[] sortColumnNames;
+
+  public CustomColumnsSortPartitionerWithRows(HoodieWriteConfig config) {
+    this.sortColumnNames = getSortColumnName(config);
+  }
+
+  public CustomColumnsSortPartitionerWithRows(String[] columnNames) {
+    this.sortColumnNames = columnNames;
+  }
+
+  @Override
+  public Dataset<Row> repartitionRecords(Dataset<Row> records, int outputSparkPartitions) {
+    final String[] sortColumns = this.sortColumnNames;
+    return records.coalesce(outputSparkPartitions)

Review Comment:
   Yes, it support null values:
   
   ```scala
   scala> val df1 = Seq(("foo", "test"), ("bar", null), ("foo", "test1"), ("bar", "test")).toDF("k", "v")
   df1: org.apache.spark.sql.DataFrame = [k: string, v: string]
   
   scala> df1.coalesce(1).sortWithinPartitions("k", "v").collect
   res8: Array[org.apache.spark.sql.Row] = Array([bar,null], [bar,test], [foo,test], [foo,test1])
   ```



-- 
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: commits-unsubscribe@hudi.apache.org

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