yihua commented on code in PR #12772:
URL: https://github.com/apache/hudi/pull/12772#discussion_r2074111541
##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/DefaultSparkRecordMerger.java:
##########
@@ -73,7 +75,7 @@ public Option<Pair<HoodieRecord, Schema>> merge(HoodieRecord
older, Schema oldSc
return Option.of(Pair.of(newer, newSchema));
}
}
- if (older.getOrderingValue(oldSchema,
props).compareTo(newer.getOrderingValue(newSchema, props)) > 0) {
+ if (compareValues(older.getOrderingValue(oldSchema, props),
newer.getOrderingValue(newSchema, props)) > 0) {
Review Comment:
The ordering value of primitive types is supported only. It's not necessary
to use Spark adapter. Let's revert the change. If this is for new variant
type, let's thrown an error for such a type if used as an ordering/precombine
field in this PR.
##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/common/util/SparkSortUtils.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.common.util;
+
+import org.apache.hudi.SparkAdapterSupport$;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.collection.FlatLists;
+
+import org.apache.avro.Schema;
+
+import static org.apache.hudi.common.util.SortUtils.prependPartitionPath;
+import static
org.apache.hudi.common.util.SortUtils.prependPartitionPathAndSuffixRecordKey;
+
+/**
+ * Utility functions used by BULK_INSERT practitioners while sorting records.
+ */
+public class SparkSortUtils {
+ /**
+ * Given a hoodie record, returns a comparable list of sorted columns.
+ *
+ * @param record HoodieRecord (Spark or Avro)
+ * @param sortColumnNames user provided sort columns
+ * @param schema schema for table
+ * @param suffixRecordKey
HoodieWriteConfig.BULKINSERT_SUFFIX_RECORD_KEY_SORT_COLUMNS
+ * @param consistentLogicalTimestampEnabled
KeyGeneratorOptions.KEYGENERATOR_CONSISTENT_LOGICAL_TIMESTAMP_ENABLED
+ */
+ public static FlatLists.ComparableList<Comparable<HoodieRecord<?>>>
getComparableSortColumns(
Review Comment:
`#getComparableSortColumns` and `#compareValues` do not have
version-divergent logic across Spark versions (between Spark 3 and 4). If
there is, the logic should be incorporated into the `InternalRow` or
`HoodieSparkRecord` abstraction, instead of wrapping the logic with utils which
makes it hard to understand. Let's revert the changes on these two methods?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]