@@ -22,10 +22,8 @@ import java.nio.ByteBuffer
2222import org .apache .spark .sql .catalyst .types .NativeType
2323import org .apache .spark .sql .columnar .{ColumnType , NativeColumnType }
2424
25- private [sql] trait Encoder {
26- def gatherCompressibilityStats [T <: NativeType ](
27- value : T # JvmType ,
28- columnType : ColumnType [T , T # JvmType ]) {}
25+ private [sql] trait Encoder [T <: NativeType ] {
26+ def gatherCompressibilityStats (value : T # JvmType , columnType : NativeColumnType [T ]) {}
2927
3028 def compressedSize : Int
3129
@@ -35,10 +33,7 @@ private[sql] trait Encoder {
3533 if (uncompressedSize > 0 ) compressedSize.toDouble / uncompressedSize else 1.0
3634 }
3735
38- def compress [T <: NativeType ](
39- from : ByteBuffer ,
40- to : ByteBuffer ,
41- columnType : ColumnType [T , T # JvmType ]): ByteBuffer
36+ def compress (from : ByteBuffer , to : ByteBuffer , columnType : NativeColumnType [T ]): ByteBuffer
4237}
4338
4439private [sql] trait Decoder [T <: NativeType ] extends Iterator [T # JvmType ]
@@ -48,7 +43,7 @@ private[sql] trait CompressionScheme {
4843
4944 def supports (columnType : ColumnType [_, _]): Boolean
5045
51- def encoder : Encoder
46+ def encoder [ T <: NativeType ] : Encoder [ T ]
5247
5348 def decoder [T <: NativeType ](buffer : ByteBuffer , columnType : NativeColumnType [T ]): Decoder [T ]
5449}
@@ -58,15 +53,18 @@ private[sql] trait WithCompressionSchemes {
5853}
5954
6055private [sql] trait AllCompressionSchemes extends WithCompressionSchemes {
61- override val schemes : Seq [CompressionScheme ] = {
62- Seq (PassThrough , RunLengthEncoding , DictionaryEncoding )
63- }
56+ override val schemes : Seq [CompressionScheme ] = CompressionScheme .all
6457}
6558
6659private [sql] object CompressionScheme {
67- def apply (typeId : Int ): CompressionScheme = typeId match {
68- case PassThrough .typeId => PassThrough
69- case _ => throw new UnsupportedOperationException ()
60+ val all : Seq [CompressionScheme ] =
61+ Seq (PassThrough , RunLengthEncoding , DictionaryEncoding , BooleanBitSet , IntDelta , LongDelta )
62+
63+ private val typeIdToScheme = all.map(scheme => scheme.typeId -> scheme).toMap
64+
65+ def apply (typeId : Int ): CompressionScheme = {
66+ typeIdToScheme.getOrElse(typeId, throw new UnsupportedOperationException (
67+ s " Unrecognized compression scheme type ID: $typeId" ))
7068 }
7169
7270 def copyColumnHeader (from : ByteBuffer , to : ByteBuffer ) {
0 commit comments