-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-18398][SQL] Fix nullabilities of MapObjects and ExternalMapToCatalyst. #15840
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
Conversation
…bda is not nullable.
Test build #68462 has finished for PR 15840 at commit
|
Jenkins, retest this please. |
On a whole this PR looks good. On a more general level, I would like to suggest that we should have a more generic way of preventing unneeded null-checks. |
Test build #68466 has finished for PR 15840 at commit
|
Do we prepare a utility method like this in def genNullableAssignment(genIsNull: boolean, isNull: boolean, lhs: String, rhs: String): String = {
if (genIsNull) {
s"""
if ($isNull) {
$lhs = null;
} else {
$lhs = rhs;
}
"""
} else {
s"$lhs = $rhs;"
}
} |
@kiszk that could be a start. However I would like to take a step back, and see which nullability checking patterns are common, and provide generic utilities for them. I also think that the proper use of |
@hvanhovell Thank for pointing out |
I found that we could use |
@hvanhovell @kiszk I tried to use |
Test build #68509 has finished for PR 15840 at commit
|
Does this approach avoid to generate code I am curious that whether the current restriction (generate only if-then) in |
@kiszk I have not checked all the case yet but I think the case that we need to generate else-clause doesn't match the case we discuss here. |
I agree that this case is fine. |
I replaced nullability checking where we can use |
@hvanhovell The pattern basically I used to replace nullability checking here is like: val eval = child.genCode(ctx)
ev.copy(code = s"""
${eval.code}
boolean ${ev.isNull} = ${eval.isNull};
${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};
if (!${ev.isNull}) {
${ev.value} = something;
}
""") into: val eval = child.genCode(ctx)
ev.copy(code = s"""
${eval.code}
${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};
""" +
ctx.nullSafeExec(child.nullable, eval.isNull)(s"""
${ev.value} = something;
"""), isNull = child.isNull) Some of them are modified to fit each case. Does this help you think about generic utilities? |
Test build #68607 has finished for PR 15840 at commit
|
Test build #68627 has finished for PR 15840 at commit
|
Test build #68629 has finished for PR 15840 at commit
|
@hvanhovell I'd like to revert some of commits in this pr which replace null checking with |
@hvanhovell Could you review this pr again, please? I reverted some commits which replace null checking with |
LGTM - pending jenkins. Small question: is it really easier for Janino to optimize ternary operators than an if/else block? |
@hvanhovell Ah, good question. I checked the Janino code around I'll revert them. |
Finally the purpose of this pr is to fix nullabilities of |
retest this please |
Test build #68931 has finished for PR 15840 at commit
|
Test build #68933 has finished for PR 15840 at commit
|
Test build #68934 has finished for PR 15840 at commit
|
Merging to master/2.1. Thanks! |
…atalyst. ## What changes were proposed in this pull request? The nullabilities of `MapObject` can be made more strict by relying on `inputObject.nullable` and `lambdaFunction.nullable`. Also `ExternalMapToCatalyst.dataType` can be made more strict by relying on `valueConverter.nullable`. ## How was this patch tested? Existing tests. Author: Takuya UESHIN <ueshin@happy-camper.st> Closes #15840 from ueshin/issues/SPARK-18398. (cherry picked from commit 9f262ae) Signed-off-by: Herman van Hovell <hvanhovell@databricks.com>
…atalyst. ## What changes were proposed in this pull request? The nullabilities of `MapObject` can be made more strict by relying on `inputObject.nullable` and `lambdaFunction.nullable`. Also `ExternalMapToCatalyst.dataType` can be made more strict by relying on `valueConverter.nullable`. ## How was this patch tested? Existing tests. Author: Takuya UESHIN <ueshin@happy-camper.st> Closes apache#15840 from ueshin/issues/SPARK-18398.
What changes were proposed in this pull request?
The nullabilities of
MapObject
can be made more strict by relying oninputObject.nullable
andlambdaFunction.nullable
.Also
ExternalMapToCatalyst.dataType
can be made more strict by relying onvalueConverter.nullable
.How was this patch tested?
Existing tests.