yihua commented on code in PR #10241:
URL: https://github.com/apache/hudi/pull/10241#discussion_r1456560159


##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileDataBlock.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.io.hfile;
+
+import org.apache.hudi.io.util.IOUtils;
+
+import java.util.Optional;
+
+import static org.apache.hudi.io.hfile.KeyValue.KEY_OFFSET;
+
+/**
+ * Represents a {@link HFileBlockType#DATA} block in the "Scanned block" 
section.
+ */
+public class HFileDataBlock extends HFileBlock {
+  protected HFileDataBlock(HFileContext context,
+                           byte[] byteBuff,
+                           int startOffsetInBuff) {
+    super(context, HFileBlockType.DATA, byteBuff, startOffsetInBuff);
+  }
+
+  /**
+   * Seeks to the key to look up.
+   *
+   * @param key Key to look up.
+   * @return The {@link KeyValue} instance in the block that contains the 
exact same key as the
+   * lookup key; or empty {@link Optional} if the lookup key does not exist.
+   */
+  public Optional<KeyValue> seekTo(Key key) {
+    int offset = startOffsetInBuff + HFILEBLOCK_HEADER_SIZE;
+    int endOffset = offset + onDiskSizeWithoutHeader;
+    // TODO: check last 4 bytes in the data block
+    while (offset + HFILEBLOCK_HEADER_SIZE < endOffset) {
+      // Full length is not known yet until parsing
+      KeyValue kv = new KeyValue(byteBuff, offset, -1);

Review Comment:
   We are good on this as we move the cursor progressively while looking up 
sorted keys, instead of always moving the cursor from the beginning of the file.



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