GitHub user ala opened a pull request:
https://github.com/apache/spark/pull/18030
[SPARK-20798] GenerateUnsafeProjection should check if a value is null
before calling the getter
## What changes were proposed in this pull request?
GenerateUnsafeProjection.writeStructToBuffer() did not honor the assumption
that the caller must make sure that a value is not null before using the
getter. This could lead to various errors. This change fixes that behavior.
Example of code generated before:
```scala
/* 059 */ final UTF8String fieldName = value.getUTF8String(0);
/* 060 */ if (value.isNullAt(0)) {
/* 061 */ rowWriter1.setNullAt(0);
/* 062 */ } else {
/* 063 */ rowWriter1.write(0, fieldName);
/* 064 */ }
```
Example of code generated now:
```scala
/* 060 */ boolean isNull1 = value.isNullAt(0);
/* 061 */ UTF8String value1 = isNull1 ? null :
value.getUTF8String(0);
/* 062 */ if (isNull1) {
/* 063 */ rowWriter1.setNullAt(0);
/* 064 */ } else {
/* 065 */ rowWriter1.write(0, value1);
/* 066 */ }
```
## How was this patch tested?
Adds GenerateUnsafeProjectionSuite.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ala/spark fix-generate-unsafe-projection
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/18030.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #18030
----
commit 0e41a265cc498cc9368d457b8212e53f46e7482c
Author: Ala Luszczak <[email protected]>
Date: 2017-05-18T10:30:27Z
Fix GenerateUnsafeProjection.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]