mgaido91 commented on a change in pull request #24873: [SPARK-28052][SQL] Make
`ArrayExists` follow the three-valued boolean logic.
URL: https://github.com/apache/spark/pull/24873#discussion_r293968853
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/higherOrderFunctions.scala
##########
@@ -409,16 +424,23 @@ case class ArrayExists(
override def nullSafeEval(inputRow: InternalRow, argumentValue: Any): Any = {
val arr = argumentValue.asInstanceOf[ArrayData]
val f = functionForEval
- var exists = false
+ var foundNull = false
var i = 0
- while (i < arr.numElements && !exists) {
+ while (i < arr.numElements) {
elementVar.value.set(arr.get(i, elementVar.dataType))
- if (f.eval(inputRow).asInstanceOf[Boolean]) {
- exists = true
+ val ret = f.eval(inputRow)
+ if (ret == null) {
+ foundNull = true
+ } else if (ret.asInstanceOf[Boolean]) {
+ return true
Review comment:
can we avoid using `return` here and keep the previous way we handle
`exists`? Using return is a pretty bad practice and I think here having an
extra flag we can easily avoid it..
----------------------------------------------------------------
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]