Skip to content

Commit f7c92aa

Browse files
authored
chore: Reuse comet allocator (#1973)
1 parent afd2ae0 commit f7c92aa

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

common/src/main/scala/org/apache/spark/sql/comet/execution/arrow/CometArrowConverters.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package org.apache.spark.sql.comet.execution.arrow
2121

22-
import org.apache.arrow.memory.{BufferAllocator, RootAllocator}
22+
import org.apache.arrow.memory.BufferAllocator
2323
import org.apache.arrow.vector.VectorSchemaRoot
2424
import org.apache.arrow.vector.types.pojo.Schema
2525
import org.apache.spark.TaskContext
@@ -29,12 +29,10 @@ import org.apache.spark.sql.comet.util.Utils
2929
import org.apache.spark.sql.types.StructType
3030
import org.apache.spark.sql.vectorized.{ColumnarArray, ColumnarBatch}
3131

32+
import org.apache.comet.CometArrowAllocator
3233
import org.apache.comet.vector.NativeUtil
3334

3435
object CometArrowConverters extends Logging {
35-
// TODO: we should reuse the same root allocator in the comet code base?
36-
private val rootAllocator: BufferAllocator = new RootAllocator(Long.MaxValue)
37-
3836
// This is similar how Spark converts internal row to Arrow format except that it is transforming
3937
// the result batch to Comet's ColumnarBatch instead of serialized bytes.
4038
// There's another big difference that Comet may consume the ColumnarBatch by exporting it to
@@ -56,7 +54,7 @@ object CometArrowConverters extends Logging {
5654
protected val arrowSchema: Schema = Utils.toArrowSchema(schema, timeZoneId)
5755
// Reuse the same root allocator here.
5856
protected val allocator: BufferAllocator =
59-
rootAllocator.newChildAllocator(s"to${this.getClass.getSimpleName}", 0, Long.MaxValue)
57+
CometArrowAllocator.newChildAllocator(s"to${this.getClass.getSimpleName}", 0, Long.MaxValue)
6058
protected val root: VectorSchemaRoot = VectorSchemaRoot.create(arrowSchema, allocator)
6159
protected val arrowWriter: ArrowWriter = ArrowWriter.create(root)
6260

0 commit comments

Comments
 (0)