Skip to content

Commit ccd872f

Browse files
committed
initial commit
1 parent 4d99b95 commit ccd872f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/OffHeapColumnVector.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,28 +436,29 @@ public void loadBytes(ColumnVector.Array array) {
436436
// Split out the slow path.
437437
@Override
438438
protected void reserveInternal(int newCapacity) {
439+
int oldCapacity = (this.data == 0L) ? 0 : capacity;
439440
if (this.resultArray != null) {
440441
this.lengthData =
441-
Platform.reallocateMemory(lengthData, elementsAppended * 4, newCapacity * 4);
442+
Platform.reallocateMemory(lengthData, oldCapacity * 4, newCapacity * 4);
442443
this.offsetData =
443-
Platform.reallocateMemory(offsetData, elementsAppended * 4, newCapacity * 4);
444+
Platform.reallocateMemory(offsetData, oldCapacity * 4, newCapacity * 4);
444445
} else if (type instanceof ByteType || type instanceof BooleanType) {
445-
this.data = Platform.reallocateMemory(data, elementsAppended, newCapacity);
446+
this.data = Platform.reallocateMemory(data, oldCapacity, newCapacity);
446447
} else if (type instanceof ShortType) {
447-
this.data = Platform.reallocateMemory(data, elementsAppended * 2, newCapacity * 2);
448+
this.data = Platform.reallocateMemory(data, oldCapacity * 2, newCapacity * 2);
448449
} else if (type instanceof IntegerType || type instanceof FloatType ||
449450
type instanceof DateType || DecimalType.is32BitDecimalType(type)) {
450-
this.data = Platform.reallocateMemory(data, elementsAppended * 4, newCapacity * 4);
451+
this.data = Platform.reallocateMemory(data, oldCapacity * 4, newCapacity * 4);
451452
} else if (type instanceof LongType || type instanceof DoubleType ||
452453
DecimalType.is64BitDecimalType(type) || type instanceof TimestampType) {
453-
this.data = Platform.reallocateMemory(data, elementsAppended * 8, newCapacity * 8);
454+
this.data = Platform.reallocateMemory(data, oldCapacity * 8, newCapacity * 8);
454455
} else if (resultStruct != null) {
455456
// Nothing to store.
456457
} else {
457458
throw new RuntimeException("Unhandled " + type);
458459
}
459-
this.nulls = Platform.reallocateMemory(nulls, elementsAppended, newCapacity);
460-
Platform.setMemory(nulls + elementsAppended, (byte)0, newCapacity - elementsAppended);
460+
this.nulls = Platform.reallocateMemory(nulls, oldCapacity, newCapacity);
461+
Platform.setMemory(nulls + oldCapacity, (byte)0, newCapacity - oldCapacity);
461462
capacity = newCapacity;
462463
}
463464
}

0 commit comments

Comments
 (0)