Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/18468#discussion_r128156883
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/vectorized/ColumnarBatchSuite.scala
---
@@ -326,6 +329,84 @@ class ColumnarBatchSuite extends SparkFunSuite {
}}
}
+ test("CachedBatch primitive Apis") {
+ (BooleanType :: IntegerType :: DoubleType :: Nil).foreach { dataType
=> {
+ val columnBuilder = ColumnBuilderHelper(dataType, 1024, "col", true)
+ val row = new SpecificInternalRow(Array(dataType))
+ for (i <- 0 until 16) {
+ dataType match {
+ case _ : BooleanType => row.setBoolean(0, i % 2 == 0)
+ case _ : IntegerType => row.setInt(0, i)
+ case _ : DoubleType => row.setDouble(0, i)
+ }
+ columnBuilder.appendFrom(row, 0)
+ }
+
+ val column = new CachedBatchColumnVector(
+ JavaUtils.bufferToArray(columnBuilder.build), 1024, dataType)
+
+ for (i <- 0 until 16) {
+ assert(column.isNullAt(i) == false)
+ dataType match {
+ case _ : BooleanType => assert(column.getBoolean(i) == (i % 2 ==
0))
+ case _ : IntegerType => assert(column.getInt(i) == i)
+ case _ : DoubleType => assert(column.getDouble(i) == i.toDouble)
+ }
+ }
+
+ /* check row access order */
+ val column2 = new CachedBatchColumnVector(
+ JavaUtils.bufferToArray(columnBuilder.build), 1024, dataType)
+ dataType match {
+ case _: BooleanType =>
+ /* Row access must start with 0 */
+ val e = intercept[UnsupportedOperationException] {
+ column2.getBoolean(1)
+ }
+ assert(e.getMessage.startsWith("Row access order must be
sequentially ascending."))
+ case _: IntegerType =>
+ /* Row access order must be sequential */
--- End diff --
I think we don't need to be so strict. The rule is, users can't jump back
and read values, but other than that is OK, e.g. `getInt(0), getInt(0),
getInt(10), getInt(11)`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]