nvander1 commented on a change in pull request #24761: [SPARK-27905] [SQL] Add 
higher order function 'forall'
URL: https://github.com/apache/spark/pull/24761#discussion_r291685524
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/higherOrderFunctions.scala
 ##########
 @@ -379,6 +379,31 @@ case class ArrayFilter(
   override def prettyName: String = "filter"
 }
 
+trait ArrayExistsForAllBase
+extends ArrayBasedSimpleHigherOrderFunction with CodegenFallback {
+  def check(cond: Boolean): Boolean
+
+  override def dataType: DataType = BooleanType
+  override def functionType: AbstractDataType = BooleanType
+
+  @transient lazy val LambdaFunction(_, Seq(elementVar: NamedLambdaVariable), 
_) = function
+
+  override def nullSafeEval(inputRow: InternalRow, argumentValue: Any): Any = {
+    val arr = argumentValue.asInstanceOf[ArrayData]
+    val f = functionForEval
+    var continue = true
+    var i = 0
+    while (i < arr.numElements && continue) {
+      elementVar.value.set(arr.get(i, elementVar.dataType))
+      if (check(f.eval(inputRow).asInstanceOf[Boolean])) {
+        continue = !continue
+      }
+      i += 1
+    }
+    !check(continue)
+  }
 
 Review comment:
   I think the name for continue makes sense here, but I can see that the final 
`!check(continue)` returned value may be confusing to read. Anyone have 
suggestions to make the intent more clear here?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to