cloud-fan commented on code in PR #55973:
URL: https://github.com/apache/spark/pull/55973#discussion_r3288203191
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala:
##########
@@ -371,36 +369,53 @@ case class GetArrayItem(
}
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
- nullSafeCodeGen(ctx, ev, (eval1, eval2) => {
- val index = ctx.freshName("index")
- val childArrayElementNullable =
child.dataType.asInstanceOf[ArrayType].containsNull
- val nullCheck = if (childArrayElementNullable) {
- s"""else if ($eval1.isNullAt($index)) {
- ${ev.isNull} = true;
- }
- """
- } else {
- ""
- }
-
- val indexOutOfBoundBranch = if (failOnError) {
+ // ArrayType is split into ANSI (failOnError) and non-ANSI branches.
+ // Order matters: the guarded case must come first.
Review Comment:
These two lines were copy-pasted from `ElementAt.doGenCode`'s comment
(`collectionOperations.scala:2780-2781`), where they sit above a `left.dataType
match { case _: ArrayType if failOnError => ...; case _: ArrayType => ...; case
_: MapType => ... }` -- and there "Order matters: the guarded case must come
first" is real (the unguarded `_: ArrayType` arm would shadow the guarded one
if reordered). Here the structure is `if (failOnError) ... else ...` -- there's
no arm-ordering invariant; flipping the branches with a negated condition would
be equivalent. `nullSafeEval` just above doesn't carry the comment either, so
it doesn't document a uniform invariant. Suggest dropping the second sentence.
```suggestion
// ANSI (failOnError) and non-ANSI paths generate different codegen.
```
--
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]