Kimahriman commented on code in PR #34558:
URL: https://github.com/apache/spark/pull/34558#discussion_r1239152129
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/higherOrderFunctions.scala:
##########
@@ -781,6 +1007,49 @@ case class ArrayForAll(
}
}
+ override protected def doGenCode(ctx: CodegenContext, ev: ExprCode):
ExprCode = {
+ ctx.withLambdaVars(Seq(elementVar), { case Seq(elementCode) =>
+ nullSafeCodeGen(ctx, ev, arg => {
+ val numElements = ctx.freshName("numElements")
+ val forall = ctx.freshName("forall")
+ val foundNull = ctx.freshName("foundNull")
+ val i = ctx.freshName("i")
+
+ val functionCode = function.genCode(ctx)
+ val elementAssignment = assignArrayElement(ctx, arg, elementCode,
elementVar, i)
+
+ val nullCheck = if (nullable) {
+ s"""
+ if ($forall && $foundNull) {
+ ${ev.isNull} = true;
+ }
+ """
+ } else {
+ ""
+ }
+
+ s"""
+ |final int $numElements = ${arg}.numElements();
+ |boolean $forall = true;
+ |boolean $foundNull = false;
+ |int $i = 0;
+ |while ($i < $numElements && $forall) {
+ | $elementAssignment
+ | ${functionCode.code}
+ | if (${functionCode.isNull}) {
+ | $foundNull = true;
+ | } else if (!${functionCode.value}) {
+ | $forall = false;
+ | }
+ | $i++;
+ |}
+ |$nullCheck
+ |${ev.value} = $forall;
+ """.stripMargin
+ })
+ })
+ }
+
Review Comment:
I'll have to look at this a little bit. It's tricky because there's a few
places they are different (default true vs false, `!`'d for one and not the
other, the `followThreeValuedLogic` flag for exists)
--
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]