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_r293118025
 
 

 ##########
 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:
   The old exists implementation:

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to