PavithranRick commented on code in PR #17604:
URL: https://github.com/apache/hudi/pull/17604#discussion_r2734424406
##########
hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/HiveRecordContext.java:
##########
@@ -97,16 +104,41 @@ public HoodieRecord<ArrayWritable>
constructHoodieRecord(BufferedRecord<ArrayWri
@Override
public ArrayWritable constructEngineRecord(HoodieSchema recordSchema,
Object[] fieldValues) {
- return new ArrayWritable(Writable.class, (Writable[]) fieldValues);
+ Schema avroSchema = recordSchema.toAvroSchema();
+ List<Schema.Field> fields = avroSchema.getFields();
+ if (fields.size() != fieldValues.length) {
+ throw new IllegalArgumentException("Mismatch between schema fields and
values");
+ }
+
+ Writable[] writables = new Writable[fields.size()];
+ for (int i = 0; i < fields.size(); i++) {
+ Schema fieldSchema = resolveUnion(fields.get(i).schema());
+ writables[i] = convertToWritable(fieldSchema, fieldValues[i]);
+ }
+ return new ArrayWritable(Writable.class, writables);
}
@Override
public ArrayWritable mergeWithEngineRecord(HoodieSchema schema,
Map<Integer, Object> updateValues,
BufferedRecord<ArrayWritable>
baseRecord) {
Writable[] engineRecord = baseRecord.getRecord().get();
+ Schema avroSchema = schema.toAvroSchema();
+ List<Schema.Field> fields = avroSchema.getFields();
for (Map.Entry<Integer, Object> value : updateValues.entrySet()) {
- engineRecord[value.getKey()] = (Writable) value.getValue();
+ int pos = value.getKey();
+ Object updateValue = value.getValue();
+
+ // If value is already a Writable, use it directly
+ if (updateValue instanceof Writable) {
Review Comment:
Yes in this file.
hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/TestHiveHoodieReaderContext.java
--
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]