-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-7199][SQL] Add date and timestamp support to UnsafeRow #5984
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 14 commits
4c07b57
e42a809
fcf8db9
752251f
b16994e
46946c6
635388a
a463e83
f4f5de6
80af342
fb532b5
281e844
9f3e577
672ef17
c30d490
0b89698
7f21ce9
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 |
|---|---|---|
|
|
@@ -103,13 +103,15 @@ public static int calculateBitSetWidthInBytes(int numFields) { | |
| IntegerType, | ||
| LongType, | ||
| FloatType, | ||
| DoubleType | ||
| DoubleType, | ||
| DateType | ||
| }))); | ||
|
|
||
| // We support get() on a superset of the types for which we support set(): | ||
| final Set<DataType> _readableFieldTypes = new HashSet<DataType>( | ||
| Arrays.asList(new DataType[]{ | ||
| StringType | ||
| StringType, | ||
| TimestampType | ||
|
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. Since timestamps are now represented as longs, we can support updates to timestamps, so we can move this into the
Member
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. OK. I will update this later.
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. ping |
||
| })); | ||
| _readableFieldTypes.addAll(settableFieldTypes); | ||
| readableFieldTypes = Collections.unmodifiableSet(_readableFieldTypes); | ||
|
|
@@ -331,8 +333,6 @@ public String getString(int i) { | |
| return getUTF8String(i).toString(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public InternalRow copy() { | ||
| throw new UnsupportedOperationException(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
|
|
||
| package org.apache.spark.sql.catalyst.expressions | ||
|
|
||
| import org.apache.spark.sql.catalyst.util.DateUtils | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.unsafe.PlatformDependent | ||
| import org.apache.spark.unsafe.array.ByteArrayMethods | ||
|
|
@@ -120,6 +122,8 @@ private object UnsafeColumnWriter { | |
| case FloatType => FloatUnsafeColumnWriter | ||
| case DoubleType => DoubleUnsafeColumnWriter | ||
| case StringType => StringUnsafeColumnWriter | ||
| case DateType => DateUnsafeColumnWriter | ||
|
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. Is it possible that we just use
Member
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. Yes. Updated now. |
||
| case TimestampType => TimestampUnsafeColumnWriter | ||
| case t => | ||
| throw new UnsupportedOperationException(s"Do not know how to write columns of type $t") | ||
| } | ||
|
|
@@ -137,6 +141,8 @@ private object LongUnsafeColumnWriter extends LongUnsafeColumnWriter | |
| private object FloatUnsafeColumnWriter extends FloatUnsafeColumnWriter | ||
| private object DoubleUnsafeColumnWriter extends DoubleUnsafeColumnWriter | ||
| private object StringUnsafeColumnWriter extends StringUnsafeColumnWriter | ||
| private object DateUnsafeColumnWriter extends DateUnsafeColumnWriter | ||
| private object TimestampUnsafeColumnWriter extends TimestampUnsafeColumnWriter | ||
|
|
||
| private abstract class PrimitiveUnsafeColumnWriter extends UnsafeColumnWriter { | ||
| // Primitives don't write to the variable-length region: | ||
|
|
@@ -258,3 +264,33 @@ private class StringUnsafeColumnWriter private() extends UnsafeColumnWriter { | |
| 8 + ByteArrayMethods.roundNumberOfBytesToNearestWord(numBytes) | ||
| } | ||
| } | ||
|
|
||
| private class DateUnsafeColumnWriter private() extends UnsafeColumnWriter { | ||
| def getSize(source: InternalRow, column: Int): Int = { | ||
| 0 | ||
| } | ||
|
|
||
| override def write( | ||
| source: InternalRow, | ||
| target: UnsafeRow, | ||
| column: Int, | ||
| appendCursor: Int): Int = { | ||
| target.setInt(column, source.getInt(column)) | ||
| 0 | ||
| } | ||
| } | ||
|
|
||
| private class TimestampUnsafeColumnWriter private() extends UnsafeColumnWriter { | ||
| def getSize(source: InternalRow, column: Int): Int = { | ||
| 0 | ||
| } | ||
|
|
||
| override def write( | ||
| source: InternalRow, | ||
| target: UnsafeRow, | ||
| column: Int, | ||
| appendCursor: Int): Int = { | ||
| target.setLong(column, source.getLong(column)) | ||
| 0 | ||
| } | ||
| } | ||
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.
remove the last comma