linliu-code commented on code in PR #13972:
URL: https://github.com/apache/hudi/pull/13972#discussion_r2375741141


##########
hudi-common/src/main/java/org/apache/hudi/common/util/DeserializationUtils.java:
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.avro.model.HoodieActionInstant;
+import org.apache.hudi.avro.model.HoodieBootstrapFilePartitionInfo;
+import org.apache.hudi.avro.model.HoodieBootstrapIndexInfo;
+import org.apache.hudi.avro.model.HoodieBootstrapPartitionMetadata;
+import org.apache.hudi.avro.model.HoodieCleanFileInfo;
+import org.apache.hudi.avro.model.HoodieCleanMetadata;
+import org.apache.hudi.avro.model.HoodieCleanPartitionMetadata;
+import org.apache.hudi.avro.model.HoodieCleanerPlan;
+import org.apache.hudi.avro.model.HoodieCompactionOperation;
+import org.apache.hudi.avro.model.HoodieCompactionPlan;
+import org.apache.hudi.avro.model.HoodieCompactionStrategy;
+import org.apache.hudi.avro.model.HoodieFileStatus;
+import org.apache.hudi.avro.model.HoodieInstantInfo;
+import org.apache.hudi.avro.model.HoodieMergeArchiveFilePlan;
+import org.apache.hudi.avro.model.HoodieReplaceCommitMetadata;
+import org.apache.hudi.avro.model.HoodieRollbackMetadata;
+import org.apache.hudi.avro.model.HoodieRollbackPartitionMetadata;
+import org.apache.hudi.avro.model.HoodieSavepointMetadata;
+import org.apache.hudi.avro.model.HoodieSavepointPartitionMetadata;
+import org.apache.hudi.avro.model.HoodieWriteStat;
+
+import org.apache.avro.generic.GenericDatumReader;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.avro.io.BinaryDecoder;
+import org.apache.avro.io.DecoderFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+public class DeserializationUtils {
+
+  private DeserializationUtils() {
+  }
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
COMPACT_PLAN_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieCompactionPlan.getClassSchema()));
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
BOOTSTRAP_INDEX_INFO_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieBootstrapIndexInfo.getClassSchema()));
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
BOOTSTRAP_PARTITION_METADATA_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieBootstrapPartitionMetadata.getClassSchema()));
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
BOOTSTRP_FILE_PARTITION_INFO_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieBootstrapFilePartitionInfo.getClassSchema()));
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
COMMIT_METADATA_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(org.apache.hudi.avro.model.HoodieCommitMetadata.getClassSchema()));
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
ROLLBACK_METADATA_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieRollbackMetadata.getClassSchema()));
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
SAVEPOINT_METADATA_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieSavepointMetadata.getClassSchema()));
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
ARCHIVE_FILE_PLAN_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieMergeArchiveFilePlan.getClassSchema()));
+
+  public static final GenericDatumReader<IndexedRecord> 
REPLACE_METADATA_DESERIALIZER =
+      new GenericDatumReader<>(HoodieReplaceCommitMetadata.getClassSchema());
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
CLEAN_METADATA_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieCleanMetadata.getClassSchema()));
+
+  public static final ThreadLocal<GenericDatumReader<IndexedRecord>> 
CLEANER_PLAN_DESERIALIZER =
+      ThreadLocal.withInitial(() -> new 
GenericDatumReader<>(HoodieCleanerPlan.getClassSchema()));
+
+  public static HoodieBootstrapIndexInfo 
deserializeHoodieBootstrapIndexInfo(byte[] data) throws IOException {
+    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(data, null);
+    GenericDatumReader<IndexedRecord> reader = 
BOOTSTRAP_INDEX_INFO_DESERIALIZER.get();
+    IndexedRecord plan = (IndexedRecord) reader.read(null, decoder).get(0);
+    return HoodieBootstrapIndexInfo.newBuilder()
+        .setVersion((Integer) plan.get(0))
+        .setBootstrapBasePath((String) plan.get(1))
+        .setCreatedTimestamp((Long) plan.get(2))
+        .setNumKeys((Integer) plan.get(3))
+        .build();
+  }
+
+  public static HoodieBootstrapPartitionMetadata 
deserializeHoodieBootstrapPartitionMetadata(byte[] data) throws IOException {
+    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(data, null);
+    GenericDatumReader<IndexedRecord> reader = 
BOOTSTRAP_PARTITION_METADATA_DESERIALIZER.get();
+    IndexedRecord record = (IndexedRecord) reader.read(null, decoder).get(0);
+    return HoodieBootstrapPartitionMetadata.newBuilder()
+        .setVersion((Integer) record.get(0))
+        .setBootstrapPartitionPath((String) record.get(1))
+        .setPartitionPath((String) record.get(2))
+        .setFileIdToBootstrapFile((Map<String, HoodieFileStatus>) 
record.get(3))
+        .build();
+  }
+
+  public static org.apache.hudi.avro.model.HoodieCommitMetadata 
deserializeHoodieCommitMetadata(
+      InputStream inputStream) throws IOException {
+    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(inputStream, 
null);
+    GenericDatumReader<IndexedRecord> reader = 
COMMIT_METADATA_DESERIALIZER.get();
+    IndexedRecord plan = (IndexedRecord) reader.read(null, decoder).get(0);
+    return org.apache.hudi.avro.model.HoodieCommitMetadata.newBuilder()
+        .setPartitionToWriteStats((Map<String, List<HoodieWriteStat>>) 
plan.get(0))

Review Comment:
   yes, working on a generic way.



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

Reply via email to