Skip to content

Commit d5501fa

Browse files
committed
More precise initial buffer size estimation for in-memory column buffer
1 parent 9038d94 commit d5501fa

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

sql/core/src/main/scala/org/apache/spark/sql/columnar/InMemoryColumnarTableScan.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ package org.apache.spark.sql.columnar
2020
import java.nio.ByteBuffer
2121

2222
import org.apache.spark.rdd.RDD
23+
import org.apache.spark.sql.Row
2324
import org.apache.spark.sql.catalyst.analysis.MultiInstanceRelation
24-
import org.apache.spark.sql.catalyst.expressions.{GenericMutableRow, Attribute}
25+
import org.apache.spark.sql.catalyst.expressions.{Attribute, GenericMutableRow}
2526
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
26-
import org.apache.spark.sql.execution.{SparkPlan, LeafNode}
27-
import org.apache.spark.sql.Row
28-
import org.apache.spark.SparkConf
27+
import org.apache.spark.sql.execution.{LeafNode, SparkPlan}
2928

3029
object InMemoryRelation {
3130
def apply(useCompression: Boolean, batchSize: Int, child: SparkPlan): InMemoryRelation =
@@ -48,7 +47,9 @@ private[sql] case class InMemoryRelation(
4847
new Iterator[Array[ByteBuffer]] {
4948
def next() = {
5049
val columnBuilders = output.map { attribute =>
51-
ColumnBuilder(ColumnType(attribute.dataType).typeId, 0, attribute.name, useCompression)
50+
val columnType = ColumnType(attribute.dataType)
51+
val initialBufferSize = columnType.defaultSize * batchSize
52+
ColumnBuilder(columnType.typeId, initialBufferSize, attribute.name, useCompression)
5253
}.toArray
5354

5455
var row: Row = null

0 commit comments

Comments
 (0)