vinothchandar commented on code in PR #13686:
URL: https://github.com/apache/hudi/pull/13686#discussion_r2263221341


##########
hudi-common/src/main/java/org/apache/hudi/common/model/SerializableIndexedRecord.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.model;
+
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.exception.HoodieIOException;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.KryoSerializable;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+
+import java.io.IOException;
+import java.util.Objects;
+
+/**
+ * Wrapper class for {@link IndexedRecord} that will serialize the record as 
bytes without the schema for efficient shuffling performance in Spark.
+ * After deserialization, the schema can be set using {@link 
#decodeRecord(Schema)} and that will also trigger deserialization of the record.
+ * This allows the record to stay in the serialized form until the data needs 
to be accessed, which allows deserialization to be avoided if data is not read.
+ */
+class SerializableIndexedRecord implements IndexedRecord, GenericRecord, 
KryoSerializable {
+  private IndexedRecord record;
+  private byte[] recordBytes;
+
+  static SerializableIndexedRecord createInstance(IndexedRecord record) {
+    return record == null ? null : new SerializableIndexedRecord(record);
+  }
+
+  private SerializableIndexedRecord(IndexedRecord record) {
+    this.record = record;
+  }
+
+  @Override
+  public void put(int i, Object v) {
+    record.put(i, v);
+  }
+
+  @Override
+  public Object get(int i) {
+    return record.get(i);
+  }
+
+  @Override
+  public Schema getSchema() {
+    return record.getSchema();
+  }
+
+  private byte[] encodeRecord() {
+    if (recordBytes == null) {
+      recordBytes = HoodieAvroUtils.avroToBytes(record);
+    }
+    return recordBytes;
+  }
+
+  void decodeRecord(Schema schema) {
+    if (record == null) {
+      try {
+        record = HoodieAvroUtils.bytesToAvro(recordBytes, schema);

Review Comment:
   yep. But, most stages don't decode the `recordBytes` again though? e.g. 
indexing, precombine, workload profile - all works off the `HoodieRecord` 
fields.. 
   
   So, if decoding only happens in write handles for e.g, it may be good to 
nullify to reduce memory pressure. (not have both avro and bytes in a spillable 
map) .. Can we do an analysis around this and close this out?



-- 
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-unsubscr...@hudi.apache.org

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

Reply via email to