spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dongjoon-hyun <...@git.apache.org>
Subject [GitHub] spark pull request #18787: [SPARK-21583][SQL] Create a ColumnarBatch from Ar...
Date Thu, 31 Aug 2017 18:06:28 GMT
Github user dongjoon-hyun commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18787#discussion_r136407451
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/execution/vectorized/ColumnarBatchSuite.scala
---
    @@ -1261,4 +1264,55 @@ class ColumnarBatchSuite extends SparkFunSuite {
             s"vectorized reader"))
         }
       }
    +
    +  test("create columnar batch from Arrow column vectors") {
    +    val allocator = ArrowUtils.rootAllocator.newChildAllocator("int", 0, Long.MaxValue)
    +    val vector1 = ArrowUtils.toArrowField("int1", IntegerType, nullable = true)
    +      .createVector(allocator).asInstanceOf[NullableIntVector]
    +    vector1.allocateNew()
    +    val mutator1 = vector1.getMutator()
    +    val vector2 = ArrowUtils.toArrowField("int2", IntegerType, nullable = true)
    +      .createVector(allocator).asInstanceOf[NullableIntVector]
    +    vector2.allocateNew()
    +    val mutator2 = vector2.getMutator()
    +
    +    (0 until 10).foreach { i =>
    +      mutator1.setSafe(i, i)
    +      mutator2.setSafe(i + 1, i)
    +    }
    +    mutator1.setNull(10)
    +    mutator1.setValueCount(11)
    +    mutator2.setNull(0)
    +    mutator2.setValueCount(11)
    +
    +    val columnVectors = Seq(new ArrowColumnVector(vector1), new ArrowColumnVector(vector2))
    +
    +    val schema = StructType(Seq(StructField("int1", IntegerType), StructField("int2",
IntegerType)))
    +    val batch = new ColumnarBatch(schema, columnVectors.toArray[ColumnVector], 11)
    +    batch.setNumRows(11)
    +
    +    assert(batch.numCols() == 2)
    +    assert(batch.numRows() == 11)
    +
    +    val rowIter = batch.rowIterator().asScala
    +    rowIter.zipWithIndex.foreach { case (row, i) =>
    +      if (i == 10) {
    +        assert(row.isNullAt(0))
    +      } else {
    +        assert(row.getInt(0) == i)
    +      }
    +      if (i == 0) {
    +        assert(row.isNullAt(1))
    +      } else {
    +        assert(row.getInt(1) == i - 1)
    +      }
    +    }
    +
    +    intercept[java.lang.AssertionError] {
    +      batch.getRow(100)
    --- End diff --
    
    Thanks! It seems to happen Maven only. sbt-hadoop-2.6 passed.
    - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20QA%20Test%20(Dashboard)/job/spark-master-test-sbt-hadoop-2.6/3480/


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message