n3nash commented on a change in pull request #2263:
URL: https://github.com/apache/hudi/pull/2263#discussion_r533653930



##########
File path: 
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/RDDCustomColumnsSortPartitioner.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.table.BulkInsertPartitioner;
+import org.apache.spark.api.java.JavaRDD;
+
+/**
+ * A partitioner that does sorting based on specified column values for each 
RDD partition.
+ *
+ * @param <T> HoodieRecordPayload type
+ */
+public class RDDCustomColumnsSortPartitioner<T extends HoodieRecordPayload>
+    implements BulkInsertPartitioner<JavaRDD<HoodieRecord<T>>> {
+
+  private final String[] sortColumnNames;
+  private final String schemaString;
+
+  public RDDCustomColumnsSortPartitioner(String[] columnNames, Schema schema) {
+    this.sortColumnNames = columnNames;
+    //TODO Schema is not serializable. So convert to String here. Figure out 
how to improve this
+    this.schemaString = schema.toString();
+  }
+
+  @Override
+  public JavaRDD<HoodieRecord<T>> repartitionRecords(JavaRDD<HoodieRecord<T>> 
records,
+                                                     int 
outputSparkPartitions) {
+    final String[] sortColumns = this.sortColumnNames;
+    final String schemaStr = this.schemaString;
+    return records.sortBy(record -> {

Review comment:
       I have a suggestion to change the way we are generating the sort cols. 
Instead of performing this operation during write where the following code will 
spend cycles to convert data to generic record again, can we do this during 
read time when the HoodieRecord is being constructed ? I think you are using 
HoodieFileSliceReader and HoodieMergedRecordScanner to do this, does it make 
sense to add a sortKey to HoodieRecord and when you are constructing the hoodie 
record where you anyways have a handle to the generic record, you can just set 
that value in the hoodie record ? 
   The downside of this approach is that the RDD bloats up so the shuffle will 
be larger so the question is whether that's worse or converting to generic 
record is worse from a CPU perspective 




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to