Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
icexelloss committed Jan 12, 2018
1 parent e068966 commit ab2a309
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ final int getArrayOffset(int rowId) {
}

/**
* This is a place holder class. Any "get" method will throw UnsupportedOperationException.
* 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.
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

0 comments on commit ab2a309

Please sign in to comment.