Repository navigation
perf: evaluate JVM-dispatched filter conjuncts only on rows passing preceding conjuncts - #11
Merged
Merged
Conversation
…receding conjuncts DataFusion's AND evaluates its right side on every row once more than 20% of rows pass the left side. A conjunct that runs through the JVM codegen dispatcher (ScalaUDF, regex family outside the native subset, other dispatched expressions) then costs a JNI round trip and Arrow export for rows Spark would never evaluate it on. CometFilterExec now splits the serialized deterministic predicate into its top-level conjuncts and rewrites `a AND b`, where b contains a JvmScalarUdf, into `CASE WHEN a THEN b END`. DataFusion's CaseExpr projects the columns b needs, filters them by a and evaluates b on the selected rows only. Null results reject rows just like false, so the filter output is unchanged. Scan pushdown is untouched because only the native filter predicate changes. Controlled by spark.comet.exec.filter.shortCircuitJvmDispatch.enabled (default true). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DataFusion 55's
ANDevaluates its right side on every row once more than 20% of rows pass the left side (PRE_SELECTION_THRESHOLD). When the right side is a conjunct that runs through the JVM codegen dispatcher (JvmScalarUdf: ScalaUDF, regex family outside the native subset, other dispatched built-ins), every row pays for the JNI round trip, the Arrow export and the Java evaluation. Spark never evaluates it for rows where the preceding conjuncts are false.Example: dbt
uzum_available_products, filterpublic AND hasActive AND enabledByMerchant AND NOT regexp_like(regexp_replace(lower(name), <subquery>, ''), <subquery>) AND .... The left side passes 31% of rows, so the regex ran on all rows, and Comet was 3.6x slower than vanilla.Change
CometFilterExecserde, applied only when the condition is deterministic:Andproto tree).JvmScalarUdfnode.CASE WHEN <previous segments> THEN <segment> END, and conjuncts inside a segment remain a balancedAND.CaseExpr(ExpressionOrExpression) projects only the columns the THEN branch uses, filters them by the WHEN mask and evaluates the dispatcher only on the selected rows. With no ELSE, it does not copy the rejected rows.CometFilterExec.condition(explain, plan stability) and scandataFilters/ pushdown are untouched.spark.comet.exec.filter.shortCircuitJvmDispatch.enabled(default true).Tests
CometFilterShortCircuitSuitecovers the plan rewrite (CASE depth), results equal to Spark with three-valued logic, nested AND/OR, multiple expensive conjuncts, no rewrite for OR, for a single conjunct or without dispatch, no rewrite for nondeterministic conditions, and unchanged scan pushdown. It uses a UDF that throws when it is evaluated on rows the guard rejects: it passes with the rewrite and throws with the switch off.Real data (uzum_available_products filter, 4% sample of product_products_daily_snapshot, 7.82M rows, msaf-spark-comet:joom-1.1-6 with the patched driver classes, 4 executors)
CASE WHEN a THEN b ELSE false ENDguard🤖 Generated with Claude Code