-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-21046][SQL] simplify the array offset and length in ColumnVector #18260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d4267b7
simplify the array offset and length in ColumnVector
cloud-fan a61ba71
address comments
cloud-fan 368c346
more comments
cloud-fan 1dae660
minor
cloud-fan e6e60e0
use long array
cloud-fan fdc0870
fix bug
cloud-fan 04790bb
fix test
cloud-fan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,14 +43,12 @@ public final class OnHeapColumnVector extends ColumnVector { | |
| private byte[] byteData; | ||
| private short[] shortData; | ||
| private int[] intData; | ||
| // This is not only used to store data for int column vector, but also can store offsets and | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int column vector -> long column vector. |
||
| // lengths for array column vector. | ||
| private long[] longData; | ||
| private float[] floatData; | ||
| private double[] doubleData; | ||
|
|
||
| // Only set if type is Array. | ||
| private int[] arrayLengths; | ||
| private int[] arrayOffsets; | ||
|
|
||
| protected OnHeapColumnVector(int capacity, DataType type) { | ||
| super(capacity, type, MemoryMode.ON_HEAP); | ||
| reserveInternal(capacity); | ||
|
|
@@ -366,55 +364,22 @@ public double getDouble(int rowId) { | |
| } | ||
| } | ||
|
|
||
| // | ||
| // APIs dealing with Arrays | ||
| // | ||
|
|
||
| @Override | ||
| public int getArrayLength(int rowId) { | ||
| return arrayLengths[rowId]; | ||
| } | ||
| @Override | ||
| public int getArrayOffset(int rowId) { | ||
| return arrayOffsets[rowId]; | ||
| } | ||
|
|
||
| @Override | ||
| public void putArray(int rowId, int offset, int length) { | ||
| arrayOffsets[rowId] = offset; | ||
| arrayLengths[rowId] = length; | ||
| } | ||
|
|
||
| @Override | ||
| public void loadBytes(ColumnVector.Array array) { | ||
| array.byteArray = byteData; | ||
| array.byteArrayOffset = array.offset; | ||
| } | ||
|
|
||
| // | ||
| // APIs dealing with Byte Arrays | ||
| // | ||
|
|
||
| @Override | ||
| public int putByteArray(int rowId, byte[] value, int offset, int length) { | ||
| int result = arrayData().appendBytes(length, value, offset); | ||
| arrayOffsets[rowId] = result; | ||
| arrayLengths[rowId] = length; | ||
| return result; | ||
| } | ||
|
|
||
| // Spilt this function out since it is the slow path. | ||
| @Override | ||
| protected void reserveInternal(int newCapacity) { | ||
| if (this.resultArray != null || DecimalType.isByteArrayDecimalType(type)) { | ||
| int[] newLengths = new int[newCapacity]; | ||
| int[] newOffsets = new int[newCapacity]; | ||
| if (this.arrayLengths != null) { | ||
| System.arraycopy(this.arrayLengths, 0, newLengths, 0, capacity); | ||
| System.arraycopy(this.arrayOffsets, 0, newOffsets, 0, capacity); | ||
| // need 1 long as offset and length for each array. | ||
| if (longData == null || longData.length < newCapacity) { | ||
| long[] newData = new long[newCapacity]; | ||
| if (longData != null) System.arraycopy(longData, 0, newData, 0, capacity); | ||
| longData = newData; | ||
| } | ||
| arrayLengths = newLengths; | ||
| arrayOffsets = newOffsets; | ||
| } else if (type instanceof BooleanType) { | ||
| if (byteData == null || byteData.length < newCapacity) { | ||
| byte[] newData = new byte[newCapacity]; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -631,7 +631,7 @@ class ColumnarBatchSuite extends SparkFunSuite { | |
| assert(column.arrayData().elementsAppended == 17) | ||
|
|
||
| // Put the same "ll" at offset. This should not allocate more memory in the column. | ||
| column.putArray(idx, offset, 2) | ||
| column.putArrayOffsetAndSize(idx, offset, 2) | ||
| reference += "ll" | ||
| idx += 1 | ||
| assert(column.arrayData().elementsAppended == 17) | ||
|
|
@@ -644,7 +644,7 @@ class ColumnarBatchSuite extends SparkFunSuite { | |
| assert(column.arrayData().elementsAppended == 17 + (s + s).length) | ||
|
|
||
| reference.zipWithIndex.foreach { v => | ||
| assert(v._1.length == column.getArrayLength(v._2), "MemoryMode=" + memMode) | ||
| assert(v._1.length == column.getInt(v._2 * 2 + 1), "MemoryMode=" + memMode) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, we should also change here. |
||
| assert(v._1 == column.getUTF8String(v._2).toString, | ||
| "MemoryMode" + memMode) | ||
| } | ||
|
|
@@ -659,18 +659,18 @@ class ColumnarBatchSuite extends SparkFunSuite { | |
| val column = ColumnVector.allocate(10, new ArrayType(IntegerType, true), memMode) | ||
|
|
||
| // Fill the underlying data with all the arrays back to back. | ||
| val data = column.arrayData(); | ||
| val data = column.arrayData() | ||
| var i = 0 | ||
| while (i < 6) { | ||
| data.putInt(i, i) | ||
| i += 1 | ||
| } | ||
|
|
||
| // Populate it with arrays [0], [1, 2], [], [3, 4, 5] | ||
| column.putArray(0, 0, 1) | ||
| column.putArray(1, 1, 2) | ||
| column.putArray(2, 2, 0) | ||
| column.putArray(3, 3, 3) | ||
| column.putArrayOffsetAndSize(0, 0, 1) | ||
| column.putArrayOffsetAndSize(1, 1, 2) | ||
| column.putArrayOffsetAndSize(2, 3, 0) | ||
| column.putArrayOffsetAndSize(3, 3, 3) | ||
|
|
||
| val a1 = ColumnVectorUtils.toPrimitiveJavaArray(column.getArray(0)).asInstanceOf[Array[Int]] | ||
| val a2 = ColumnVectorUtils.toPrimitiveJavaArray(column.getArray(1)).asInstanceOf[Array[Int]] | ||
|
|
@@ -703,7 +703,7 @@ class ColumnarBatchSuite extends SparkFunSuite { | |
| data.reserve(array.length) | ||
| assert(data.capacity == array.length * 2) | ||
| data.putInts(0, array.length, array, 0) | ||
| column.putArray(0, 0, array.length) | ||
| column.putArrayOffsetAndSize(0, 0, array.length) | ||
| assert(ColumnVectorUtils.toPrimitiveJavaArray(column.getArray(0)).asInstanceOf[Array[Int]] | ||
| === array) | ||
| }} | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offsetshould be converted tolongbefore shifting?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch