-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12439][SQL] Fix toCatalystArray and MapObjects #10391
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 8 commits
788a7c6
180048c
a726fd8
090b293
7389e15
ae55e01
f5b9d50
7728124
e0d34a5
e541e04
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 |
|---|---|---|
|
|
@@ -35,7 +35,8 @@ object RowEncoder { | |
| def apply(schema: StructType): ExpressionEncoder[Row] = { | ||
| val cls = classOf[Row] | ||
| val inputObject = BoundReference(0, ObjectType(cls), nullable = true) | ||
| val extractExpressions = extractorsFor(inputObject, schema) | ||
| // We use an If expression to wrap extractorsFor result of StructType | ||
| val extractExpressions = extractorsFor(inputObject, schema).asInstanceOf[If].falseValue | ||
| val constructExpression = constructorFor(schema) | ||
|
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. same with
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. Unlike |
||
| new ExpressionEncoder[Row]( | ||
| schema, | ||
|
|
@@ -92,6 +93,7 @@ object RowEncoder { | |
| NewInstance( | ||
| classOf[GenericArrayData], | ||
| inputObject :: Nil, | ||
| propagateNull = true, | ||
|
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. |
||
| dataType = t) | ||
| case _ => MapObjects(extractorsFor(_, et), inputObject, externalDataTypeFor(et)) | ||
| } | ||
|
|
@@ -114,6 +116,7 @@ object RowEncoder { | |
| NewInstance( | ||
| classOf[ArrayBasedMapData], | ||
| convertedKeys :: convertedValues :: Nil, | ||
| propagateNull = true, | ||
| dataType = t) | ||
|
|
||
| case StructType(fields) => | ||
|
|
@@ -130,7 +133,9 @@ object RowEncoder { | |
| Invoke(inputObject, method, externalDataTypeFor(f.dataType), Literal(i) :: Nil), | ||
| f.dataType)) | ||
| } | ||
| CreateStruct(convertedFields) | ||
| If(IsNull(inputObject), | ||
| Literal.create(null, inputType), | ||
| CreateStruct(convertedFields)) | ||
| } | ||
|
|
||
| private def externalDataTypeFor(dt: DataType): DataType = dt match { | ||
|
|
@@ -222,6 +227,8 @@ object RowEncoder { | |
| Literal.create(null, externalDataTypeFor(f.dataType)), | ||
| constructorFor(GetStructField(input, i))) | ||
| } | ||
| CreateExternalRow(convertedFields) | ||
| If(IsNull(input), | ||
| Literal.create(null, externalDataTypeFor(input.dataType)), | ||
| CreateExternalRow(convertedFields)) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -456,10 +456,10 @@ case class MapObjects( | |
| ($elementJavaType)${genInputData.value}${itemAccessor(loopIndex)}; | ||
| $loopNullCheck | ||
|
|
||
| if (${loopVar.isNull}) { | ||
| ${genFunction.code} | ||
| if (${genFunction.isNull}) { | ||
|
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. Even |
||
| $convertedArray[$loopIndex] = null; | ||
| } else { | ||
| ${genFunction.code} | ||
| $convertedArray[$loopIndex] = ${genFunction.value}; | ||
| } | ||
|
|
||
|
|
||
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 part of fixing is from pr #10401. Without this, the following fixing toMapObjectswill cause null exception. Can we merge #10401 first then I do rebase here?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.
Waiting #10443 to getting merged too.