-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-1292] In-memory columnar representation for Spark SQL #205
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 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
acc5c48
Added Hive test files to .gitignore
liancheng 34f3c19
Added TypeTag field to all NativeTypes
liancheng 2d09066
Added KryoSerializer
liancheng f18ddc6
Added ColumnTypes and test suite
liancheng c01a177
Added column builder classes and test suite
liancheng dbf7a38
Added ColumnAccessor and test suite, refactored ColumnBuilder
liancheng da2f4d5
Added Apache license
liancheng 214be73
Refactored BINARY and GENERIC to reduce duplicate code
liancheng b6c0a49
Minor test suite refactoring
liancheng b8a645a
Replaced KryoSerializer with an updated SparkSqlSerializer
liancheng ed8608e
Added implicit conversion from DataType to ColumnType
liancheng c701c7a
Using SparkSqlSerializer for generic object SerDe causes error, made …
liancheng 220ee1e
Added table scan operator for in-memory columnar support.
liancheng 9bcae4b
Added Apache license
liancheng a162d4d
Removed the unnecessary InMemoryColumnarRelation class
liancheng 0dbf2fb
Make necessary renaming due to rebase
liancheng af1ad5e
Fixed some minor issues introduced during rebasing
liancheng 0892ad8
Addressed ScalaStyle issues
liancheng 99dba41
Restricted new objects/classes to `private[sql]'
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,3 +45,4 @@ dist/ | |
| spark-*-bin.tar.gz | ||
| unit-tests.log | ||
| /lib/ | ||
| sql/hive/src/test/resources | ||
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
159 changes: 159 additions & 0 deletions
159
sql/core/src/main/scala/org/apache/spark/sql/columnar/ColumnAccessor.scala
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 |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql | ||
| package columnar | ||
|
|
||
| import java.nio.{ByteOrder, ByteBuffer} | ||
|
|
||
| import org.apache.spark.sql.catalyst.types.{BinaryType, NativeType, DataType} | ||
| import org.apache.spark.sql.catalyst.expressions.MutableRow | ||
| import org.apache.spark.sql.execution.SparkSqlSerializer | ||
|
|
||
| /** | ||
| * An `Iterator` like trait used to extract values from columnar byte buffer. When a value is | ||
| * extracted from the buffer, instead of directly returning it, the value is set into some field of | ||
| * a [[MutableRow]]. In this way, boxing cost can be avoided by leveraging the setter methods | ||
| * for primitive values provided by [[MutableRow]]. | ||
| */ | ||
| trait ColumnAccessor { | ||
| initialize() | ||
|
|
||
| protected def initialize() | ||
|
|
||
| def hasNext: Boolean | ||
|
|
||
| def extractTo(row: MutableRow, ordinal: Int) | ||
|
|
||
| protected def underlyingBuffer: ByteBuffer | ||
| } | ||
|
|
||
| abstract class BasicColumnAccessor[T <: DataType, JvmType](buffer: ByteBuffer) | ||
| extends ColumnAccessor { | ||
|
|
||
| protected def initialize() {} | ||
|
|
||
| def columnType: ColumnType[T, JvmType] | ||
|
|
||
| def hasNext = buffer.hasRemaining | ||
|
|
||
| def extractTo(row: MutableRow, ordinal: Int) { | ||
| doExtractTo(row, ordinal) | ||
| } | ||
|
|
||
| protected def doExtractTo(row: MutableRow, ordinal: Int) | ||
|
|
||
| protected def underlyingBuffer = buffer | ||
| } | ||
|
|
||
| abstract class NativeColumnAccessor[T <: NativeType]( | ||
| buffer: ByteBuffer, | ||
| val columnType: NativeColumnType[T]) | ||
| extends BasicColumnAccessor[T, T#JvmType](buffer) | ||
| with NullableColumnAccessor | ||
|
|
||
| class BooleanColumnAccessor(buffer: ByteBuffer) extends NativeColumnAccessor(buffer, BOOLEAN) { | ||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row.setBoolean(ordinal, columnType.extract(buffer)) | ||
| } | ||
| } | ||
|
|
||
| class IntColumnAccessor(buffer: ByteBuffer) extends NativeColumnAccessor(buffer, INT) { | ||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row.setInt(ordinal, columnType.extract(buffer)) | ||
| } | ||
| } | ||
|
|
||
| class ShortColumnAccessor(buffer: ByteBuffer) extends NativeColumnAccessor(buffer, SHORT) { | ||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row.setShort(ordinal, columnType.extract(buffer)) | ||
| } | ||
| } | ||
|
|
||
| class LongColumnAccessor(buffer: ByteBuffer) extends NativeColumnAccessor(buffer, LONG) { | ||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row.setLong(ordinal, columnType.extract(buffer)) | ||
| } | ||
| } | ||
|
|
||
| class ByteColumnAccessor(buffer: ByteBuffer) extends NativeColumnAccessor(buffer, BYTE) { | ||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row.setByte(ordinal, columnType.extract(buffer)) | ||
| } | ||
| } | ||
|
|
||
| class DoubleColumnAccessor(buffer: ByteBuffer) extends NativeColumnAccessor(buffer, DOUBLE) { | ||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row.setDouble(ordinal, columnType.extract(buffer)) | ||
| } | ||
| } | ||
|
|
||
| class FloatColumnAccessor(buffer: ByteBuffer) extends NativeColumnAccessor(buffer, FLOAT) { | ||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row.setFloat(ordinal, columnType.extract(buffer)) | ||
| } | ||
| } | ||
|
|
||
| class StringColumnAccessor(buffer: ByteBuffer) extends NativeColumnAccessor(buffer, STRING) { | ||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row.setString(ordinal, columnType.extract(buffer)) | ||
| } | ||
| } | ||
|
|
||
| class BinaryColumnAccessor(buffer: ByteBuffer) | ||
| extends BasicColumnAccessor[BinaryType.type, Array[Byte]](buffer) | ||
| with NullableColumnAccessor { | ||
|
|
||
| def columnType = BINARY | ||
|
|
||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| row(ordinal) = columnType.extract(buffer) | ||
| } | ||
| } | ||
|
|
||
| class GenericColumnAccessor(buffer: ByteBuffer) | ||
| extends BasicColumnAccessor[DataType, Array[Byte]](buffer) | ||
| with NullableColumnAccessor { | ||
|
|
||
| def columnType = GENERIC | ||
|
|
||
| override protected def doExtractTo(row: MutableRow, ordinal: Int) { | ||
| val serialized = columnType.extract(buffer) | ||
| row(ordinal) = SparkSqlSerializer.deserialize[Any](serialized) | ||
| } | ||
| } | ||
|
|
||
| object ColumnAccessor { | ||
| def apply(b: ByteBuffer): ColumnAccessor = { | ||
| // The first 4 bytes in the buffer indicates the column type. | ||
| val buffer = b.duplicate().order(ByteOrder.nativeOrder()) | ||
| val columnTypeId = buffer.getInt() | ||
|
|
||
| columnTypeId match { | ||
| case INT.typeId => new IntColumnAccessor(buffer) | ||
| case LONG.typeId => new LongColumnAccessor(buffer) | ||
| case FLOAT.typeId => new FloatColumnAccessor(buffer) | ||
| case DOUBLE.typeId => new DoubleColumnAccessor(buffer) | ||
| case BOOLEAN.typeId => new BooleanColumnAccessor(buffer) | ||
| case BYTE.typeId => new ByteColumnAccessor(buffer) | ||
| case SHORT.typeId => new ShortColumnAccessor(buffer) | ||
| case STRING.typeId => new StringColumnAccessor(buffer) | ||
| case BINARY.typeId => new BinaryColumnAccessor(buffer) | ||
| case GENERIC.typeId => new GenericColumnAccessor(buffer) | ||
| } | ||
| } | ||
| } |
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.
The test files are merged in, so we don't want this any more.