Github user cloud-fan commented on the pull request:
https://github.com/apache/spark/pull/10987#issuecomment-176987283
`Unhex` with a not nullable child:
before:
```
UTF8String value3 = i.getUTF8String(0);
boolean isNull0 = false;
byte[] value1 = null;
if (!false) {
value1 =
org.apache.spark.sql.catalyst.expressions.Hex.unhex(value3.getBytes());
isNull0 = value1 == null;
}
```
after:
```
UTF8String value3 = i.getUTF8String(0);
boolean isNull0 = false;
byte[] value1 = null;
value1 =
org.apache.spark.sql.catalyst.expressions.Hex.unhex(value3.getBytes());
isNull0 = value1 == null;
```
<br />
`Substring` with a nullable `pos`, other children are not nullable:
before:
```
/* input[0, string] */
UTF8String value3 = i.getUTF8String(0);
boolean isNull0 = true;
UTF8String value1 = null;
if (!false) {
/* input[1, int] */
boolean isNull4 = i.isNullAt(1);
int value5 = isNull4 ? -1 : (i.getInt(1));
if (!isNull4) {
/* input[2, int] */
int value7 = i.getInt(2);
if (!false) {
isNull0 = false; // resultCode could change nullability
value1 = value3.substringSQL(value5, value7);
}
}
}
```
after:
```
boolean isNull0 = true;
UTF8String value1 = null;
/* input[0, string] */
UTF8String value3 = i.getUTF8String(0);
/* input[1, int] */
boolean isNull4 = i.isNullAt(1);
int value5 = isNull4 ? -1 : (i.getInt(1));
if (!isNull4) {
/* input[2, int] */
int value7 = i.getInt(2);
isNull0 = false; // resultCode could change nullability, so this should
sit before it.
value1 = value3.substringSQL(value5, value7);
}
```
<br />
I agree that this PR makes the code a little harder to read, but not that
bad, the style of `ctx.genNullCheck` is kind of similar to if block :)
---
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]