brijrajk commented on code in PR #12151:
URL: https://github.com/apache/gluten/pull/12151#discussion_r3443918216


##########
backends-velox/src/main/scala/org/apache/gluten/extension/BloomFilterMightContainFallbackPatcher.scala:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.extension
+
+import org.apache.gluten.backendsapi.BackendsApiManager
+import org.apache.gluten.config.GlutenConfig
+import org.apache.gluten.expression.VeloxBloomFilterMightContain
+import org.apache.gluten.extension.columnar.heuristic.FallbackNode
+
+import org.apache.spark.sql.catalyst.expressions.BloomFilterMightContain
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.execution.{FilterExec, SparkPlan}
+
+/**
+ * Fallback policy rule that patches `BloomFilterMightContain` -> 
`VeloxBloomFilterMightContain`
+ * inside whole-stage fallback plans when the Velox backend requires joint 
fallback.
+ *
+ * When 
[[org.apache.gluten.extension.columnar.heuristic.ExpandFallbackPolicy]] 
triggers a
+ * whole-stage fallback it returns the original vanilla Spark plan (containing 
vanilla
+ * `BloomFilterMightContain`) wrapped in a `FallbackNode`. If the bloom-filter 
producer (Stage 0)
+ * already ran natively it produced bytes in Velox's serialization format, 
which is incompatible
+ * with `BloomFilterImpl.readFrom()`. This rule replaces the vanilla 
expression with
+ * `VeloxBloomFilterMightContain`, which reads Velox-format bytes via JNI, so 
the JVM filter stage
+ * can execute correctly after falling back.
+ *
+ * This rule runs as a second fallback-policy pass, after 
`ExpandFallbackPolicy`, so it only acts
+ * when the plan is already wrapped in a `FallbackNode`.
+ */
+case class BloomFilterMightContainFallbackPatcher() extends Rule[SparkPlan] {

Review Comment:
   Done — `BloomFilterMightContainJointRewriteRule` is now a 
`Rule[LogicalPlan]` registered via `injectOptimizerRule`, modelled after 
`CollectRewriteRule`. The patcher is gone. Running as an optimizer rule ensures 
both substitutions (`BloomFilterAggregate` → `VeloxBloomFilterAggregate` and 
`BloomFilterMightContain` → `VeloxBloomFilterMightContain`) are captured in the 
`originalPlan` snapshot before `ExpandFallbackPolicy` takes it, so the byte 
format stays consistent regardless of which stages fall back. This also fixes 
the threshold=1 case where Stage 0 itself falls back (the patcher would 
incorrectly rewrite the filter side while Stage 0 was producing Spark-format 
bytes).



-- 
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]

Reply via email to