wombatu-kun commented on code in PR #12171:
URL: https://github.com/apache/hudi/pull/12171#discussion_r1819056185
##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/block/HoodieLogBlock.java:
##########
@@ -255,42 +256,31 @@ public long getBlockEndPos() {
}
/**
- * Convert log metadata to bytes 1. Write size of metadata 2. Write enum
ordinal 3. Write actual bytes
+ * Convert header metadata to bytes 1. Write size of metadata 2. Write enum
ordinal 3. Write actual bytes
*/
- public static byte[] getLogMetadataBytes(Map<HeaderMetadataType, String>
metadata) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream output = new DataOutputStream(baos);
- output.writeInt(metadata.size());
- for (Map.Entry<HeaderMetadataType, String> entry : metadata.entrySet()) {
- output.writeInt(entry.getKey().ordinal());
- byte[] bytes = getUTF8Bytes(entry.getValue());
- output.writeInt(bytes.length);
- output.write(bytes);
- }
- return baos.toByteArray();
+ public static byte[] getHeaderMetadataBytes(Map<HeaderMetadataType, String>
metadata) throws IOException {
+ return getLogMetadataBytes(metadata);
}
/**
- * Convert bytes to LogMetadata, follow the same order as {@link
HoodieLogBlock#getLogMetadataBytes}.
+ * Convert bytes to Header Metadata, follow the same order as {@link
HoodieLogBlock#getHeaderMetadataBytes}.
*/
- public static Map<HeaderMetadataType, String>
getLogMetadata(SeekableDataInputStream dis) throws IOException {
+ public static Map<HeaderMetadataType, String>
getHeaderMetadata(SeekableDataInputStream dis) throws IOException {
+ return getLogMetadata(dis, index -> HeaderMetadataType.values()[index]);
+ }
- Map<HeaderMetadataType, String> metadata = new HashMap<>();
- // 1. Read the metadata written out
- int metadataCount = dis.readInt();
- try {
- while (metadataCount > 0) {
- int metadataEntryIndex = dis.readInt();
- int metadataEntrySize = dis.readInt();
- byte[] metadataEntry = new byte[metadataEntrySize];
- dis.readFully(metadataEntry, 0, metadataEntrySize);
- metadata.put(HeaderMetadataType.values()[metadataEntryIndex], new
String(metadataEntry));
- metadataCount--;
- }
- return metadata;
- } catch (EOFException eof) {
- throw new IOException("Could not read metadata fields ", eof);
- }
+ /**
+ * Convert footer metadata to bytes 1. Write size of metadata 2. Write enum
ordinal 3. Write actual bytes
+ */
+ public static byte[] getFooterMetadataBytes(Map<FooterMetadataType, String>
metadata) throws IOException {
+ return getLogMetadataBytes(metadata);
+ }
+
+ /**
+ * Convert bytes to Footer Metadata, follow the same order as {@link
HoodieLogBlock#getFooterMetadataBytes}.
+ */
+ public static Map<FooterMetadataType, String>
getFooterMetadata(SeekableDataInputStream dis) throws IOException {
+ return getLogMetadata(dis, index -> FooterMetadataType.values()[index]);
Review Comment:
actually, this function `index -> FooterMetadataType.values()[index]` is not
executed if there is no metadata in footer.
--
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]