platinumhamburg commented on code in PR #2485: URL: https://github.com/apache/fluss/pull/2485#discussion_r2744297851
########## fluss-common/src/main/java/org/apache/fluss/record/KeyRecordBatch.java: ########## @@ -0,0 +1,200 @@ +/* + * 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.fluss.record; + +import org.apache.fluss.metadata.KvFormat; +import org.apache.fluss.metadata.Schema; +import org.apache.fluss.metadata.SchemaGetter; +import org.apache.fluss.row.BinaryRow; +import org.apache.fluss.row.InternalRow; +import org.apache.fluss.row.decode.KeyDecoder; +import org.apache.fluss.row.encode.RowEncoder; +import org.apache.fluss.types.DataType; +import org.apache.fluss.types.RowType; + +import java.nio.ByteBuffer; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +import static org.apache.fluss.record.LogRecordBatchFormat.NO_BATCH_SEQUENCE; +import static org.apache.fluss.record.LogRecordBatchFormat.NO_WRITER_ID; + +/** + * A lazy-decoding KvRecordBatch that stores key bytes and converts them to KvRecords on-demand + * during iteration. + * + * <p>When iterating via {@link #records(ReadContext)}, each key is decoded and a full row is + * constructed with key fields populated and non-key fields set to null. This avoids upfront + * full-batch decoding, improving memory efficiency. + */ +public class KeyRecordBatch implements KvRecordBatch { + + private final List<byte[]> keyBytes; + + /** + * Creates a KeyRecordBatch for lazy KvRecord construction. + * + * @param keyBytes the list of encoded key bytes + */ + public KeyRecordBatch(List<byte[]> keyBytes) { + this.keyBytes = keyBytes; + } + + @Override + public Iterable<KvRecord> records(ReadContext readContext) { + return () -> new LazyKvRecordIterator(readContext); + } + + @Override + public int getRecordCount() { + return keyBytes.size(); + } + + @Override + public short schemaId() { + return 0; Review Comment: Is it safe to use constant 0 here? -- 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]
