This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/master/pr-21088-b53aaecb6a5e15e59c87ba47cd79f985c6c642ab in repository https://gitbox.apache.org/repos/asf/hudi.git
commit 16dcda154e6d808d39fa8eab8d80646756be56aa Author: voonhous <[email protected]> AuthorDate: Fri Dec 4 14:33:31 2026 +0000 test(spark): cover filters on another function of an expression index column (#21088) An expression index on lower(rider) must not answer upper(rider), length(rider) or other functions of the column. Ported from #20256. Co-authored-by: Y Ethan Guo <[email protected]> --- .../hudi/feature/index/TestExpressionIndex.scala | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/feature/index/TestExpressionIndex.scala b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/feature/index/TestExpressionIndex.scala index a8055a997a49..300f7880702f 100644 --- a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/feature/index/TestExpressionIndex.scala +++ b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/feature/index/TestExpressionIndex.scala @@ -2042,6 +2042,55 @@ class TestExpressionIndex extends HoodieSparkSqlTestBase with SparkAdapterSuppor } } + /** + * Filters on a different function of the indexed column must not be evaluated against the expression index. + */ + test("Test Expression Index Is Not Used For Filters On Another Function") { + withTempDir { tmp => + Seq("cow", "mor").foreach { tableType => + val tableName = generateTableName + s"_other_function_$tableType" + val basePath = s"${tmp.getCanonicalPath}/$tableName" + withSQLConf("hoodie.fileIndex.dataSkippingFailureMode" -> "strict", + "hoodie.metadata.enable" -> "true", + "hoodie.enable.data.skipping" -> "true", + "hoodie.parquet.small.file.limit" -> "0") { + spark.sql( + s""" + |create table $tableName ( + | id string, + | rider string, + | ts long + |) using hudi + | options ( + | primaryKey ='id', + | type = '$tableType', + | preCombineField = 'ts' + | ) + | location '$basePath' + |""".stripMargin) + spark.sql(s"insert into $tableName values ('trip1', 'rider-A', 1), ('trip2', 'rider-C', 2)") + spark.sql(s"insert into $tableName values ('trip3', 'rider-E', 3), ('trip4', 'rider-C', 4)") + spark.sql(s"update $tableName set ts = 10 where id = 'trip4'") + spark.sql(s"create index idx_lower on $tableName using column_stats(rider) options(expr='lower')") + val metaClient = createMetaClient(spark, basePath) + if (tableType == "mor") { + assertTrue(getLatestDataFilesCount(metaClient = metaClient) > getLatestDataFilesCount(includeLogFiles = false, metaClient = metaClient)) + } + + checkAnswer(s"select id from $tableName where upper(rider) = 'RIDER-C'")(Seq("trip2"), Seq("trip4")) + checkAnswer(s"select id from $tableName where upper(rider) in ('RIDER-A', 'RIDER-E')")(Seq("trip1"), Seq("trip3")) + checkAnswer(s"select id from $tableName where length(rider) = 7")(Seq("trip1"), Seq("trip2"), Seq("trip3"), Seq("trip4")) + checkAnswer(s"select id from $tableName where lower(rider) = 'rider-c'")(Seq("trip2"), Seq("trip4")) + + val tableSchema = StructType(Seq(StructField("id", StringType), StructField("rider", StringType), StructField("ts", LongType))) + val opts = Map(DataSourceReadOptions.ENABLE_DATA_SKIPPING.key -> "true", HoodieMetadataConfig.ENABLE.key -> "true") + val lowerExpr = resolveExpr(spark, sparkAdapter.getExpressionFromColumn(functions.lower(functions.col("rider"))), tableSchema) + verifyFilePruning(opts, EqualTo(lowerExpr, Literal.create("rider-e")), metaClient, isDataSkippingExpected = true) + } + } + } + } + test("Test bloom filters index pruning") { withTempDir { tmp => Seq("cow", "mor").foreach { tableType =>
