vbhanuchander-lang commented on code in PR #17645:
URL: https://github.com/apache/iceberg/pull/17645#discussion_r3787866306
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/VectorizedArrowReader.java:
##########
@@ -304,14 +305,21 @@ private void allocateVectorBasedOnTypeName(PrimitiveType
primitive, Field arrowF
this.readType = ReadType.FIXED_WIDTH_BINARY;
}
this.vec = arrowField.createVector(rootAlloc);
- vec.setInitialCapacity(batchSize * len);
+ // Fixed-width vectors size their data buffer as valueCount *
typeWidth, so passing a byte
+ // count reserves typeWidth times too many values.
+ vec.setInitialCapacity(batchSize);
Review Comment:
You are right, and the description was the stale half. I folded the
fixed-width sites in with 3873922 but only edited the "Scope" section to say I
*had* left them out. Rewritten now: it lists all four sites in two groups
(variable-width via the density overload, fixed-width via plain `batchSize`)
and explains why they belong in one PR.
##########
arrow/src/test/java/org/apache/iceberg/arrow/vectorized/TestVariableWidthInitialCapacity.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.FixedSizeBinaryVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Pins the Arrow sizing contract that {@code VectorizedArrowReader} relies on
when it allocates
+ * variable-width vectors.
+ *
+ * <p>{@code setInitialCapacity(int)} takes a <em>value count</em>, not a byte
count, and sizes the
+ * data buffer at Arrow's default of 8 bytes per value. Passing {@code
batchSize * averageWidth} to
+ * it therefore reserves offsets for {@code averageWidth} times too many
values. The density
+ * overload, {@code setInitialCapacity(int, double)}, expresses what the
reader actually means.
+ */
+public class TestVariableWidthInitialCapacity {
Review Comment:
Confirmed and fixed — you were right that the test did not guard the change.
I checked your claim directly: with the test as it was and
`VectorizedArrowReader` reverted to `main`, all three tests still passed. It
was pinning Arrow's own sizing contract, not the reader's use of it.
Replaced it with `TestVectorInitialCapacity` (95fe124), which goes through
the reader. It writes a table with `string`, `binary` and `fixed[16]` columns —
dictionary encoding off, so the reader takes the plain-encoded allocation path
rather than `allocateDictEncodedVector` — reads it through
`VectorizedTableScanIterable` at the default batch size, and asserts the
capacity of the vectors `VectorizedArrowReader` actually allocated.
Verified it fails on revert, which is the property the old one lacked:
```
variableWidthVectorsHoldOneBatchOfValues() FAILED
[a varchar vector must not reserve offsets for batchSize * averageWidth
rows]
Expecting actual: 63549 to be less than: 50000
fixedWidthVectorsHoldOneBatchOfValues() FAILED
[a fixed width vector must not reserve batchSize * typeWidth values]
Expecting actual: 130055 to be less than: 80000
```
One gap worth naming: `INT96` is not covered. The Iceberg writer does not
emit INT96 timestamps, so that branch is not reachable from a written table. It
is the same one-line units change as `FIXED_LEN_BYTE_ARRAY`.
--
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]