-
Notifications
You must be signed in to change notification settings - Fork 29k
[SQL][SPARK-17490] Optimize SerializeFromObject() for a primitive array #15044
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 1 commit
170e7de
327b7dd
e98cb1e
3d7ea2c
5d5ccd6
edfbce3
8b79146
b5473e3
c5378f9
d9e5b4f
d507cfc
c217395
4c679b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ package org.apache.spark.sql.catalyst | |
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.Row | ||
| import org.apache.spark.sql.catalyst.expressions.UnsafeArrayData | ||
| import org.apache.spark.sql.catalyst.util.GenericArrayData | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
| class CatalystTypeConvertersSuite extends SparkFunSuite { | ||
|
|
@@ -61,4 +63,39 @@ class CatalystTypeConvertersSuite extends SparkFunSuite { | |
| test("option handling in createToCatalystConverter") { | ||
| assert(CatalystTypeConverters.createToCatalystConverter(IntegerType)(Some(123)) === 123) | ||
| } | ||
|
|
||
| test("primitive array handing") { | ||
|
||
| val intArray = Array(1, 100, 10000) | ||
| val intUnsafeArray = UnsafeArrayData.fromPrimitiveArray(intArray) | ||
| val intArrayType = ArrayType(IntegerType, false) | ||
| assert(CatalystTypeConverters.createToScalaConverter(intArrayType)(intUnsafeArray) === intArray) | ||
| assert(CatalystTypeConverters.createToCatalystConverter(intArrayType)(intArray) | ||
| == intUnsafeArray) | ||
|
|
||
| val doubleArray = Array(1.1, 111.1, 11111.1) | ||
| val doubleUnsafeArray = UnsafeArrayData.fromPrimitiveArray(doubleArray) | ||
| val doubleArrayType = ArrayType(DoubleType, false) | ||
| assert(CatalystTypeConverters.createToScalaConverter(doubleArrayType)(doubleUnsafeArray) | ||
| === doubleArray) | ||
| assert(CatalystTypeConverters.createToCatalystConverter(doubleArrayType)(doubleArray) | ||
| == doubleUnsafeArray) | ||
| } | ||
|
|
||
| test("An array with null handing") { | ||
|
||
| val intArray = Array(1, null, 100, null, 10000) | ||
| val intGenericArray = new GenericArrayData(intArray) | ||
| val intArrayType = ArrayType(IntegerType, true) | ||
| assert(CatalystTypeConverters.createToScalaConverter(intArrayType)(intGenericArray) | ||
| === intArray) | ||
| assert(CatalystTypeConverters.createToCatalystConverter(intArrayType)(intArray) | ||
| == intGenericArray) | ||
|
|
||
| val doubleArray = Array(1.1, null, 111.1, null, 11111.1) | ||
| val doubleGenericArray = new GenericArrayData(doubleArray) | ||
| val doubleArrayType = ArrayType(DoubleType, true) | ||
| assert(CatalystTypeConverters.createToScalaConverter(doubleArrayType)(doubleGenericArray) | ||
| === doubleArray) | ||
| assert(CatalystTypeConverters.createToCatalystConverter(doubleArrayType)(doubleArray) | ||
| == doubleGenericArray) | ||
| } | ||
| } | ||
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.
do we need to do this? The
CatalystTypeConverterwill be removed and replaced by encoder eventually. Does your benchmark cover this branch?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.
My benchmark does not cover this branch.
This test causes an failure without this branch. Should we drop this test and this branch?
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.
yea let's remove them,
CatalystTypeConverterwill not be in critical path and we don't need to optimize it.