philo-he commented on code in PR #12151: URL: https://github.com/apache/gluten/pull/12151#discussion_r3455560268
########## gluten-ut/test/src/test/scala/org/apache/gluten/sql/GlutenBloomFilterFallbackSuite.scala: ########## @@ -0,0 +1,201 @@ +/* + * 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.sql + +import org.apache.gluten.backendsapi.BackendsApiManager +import org.apache.gluten.config.GlutenConfig +import org.apache.gluten.execution.WholeStageTransformerSuite + +import org.apache.spark.sql.catalyst.FunctionIdentifier +import org.apache.spark.sql.catalyst.expressions.BloomFilterMightContain +import org.apache.spark.sql.catalyst.expressions.ExpressionInfo +import org.apache.spark.sql.catalyst.expressions.aggregate.BloomFilterAggregate +import org.apache.spark.sql.internal.SQLConf + +/** + * Regression tests for https://github.com/apache/gluten/issues/12013. + * + * Verifies that `BloomFilterMightContainJointRewriteRule`, registered as a `Rule[LogicalPlan]` via + * `injectOptimizerRule`, correctly handles whole-stage AQE fallback scenarios where one or both + * bloom-filter stages revert to vanilla Spark execution. + */ +class GlutenBloomFilterFallbackSuite extends WholeStageTransformerSuite { + protected val resourcePath: String = null + protected val fileFormat: String = null + + import testImplicits._ + + private val funcIdBloomFilterAgg = FunctionIdentifier("bloom_filter_agg") + private val funcIdMightContain = FunctionIdentifier("might_contain") + + override def beforeAll(): Unit = { + super.beforeAll() + spark.sessionState.functionRegistry.registerFunction( + funcIdBloomFilterAgg, + new ExpressionInfo(classOf[BloomFilterAggregate].getName, "bloom_filter_agg"), + args => + args.size match { + case 1 => new BloomFilterAggregate(args(0)) + case 2 => new BloomFilterAggregate(args(0), args(1)) + case 3 => new BloomFilterAggregate(args(0), args(1), args(2)) + case _ => throw new IllegalArgumentException("bloom_filter_agg requires 1-3 arguments") + } + ) + spark.sessionState.functionRegistry.registerFunction( + funcIdMightContain, + new ExpressionInfo(classOf[BloomFilterMightContain].getName, "might_contain"), + args => BloomFilterMightContain(args(0), args(1))) + } + + override def afterAll(): Unit = { + spark.sessionState.functionRegistry.dropFunction(funcIdBloomFilterAgg) + spark.sessionState.functionRegistry.dropFunction(funcIdMightContain) + super.afterAll() + } + + private val veloxBloomFilterMaxNumBits = 4194304L + + // GLUTEN-12013: only filter stage falls back (threshold=2). + // bloom_filter_agg subquery runs natively and produces Velox-format bytes; the filter stage + // falls back via ExpandFallbackPolicy. The optimizer-level substitution ensures the fallback + // plan still uses VeloxBloomFilterMightContain so the JVM filter reads Velox-format bytes. + testWithMinSparkVersion( + "GLUTEN-12013: bloom_filter_agg whole-stage fallback does not corrupt bloom filter bytes", + "3.3") { Review Comment: Since 3.3 is already Gluten's minimum supported version, it might be unnecessary to use "testWithMinSparkVersion". Ditto for other tests. Thanks. -- 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]
