viirya commented on code in PR #55941:
URL: https://github.com/apache/spark/pull/55941#discussion_r3260914309
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala:
##########
@@ -2786,21 +2788,38 @@ case class ElementAt(
""
}
val errorContext = getContextOrNullCode(ctx)
- val indexOutOfBoundBranch = if (failOnError) {
- // scalastyle:off line.size.limit
- s"throw QueryExecutionErrors.invalidElementAtIndexError($index,
$eval1.numElements(), $errorContext);"
- // scalastyle:on line.size.limit
+ val utils = classOf[ElementAtUtils].getName
+ s"""
+ |int $index = $utils.elementAtIndexExact(
+ | $eval1.numElements(), (int) $eval2, $errorContext);
+ |$nullCheck
+ |{
+ | ${ev.value} = ${CodeGenerator.getValue(eval1, dataType,
index)};
+ |}
Review Comment:
Just cosmetic.
When `$nullCheck` is empty string, there will be a `{ ... }` block scope
which is not necessary. We can get rid of it by like putting assignment into
`nullCheck`, i.e.,
```scala
val assignment = s"${ev.value} = ${CodeGenerator.getValue(eval1, dataType,
index)};"
val body = if (arrayElementNullable) {
s"""
|if ($eval1.isNullAt($index)) {
| ${ev.isNull} = true;
|} else {
| $assignment
|}
""".stripMargin
} else {
assignment
}
s"""
|int $index = $utils.elementAtIndexExact(
| $eval1.numElements(), (int) $eval2, $errorContext);
|$body
""".stripMargin
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]