-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-1371][WIP] Compression support for Spark SQL in-memory columnar storage #285
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
85cc59b
Refactored ColumnAccessors & ColumnBuilders to remove duplicate code
liancheng 211331c
WIP: in-memory columnar compression support
liancheng 2780d6a
[WIP] in-memory columnar compression support
liancheng c298b76
Test suites refactored
liancheng 5034453
Bug fix, more tests, and more refactoring
liancheng d3a4fa9
Removed Ordering[T] in ColumnStats for better performance
liancheng ed71bbd
Addressed all PR comments by @marmbrus
liancheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Test suites refactored
- Loading branch information
commit c298b7666c3c920b0fd30ea86a4fe047e283a086
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,14 +19,15 @@ package org.apache.spark.sql.columnar | |
|
|
||
| import java.nio.ByteBuffer | ||
|
|
||
| import scala.util.Random | ||
|
|
||
| import org.scalatest.FunSuite | ||
|
|
||
| import org.apache.spark.sql.catalyst.types._ | ||
| import org.apache.spark.sql.columnar.ColumnarTestData._ | ||
| import org.apache.spark.sql.execution.SparkSqlSerializer | ||
|
|
||
| class ColumnTypeSuite extends FunSuite { | ||
| val DEFAULT_BUFFER_SIZE = 512 | ||
|
|
||
| val columnTypes = Seq(INT, SHORT, LONG, BYTE, DOUBLE, FLOAT, STRING, BINARY, GENERIC) | ||
|
|
||
| test("defaultSize") { | ||
|
|
@@ -55,116 +56,69 @@ class ColumnTypeSuite extends FunSuite { | |
| } | ||
| } | ||
|
|
||
| testNumericColumnType[BooleanType.type, Boolean]( | ||
| testNativeColumnStats[BooleanType.type]( | ||
| BOOLEAN, | ||
| Array.fill(4)(Random.nextBoolean()), | ||
| ByteBuffer.allocate(32), | ||
| (buffer: ByteBuffer, v: Boolean) => { | ||
| buffer.put((if (v) 1 else 0).toByte) | ||
| }, | ||
| (buffer: ByteBuffer) => { | ||
| buffer.get() == 1 | ||
| }) | ||
|
|
||
| testNumericColumnType[IntegerType.type, Int]( | ||
| testNativeColumnStats[IntegerType.type]( | ||
| INT, | ||
| Array.fill(4)(Random.nextInt()), | ||
| ByteBuffer.allocate(32), | ||
| (_: ByteBuffer).putInt(_), | ||
|
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. Nit: I believe |
||
| (_: ByteBuffer).getInt) | ||
|
|
||
| testNumericColumnType[ShortType.type, Short]( | ||
| testNativeColumnStats[ShortType.type]( | ||
| SHORT, | ||
| Array.fill(4)(Random.nextInt(Short.MaxValue).asInstanceOf[Short]), | ||
| ByteBuffer.allocate(32), | ||
| (_: ByteBuffer).putShort(_), | ||
| (_: ByteBuffer).getShort) | ||
|
|
||
| testNumericColumnType[LongType.type, Long]( | ||
| testNativeColumnStats[LongType.type]( | ||
| LONG, | ||
| Array.fill(4)(Random.nextLong()), | ||
| ByteBuffer.allocate(64), | ||
| (_: ByteBuffer).putLong(_), | ||
| (_: ByteBuffer).getLong) | ||
|
|
||
| testNumericColumnType[ByteType.type, Byte]( | ||
| testNativeColumnStats[ByteType.type]( | ||
| BYTE, | ||
| Array.fill(4)(Random.nextInt(Byte.MaxValue).asInstanceOf[Byte]), | ||
| ByteBuffer.allocate(64), | ||
| (_: ByteBuffer).put(_), | ||
| (_: ByteBuffer).get) | ||
|
|
||
| testNumericColumnType[DoubleType.type, Double]( | ||
| testNativeColumnStats[DoubleType.type]( | ||
| DOUBLE, | ||
| Array.fill(4)(Random.nextDouble()), | ||
| ByteBuffer.allocate(64), | ||
| (_: ByteBuffer).putDouble(_), | ||
| (_: ByteBuffer).getDouble) | ||
|
|
||
| testNumericColumnType[FloatType.type, Float]( | ||
| testNativeColumnStats[FloatType.type]( | ||
| FLOAT, | ||
| Array.fill(4)(Random.nextFloat()), | ||
| ByteBuffer.allocate(64), | ||
| (_: ByteBuffer).putFloat(_), | ||
| (_: ByteBuffer).getFloat) | ||
|
|
||
| test("STRING") { | ||
| val buffer = ByteBuffer.allocate(128) | ||
| val seq = Array("hello", "world", "spark", "sql") | ||
|
|
||
| seq.map(_.getBytes).foreach { bytes: Array[Byte] => | ||
| buffer.putInt(bytes.length).put(bytes) | ||
| } | ||
|
|
||
| buffer.rewind() | ||
| seq.foreach { s => | ||
| assert(s === STRING.extract(buffer)) | ||
| } | ||
|
|
||
| buffer.rewind() | ||
| seq.foreach(STRING.append(_, buffer)) | ||
|
|
||
| buffer.rewind() | ||
| seq.foreach { s => | ||
| val length = buffer.getInt | ||
| assert(length === s.getBytes.length) | ||
|
|
||
| testNativeColumnStats[StringType.type]( | ||
| STRING, | ||
| (buffer: ByteBuffer, string: String) => { | ||
| val bytes = string.getBytes() | ||
| buffer.putInt(bytes.length).put(string.getBytes) | ||
| }, | ||
| (buffer: ByteBuffer) => { | ||
| val length = buffer.getInt() | ||
| val bytes = new Array[Byte](length) | ||
| buffer.get(bytes, 0, length) | ||
| assert(s === new String(bytes)) | ||
| } | ||
| } | ||
|
|
||
| test("BINARY") { | ||
| val buffer = ByteBuffer.allocate(128) | ||
| val seq = Array.fill(4) { | ||
| val bytes = new Array[Byte](4) | ||
| Random.nextBytes(bytes) | ||
| bytes | ||
| } | ||
| new String(bytes) | ||
| }) | ||
|
|
||
| seq.foreach { bytes => | ||
| testColumnStats[BinaryType.type, Array[Byte]]( | ||
| BINARY, | ||
| (buffer: ByteBuffer, bytes: Array[Byte]) => { | ||
| buffer.putInt(bytes.length).put(bytes) | ||
| } | ||
|
|
||
| buffer.rewind() | ||
| seq.foreach { b => | ||
| assert(b === BINARY.extract(buffer)) | ||
| } | ||
|
|
||
| buffer.rewind() | ||
| seq.foreach(BINARY.append(_, buffer)) | ||
|
|
||
| buffer.rewind() | ||
| seq.foreach { b => | ||
| val length = buffer.getInt | ||
| assert(length === b.length) | ||
|
|
||
| }, | ||
| (buffer: ByteBuffer) => { | ||
| val length = buffer.getInt() | ||
| val bytes = new Array[Byte](length) | ||
| buffer.get(bytes, 0, length) | ||
| assert(b === bytes) | ||
| } | ||
| } | ||
| bytes | ||
| }) | ||
|
|
||
| test("GENERIC") { | ||
| val buffer = ByteBuffer.allocate(512) | ||
|
|
@@ -188,14 +142,22 @@ class ColumnTypeSuite extends FunSuite { | |
| assert(obj === SparkSqlSerializer.deserialize(GENERIC.extract(buffer))) | ||
| } | ||
|
|
||
| def testNumericColumnType[T <: DataType, JvmType]( | ||
| def testNativeColumnStats[T <: NativeType]( | ||
| columnType: NativeColumnType[T], | ||
| putter: (ByteBuffer, T#JvmType) => Unit, | ||
| getter: (ByteBuffer) => T#JvmType) { | ||
|
|
||
| testColumnStats[T, T#JvmType](columnType, putter, getter) | ||
| } | ||
|
|
||
| def testColumnStats[T <: DataType, JvmType]( | ||
| columnType: ColumnType[T, JvmType], | ||
| seq: Seq[JvmType], | ||
| buffer: ByteBuffer, | ||
| putter: (ByteBuffer, JvmType) => Unit, | ||
| getter: (ByteBuffer) => JvmType) { | ||
|
|
||
| val buffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE) | ||
| val columnTypeName = columnType.getClass.getSimpleName.stripSuffix("$") | ||
| val seq = (0 until 4).map(_ => makeRandomValue(columnType)) | ||
|
|
||
| test(s"$columnTypeName.extract") { | ||
| buffer.rewind() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Minor existing comment: I find this style of testing produces very cryptic failures. When something breaks all you are going to get is
4 does not equal 8. Furthermore, because the failure is in a loop the stacktrace also won't be helpful in figuring out which datatype is wrong. Finally, the correct answer forGENERICis 10 lines aways from the check, making it unnecessarily hard to read the test and see what the expected answers are.I think something like this would be clearer, and the same number of lines of code:
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.
I found
expectResultis equivalent to this and is more concise. Updated all occurrences where I think is proper.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.
Oh cool, I did not know about that. Much clearer!