huaxingao commented on a change in pull request #34087:
URL: https://github.com/apache/spark/pull/34087#discussion_r715681468
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/vectorized/ColumnarBatchSuite.scala
##########
@@ -1151,6 +1153,113 @@ class ColumnarBatchSuite extends SparkFunSuite {
}}
}
+ test("ColumnarBatch customization") {
+ (MemoryMode.ON_HEAP :: MemoryMode.OFF_HEAP :: Nil).foreach { memMode => {
+ val schema = new StructType()
+ .add("intCol", IntegerType)
+ .add("doubleCol", DoubleType)
+ .add("intCol2", IntegerType)
+ .add("string", BinaryType)
+
+ val capacity = 4 * 1024
+ val columns = schema.fields.map { field =>
+ allocate(capacity, field.dataType, memMode)
+ }
+ val batch = new CustomizedColumnarBatch(columns.toArray)
+ assert(batch.numCols() == 4)
+ assert(batch.numRows() == 0)
+ assert(batch.rowIterator().hasNext == false)
+
+ // Add a row [1, 1.1, NULL]
+ columns(0).putInt(0, 1)
+ columns(1).putDouble(0, 1.1)
+ columns(2).putNull(0)
+ columns(3).putByteArray(0, "Hello".getBytes(StandardCharsets.UTF_8))
+ batch.setNumRows(1)
+
+ // Verify the results of the row.
+ assert(batch.numCols() == 4)
+ assert(batch.numRows() == 1)
+ // rowId 0 is skipped
+ assert(batch.rowIterator().hasNext == false)
+
+ // Reset and add 3 rows
+ columns.foreach(_.reset())
+ // Add rows [NULL, 2.2, 2, "abc"], [3, NULL, 3, ""], [4, 4.4, 4, "world]
Review comment:
nit: `[4, 4.4, 4, "world]` -> `[4, 4.4, 4, "world"]`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]