Skip to content
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

[SPARK-23047][PYTHON][SQL] Change MapVector to NullableMapVector in ArrowColumnVector #20239

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ public ArrowColumnVector(ValueVector vector) {

childColumns = new ArrowColumnVector[1];
childColumns[0] = new ArrowColumnVector(listVector.getDataVector());
} else if (vector instanceof MapVector) {
MapVector mapVector = (MapVector) vector;
} else if (vector instanceof NullableMapVector) {
NullableMapVector mapVector = (NullableMapVector) vector;
accessor = new StructAccessor(mapVector);

childColumns = new ArrowColumnVector[mapVector.size()];
Expand Down Expand Up @@ -553,9 +553,16 @@ final int getArrayOffset(int rowId) {
}
}

/**
* Any call to "get" method will throw UnsupportedOperationException.
*
* Access struct values in a ArrowColumnVector doesn't use this accessor. Instead, it uses getStruct() method defined
* in the parent class. Any call to "get" method in this class is a bug in the code.
*
*/
private static class StructAccessor extends ArrowVectorAccessor {

StructAccessor(MapVector vector) {
StructAccessor(NullableMapVector vector) {
super(vector);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,42 @@ class ArrowColumnVectorSuite extends SparkFunSuite {
allocator.close()
}

test("non nullable struct") {
val allocator = ArrowUtils.rootAllocator.newChildAllocator("struct", 0, Long.MaxValue)
val schema = new StructType().add("int", IntegerType).add("long", LongType)
val vector = ArrowUtils.toArrowField("struct", schema, nullable = false, null)
.createVector(allocator).asInstanceOf[NullableMapVector]

vector.allocateNew()
val intVector = vector.getChildByOrdinal(0).asInstanceOf[IntVector]
val longVector = vector.getChildByOrdinal(1).asInstanceOf[BigIntVector]

vector.setIndexDefined(0)
intVector.setSafe(0, 1)
longVector.setSafe(0, 1L)

vector.setIndexDefined(1)
intVector.setSafe(1, 2)
longVector.setNull(1)

vector.setValueCount(2)

val columnVector = new ArrowColumnVector(vector)
assert(columnVector.dataType === schema)
assert(columnVector.numNulls === 0)

val row0 = columnVector.getStruct(0, 2)
assert(row0.getInt(0) === 1)
assert(row0.getLong(1) === 1L)

val row1 = columnVector.getStruct(1, 2)
assert(row1.getInt(0) === 2)
assert(row1.isNullAt(1))

columnVector.close()
allocator.close()
}

test("struct") {
val allocator = ArrowUtils.rootAllocator.newChildAllocator("struct", 0, Long.MaxValue)
val schema = new StructType().add("int", IntegerType).add("long", LongType)
Expand Down