apache / apache/arrow-java

VectorAppender fails with OversizedAllocationException when appending to empty UnionVector

Offen
#812 0 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Type: bug
Vorherrschende Sprache
Java
Sterne
94
Forks
152
Ø Merge
3 T. 16 Std.
Gemergte PRs (30 T.)
11

Beschreibung

### Describe the bug, including details regarding any error messages, version, and platform.

**Description:**
When appending a `UnionVector` to an empty target `UnionVector`, [this](https://github.com/apache/arrow-java/blob/main/vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java#L556) while loop runs infinitely until the exception occurs:
```
org.apache.arrow.vector.util.OversizedAllocationException: Unable to expand the buffer
```
It seems to be a issue with the `UnionVector.getValueCapacity()` method. Logging the capacity before and after calling `reAlloc()` shows that it's always `0`.
Debugging further, it seems like the value capacity of the `internalStruct` in the `UnionVector` always returns `0` because it has no children so [size](https://github.com/apache/arrow-java/blob/main/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java#L373) is `0`.
```
@Override
public int getValueCapacity() {
return Math.min(getTypeBufferValueCapacity(), internalStruct.getValueCapacity());
}
```

**Steps to reproduce**
```
@Test
public void testAppendEmptyTargetUnionVector() {
final int length = 5;

try (final UnionVector target = UnionVector.empty("target", allocator);
final UnionVector delta = UnionVector.empty("delta", allocator)) {

// populate the delta vector
delta.setType(0, Types.MinorType.FLOAT4);
delta.setType(1, Types.MinorType.FLOAT4);
delta.setType(2, Types.MinorType.FLOAT4);
delta.setType(3, Types.MinorType.FLOAT4);
delta.setType(4, Types.MinorType.FLOAT4);

Float4Vector deltaFloatVector = delta.getFloat4Vector();
deltaFloatVector.allocateNew();
ValueVectorDataPopulator.setVector(deltaFloatVector, 1f, 2f, 3f, 4f, 5f);
assertEquals(length, deltaFloatVector.getValueCount());
delta.setValueCount(length);

VectorAppender appender = new VectorAppender(target);
delta.accept(appender, null);

assertEquals(length, target.getValueCount());

for (int i = 0; i < length; i++) {
Object floatObj = target.getObject(i);
assertTrue(floatObj instanceof Float);
assertEquals(i+1, ((Float) floatObj).intValue());
}
}
}
```
This issue does not occur if any value is set in the target vector before appending.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der VectorAppender.java-Schleife um Zeile 556 und untersuche UnionVector.getValueCapacity(), einschließlich NonNullableStructVector.java um Zeile 373. Führe die bereitgestellte testAppendEmptyTargetUnionVector-Reproduktion aus und vergleiche die Kapazität vor und nach reAlloc(). Erledigt ist die Aufgabe, wenn das Anhängen an einen leeren UnionVector ohne OversizedAllocationException abgeschlossen wird und alle fünf float-Werte erhalten bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
data
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
55/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.