Description
https://github.com/apache/spark/pull/30245 added support for creating subexpressions that are present in all branches of conditional statements. However, for a statement to be in "all branches" of a CaseWhen statement, it must also be in the elseValue. This can lead to a subexpression to be created and run for branches of a conditional that don't pass. This can cause issues especially with a UDF in a branch that gets executed assuming the condition is true. For example:
val col = when($"id" < 0, myUdf($"id")) spark.range(1).select(when(col > 0, col)).show()
myUdf($"id") gets extracted as a subexpression and executed even though both conditions don't pass and it should never be executed.