huaxingao commented on code in PR #13709: URL: https://github.com/apache/iceberg/pull/13709#discussion_r2277492839
########## arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java: ########## @@ -0,0 +1,178 @@ +/* + * 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.iceberg.arrow.vectorized.parquet; + +import java.io.EOFException; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.UUID; +import java.util.function.IntUnaryOperator; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.IntVector; +import org.apache.iceberg.arrow.ArrowAllocation; +import org.apache.iceberg.io.CloseableGroup; +import org.apache.parquet.bytes.ByteBufferInputStream; +import org.apache.parquet.io.ParquetDecodingException; +import org.apache.parquet.io.api.Binary; + +public class VectorizedDeltaLengthByteArrayValuesReader + implements VectorizedValuesReader, AutoCloseable { + + private final VectorizedDeltaEncodedValuesReader lengthReader; + private final CloseableGroup closeables; + + private ByteBufferInputStream in; + private IntVector lengthsVector; + private ByteBuffer byteBuffer; + + VectorizedDeltaLengthByteArrayValuesReader() { + lengthReader = new VectorizedDeltaEncodedValuesReader(); + closeables = new CloseableGroup(); + } + + @Override + public void initFromPage(int valueCount, ByteBufferInputStream inputStream) throws IOException { + lengthsVector = new IntVector("length-" + UUID.randomUUID(), ArrowAllocation.rootAllocator()); + closeables.addCloseable(lengthsVector); + lengthReader.initFromPage(valueCount, inputStream); + lengthReader.readIntegers(lengthReader.getTotalValueCount(), lengthsVector, 0); + this.in = inputStream.remainingStream(); + } + + @Override + public Binary readBinary(int len) { + readValues(1, null, 0, x -> len, (f, i, v) -> byteBuffer = v); + return Binary.fromReusedByteBuffer(byteBuffer); + } + + @Override + public void readBinary(int total, FieldVector vec, int rowId) { + readValues( + total, + vec, + rowId, + x -> lengthsVector.get(x), + (f, i, v) -> f.getDataBuffer().setBytes(i, v)); + } + + private void readValues( + int total, + FieldVector vec, + int rowId, + IntUnaryOperator getLength, + BinaryOutputWriter outputWriter) { + ByteBuffer buffer; + int length; + for (int i = 0; i < total; i++) { + length = getLength.applyAsInt(rowId + i); Review Comment: nit: shall we assert length > 0? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
