-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-10917] [SQL] improve performance of complex type in columnar cache #8971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
713c884
59bb2f9
a791ba3
f9a3502
3ad1e9c
3b9f59e
54479f1
d0be9e4
9c5718d
4f0a94e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package org.apache.spark.sql.columnar | |
|
|
||
| import java.nio.{ByteBuffer, ByteOrder} | ||
|
|
||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.MutableRow | ||
| import org.apache.spark.sql.columnar.compression.CompressibleColumnAccessor | ||
| import org.apache.spark.sql.types._ | ||
|
|
@@ -61,6 +62,10 @@ private[sql] abstract class BasicColumnAccessor[JvmType]( | |
| protected def underlyingBuffer = buffer | ||
| } | ||
|
|
||
| private[sql] class NullColumnAccess(buffer: ByteBuffer) | ||
| extends BasicColumnAccessor[Any](buffer, NULL) | ||
| with NullableColumnAccessor | ||
|
|
||
| private[sql] abstract class NativeColumnAccessor[T <: AtomicType]( | ||
| override protected val buffer: ByteBuffer, | ||
| override protected val columnType: NativeColumnType[T]) | ||
|
|
@@ -96,18 +101,31 @@ private[sql] class BinaryColumnAccessor(buffer: ByteBuffer) | |
| extends BasicColumnAccessor[Array[Byte]](buffer, BINARY) | ||
| with NullableColumnAccessor | ||
|
|
||
| private[sql] class FixedDecimalColumnAccessor(buffer: ByteBuffer, precision: Int, scale: Int) | ||
| extends NativeColumnAccessor(buffer, FIXED_DECIMAL(precision, scale)) | ||
| private[sql] class CompactDecimalColumnAccessor(buffer: ByteBuffer, dataType: DecimalType) | ||
| extends NativeColumnAccessor(buffer, COMPACT_DECIMAL(dataType)) | ||
|
|
||
| private[sql] class DecimalColumnAccessor(buffer: ByteBuffer, dataType: DecimalType) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe |
||
| extends BasicColumnAccessor[Decimal](buffer, LARGE_DECIMAL(dataType)) | ||
| with NullableColumnAccessor | ||
|
|
||
| private[sql] class StructColumnAccessor(buffer: ByteBuffer, dataType: StructType) | ||
| extends BasicColumnAccessor[InternalRow](buffer, STRUCT(dataType)) | ||
| with NullableColumnAccessor | ||
|
|
||
| private[sql] class ArrayColumnAccessor(buffer: ByteBuffer, dataType: ArrayType) | ||
| extends BasicColumnAccessor[ArrayData](buffer, ARRAY(dataType)) | ||
| with NullableColumnAccessor | ||
|
|
||
| private[sql] class GenericColumnAccessor(buffer: ByteBuffer, dataType: DataType) | ||
| extends BasicColumnAccessor[Array[Byte]](buffer, GENERIC(dataType)) | ||
| private[sql] class MapColumnAccessor(buffer: ByteBuffer, dataType: MapType) | ||
| extends BasicColumnAccessor[MapData](buffer, MAP(dataType)) | ||
| with NullableColumnAccessor | ||
|
|
||
| private[sql] object ColumnAccessor { | ||
| def apply(dataType: DataType, buffer: ByteBuffer): ColumnAccessor = { | ||
| val buf = buffer.order(ByteOrder.nativeOrder) | ||
|
|
||
| dataType match { | ||
| case NullType => new NullColumnAccess(buf) | ||
| case BooleanType => new BooleanColumnAccessor(buf) | ||
| case ByteType => new ByteColumnAccessor(buf) | ||
| case ShortType => new ShortColumnAccessor(buf) | ||
|
|
@@ -117,9 +135,15 @@ private[sql] object ColumnAccessor { | |
| case DoubleType => new DoubleColumnAccessor(buf) | ||
| case StringType => new StringColumnAccessor(buf) | ||
| case BinaryType => new BinaryColumnAccessor(buf) | ||
| case DecimalType.Fixed(precision, scale) if precision < 19 => | ||
| new FixedDecimalColumnAccessor(buf, precision, scale) | ||
| case other => new GenericColumnAccessor(buf, other) | ||
| case dt: DecimalType if dt.precision <= Decimal.MAX_LONG_DIGITS => | ||
| new CompactDecimalColumnAccessor(buf, dt) | ||
| case dt: DecimalType => new DecimalColumnAccessor(buf, dt) | ||
| case struct: StructType => new StructColumnAccessor(buf, struct) | ||
| case array: ArrayType => new ArrayColumnAccessor(buf, array) | ||
| case map: MapType => new MapColumnAccessor(buf, map) | ||
| case udt: UserDefinedType[_] => ColumnAccessor(udt.sqlType, buffer) | ||
| case other => | ||
| throw new Exception(s"not support type: $other") | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,7 +235,9 @@ private[sql] class BinaryColumnStats extends ColumnStats { | |
| new GenericInternalRow(Array[Any](null, null, nullCount, count, sizeInBytes)) | ||
| } | ||
|
|
||
| private[sql] class FixedDecimalColumnStats(precision: Int, scale: Int) extends ColumnStats { | ||
| private[sql] class DecimalColumnStats(precision: Int, scale: Int) extends ColumnStats { | ||
| def this(dt: DecimalType) = this(dt.precision, dt.scale) | ||
|
|
||
| protected var upper: Decimal = null | ||
| protected var lower: Decimal = null | ||
|
|
||
|
|
@@ -245,16 +247,17 @@ private[sql] class FixedDecimalColumnStats(precision: Int, scale: Int) extends C | |
| val value = row.getDecimal(ordinal, precision, scale) | ||
| if (upper == null || value.compareTo(upper) > 0) upper = value | ||
| if (lower == null || value.compareTo(lower) < 0) lower = value | ||
| sizeInBytes += FIXED_DECIMAL.defaultSize | ||
| // TODO: this is not right for DecimalType with precision > 18 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use |
||
| sizeInBytes += 8 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For decimals with precision greater than 18,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, thanks. I thinking it's better to get the number of written bytes from buffer, no more guessing. |
||
| } | ||
| } | ||
|
|
||
| override def collectedStatistics: GenericInternalRow = | ||
| new GenericInternalRow(Array[Any](lower, upper, nullCount, count, sizeInBytes)) | ||
| } | ||
|
|
||
| private[sql] class GenericColumnStats(dataType: DataType) extends ColumnStats { | ||
| val columnType = GENERIC(dataType) | ||
| private[sql] class ObjectColumnStats(dataType: DataType) extends ColumnStats { | ||
| val columnType = ColumnType(dataType) | ||
|
|
||
| override def gatherStats(row: InternalRow, ordinal: Int): Unit = { | ||
| super.gatherStats(row, ordinal) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a bug that worths a separate JIRA ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://issues.apache.org/jira/browse/SPARK-10980