dongjoon-hyun opened a new pull request, #60568: URL: https://github.com/apache/spark/pull/60568
### What changes were proposed in this pull request? This PR fixes `InjectRuntimeFilter` to keep scalar external UDFs (`ExternalUserDefinedFunction`) out of runtime bloom filters, as it keeps Python UDFs out. - `injectBloomFilter` skips a bloom filter whose creation-side subquery has `EXTERNAL_UDF`, as it skips one with `PYTHON_UDF` since SPARK-58310. - `isSimpleExpression` excludes `EXTERNAL_UDF`, like `PYTHON_UDF` and `SCALA_UDF`. So a scalar external UDF in a creation-side filter or in a join key no longer counts as a simple expression. ### Why are the changes needed? SPARK-58467 added the planning of scalar external UDFs to the unreleased Apache Spark 4.4.0. `ExternalUserDefinedFunction` is `Unevaluable`, and `PlanExternalUDFs` extracts it into an `ExecuteExternalUDF` node before physical planning. `InjectRuntimeFilter` runs after subquery optimization and adds a new `ScalarSubquery` over the creation side of a join, but `PlanExternalUDFs` rewrites only the main plan. So a scalar external UDF that the subquery of the bloom filter reads reaches execution as it is, and the query fails. SPARK-58310 fixed the same problem for Python UDFs before scalar external UDFs were added. For example, the following queries of the new test case fail when `ext` is a deterministic scalar external UDF and `spark.sql.execution.udf.unified.execution.enabled` is `true`. The first one has the UDF in a filter of the creation side, and the second one in the join key of the creation side. ```sql SELECT * FROM bf1 JOIN bf2 ON bf1.c1 = bf2.c2 WHERE ext(bf2.a2) = 62; -- org.apache.spark.SparkException: [INTERNAL_ERROR] Cannot generate code for expression: ext(input[0, int, true])#45859 SQLSTATE: XX000 SELECT * FROM (SELECT ext(c2) c2 FROM bf2 WHERE a2 = 62) t LEFT JOIN bf1 ON t.c2 = bf1.c1; -- org.apache.spark.SparkException: [INTERNAL_ERROR] Cannot generate code for expression: ext(input[1, int, true])#45914 SQLSTATE: XX000 ``` `isSimpleExpression` lists the expressions that are too expensive for a runtime filter, such as Python and Scala UDFs. A scalar external UDF runs in a worker process like a Python UDF, so it belongs there too. Then a join key with a scalar external UDF gets no bloom filter, which would evaluate the UDF on its side apart from the join, and a creation-side filter with one stops the search for a creation side. `injectBloomFilter` still needs its check for a UDF in a projection above the creation-side filters, like the second query above, since `isSimpleExpression` does not see it. ### Does this PR introduce _any_ user-facing change? No. Scalar external UDF planning is not released yet, and no public API builds a scalar external UDF. ### How was this patch tested? Pass the CIs with the newly added test case in `InjectRuntimeFilterSuite`. It registers a scalar external UDF as a function and checks that the two queries above and a query with the UDF in the join key of the application side get no bloom filter, while the same query without the UDF still gets one. It fails without this change. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 -- 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]
