richardstartin commented on a change in pull request #7595: URL: https://github.com/apache/pinot/pull/7595#discussion_r732959430
########## File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/forward/VarByteChunkMVForwardIndexReader.java ########## @@ -0,0 +1,192 @@ +/** + * 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.pinot.segment.local.segment.index.readers.forward; + +import java.nio.ByteBuffer; +import javax.annotation.Nullable; +import org.apache.pinot.segment.local.io.writer.impl.VarByteChunkSVForwardIndexWriter; +import org.apache.pinot.segment.spi.memory.PinotDataBuffer; +import org.apache.pinot.spi.data.FieldSpec.DataType; + +/** + * Chunk-based single-value raw (non-dictionary-encoded) forward index reader for values of + * variable + * length data type + * (STRING, BYTES). + * <p>For data layout, please refer to the documentation for {@link VarByteChunkSVForwardIndexWriter} + */ +public final class VarByteChunkMVForwardIndexReader extends BaseChunkSVForwardIndexReader { + + private static final int ROW_OFFSET_SIZE = VarByteChunkSVForwardIndexWriter.CHUNK_HEADER_ENTRY_ROW_OFFSET_SIZE; + + private final int _maxChunkSize; + + public VarByteChunkMVForwardIndexReader(PinotDataBuffer dataBuffer, DataType valueType) { + super(dataBuffer, valueType); + _maxChunkSize = _numDocsPerChunk * (ROW_OFFSET_SIZE + _lengthOfLongestEntry); + } + + @Nullable + @Override + public ChunkReaderContext createContext() { + if (_isCompressed) { + return new ChunkReaderContext(_maxChunkSize); + } else { + return null; + } + } + + @Override + public int getStringMV(final int docId, final String[] valueBuffer, + final ChunkReaderContext context) { + byte[] compressedBytes; + if (_isCompressed) { + compressedBytes = getBytesCompressed(docId, context); + } else { + compressedBytes = getBytesUncompressed(docId); + } + ByteBuffer byteBuffer = ByteBuffer.wrap(compressedBytes); + int numValues = byteBuffer.getInt(); + int contentOffset = (numValues + 1) * Integer.BYTES; + for (int i = 0; i < numValues; i++) { + int length = byteBuffer.getInt((i + 1) * Integer.BYTES); + byte[] bytes = new byte[length]; + byteBuffer.position(contentOffset); + byteBuffer.get(bytes, 0, length); + valueBuffer[i] = new String(bytes); Review comment: TODO: This doesn't specify encoding -- 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...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org