-
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 7 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 |
|---|---|---|
|
|
@@ -439,6 +439,13 @@ case class MapObjects( | |
| s"boolean ${loopVar.isNull} = ${genInputData.isNull} || ${loopVar.value} == null;" | ||
| } | ||
|
|
||
| // If lambdaFunction is WrapOption, we will not determine null or not based on the | ||
| // value of loopVar.isNull, because WrapOption will return None for null. | ||
| val isWrapOption = lambdaFunction match { | ||
|
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. I'm not sure exactly what is going on here, but this looks like a hack. Ideally this node should not need to know what type its child is to operate correctly.
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. Let me explain it. When we pass in an array with None. It will be encoded as null internally. When we decode it back, WrapOption is called to re-construct it. The logic of MapObjects is to assign an element as null if its given input element is null. So It will not actually go into WrapOption to re-construct a None back. In order to do that, we need to call lambdaFunction even the element is null. But we can't simply ignore loopVar.isNull and call all kinds of lambdaFunctions. I tried before but for some lambdaFunctions, a null input value causes problematic results. In the end I can only check if lambdaFunction is WrapOption or not to make the decision here. Do you have other suggestion other than a hack like this here? Thanks.
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. @marmbrus I have refactored this part and removed the check of WrapOption now. Please take a look it if it is better now. Thanks. |
||
| case _: WrapOption => "true" | ||
| case _ => "false" | ||
| } | ||
|
|
||
| s""" | ||
| ${genInputData.code} | ||
|
|
||
|
|
@@ -456,11 +463,15 @@ case class MapObjects( | |
| ($elementJavaType)${genInputData.value}${itemAccessor(loopIndex)}; | ||
| $loopNullCheck | ||
|
|
||
| if (${loopVar.isNull}) { | ||
| if (${loopVar.isNull} && !${isWrapOption}) { | ||
| $convertedArray[$loopIndex] = null; | ||
| } else { | ||
| ${genFunction.code} | ||
| $convertedArray[$loopIndex] = ${genFunction.value}; | ||
| if (${genFunction.isNull}) { | ||
| $convertedArray[$loopIndex] = null; | ||
| } else { | ||
| $convertedArray[$loopIndex] = ${genFunction.value}; | ||
| } | ||
| } | ||
|
|
||
| $loopIndex += 1; | ||
|
|
||
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.