rahil-c commented on code in PR #13736: URL: https://github.com/apache/hudi/pull/13736#discussion_r2286718153
########## hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/procedure/TestShowCleansProcedures.scala: ########## @@ -0,0 +1,356 @@ +/* + * 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.spark.sql.hudi.procedure + +class TestShowCleansProcedures extends HoodieSparkProcedureTestBase { + + test("Test show_clean_plans procedure") { + withSQLConf("hoodie.clean.automatic" -> "false", "hoodie.parquet.max.file.size" -> "10000") { + withTempDir { tmp => + val tableName = generateTableName + spark.sql( + s""" + |create table $tableName ( + | id int, + | name string, + | price double, + | ts long + | ) using hudi + | location '${tmp.getCanonicalPath}' + | tblproperties ( + | primaryKey = 'id', + | type = 'cow', + | preCombineField = 'ts' + | ) + |""".stripMargin) + + spark.sql(s"insert into $tableName values(1, 'a1', 10, 1000)") + spark.sql(s"insert into $tableName values(2, 'a2', 20, 2000)") + spark.sql(s"insert into $tableName values(3, 'a3', 30, 3000)") + + spark.sql(s"update $tableName set price = 11 where id = 1") + spark.sql(s"update $tableName set price = 21 where id = 2") + spark.sql(s"update $tableName set price = 12 where id = 1") + spark.sql(s"update $tableName set price = 22 where id = 2") + + spark.sql(s"call run_clean(table => '$tableName', retain_commits => 2)") + .collect() + + val firstCleanPlans = spark.sql(s"call show_clean_plans(table => '$tableName')").collect() + require(firstCleanPlans.length >= 1, "Should have at least 1 clean plan after ensuring sufficient commits") + + spark.sql(s"insert into $tableName values(4, 'a4', 40, 4000)") + spark.sql(s"update $tableName set price = 15 where id = 1") + spark.sql(s"update $tableName set price = 25 where id = 2") + spark.sql(s"update $tableName set price = 35 where id = 3") + spark.sql(s"update $tableName set price = 45 where id = 4") + + spark.sql(s"call run_clean(table => '$tableName', retain_commits => 1)") + .collect() + + val secondCleanPlans = spark.sql(s"call show_clean_plans(table => '$tableName')").collect() + require(secondCleanPlans.length >= 2, "Should have at least 2 clean plans after second clean") + + val sortedPlans = secondCleanPlans.sortBy(_.getString(0)) + val actualFirstCleanTime = sortedPlans(0).getString(0) + + val startTimeStr = (actualFirstCleanTime.toLong + 1000).toString + + val allCleanPlans = spark.sql(s"call show_clean_plans(table => '$tableName')") + allCleanPlans.show(false) + val allPlans = allCleanPlans.collect() + + assert(allPlans.length >= 2, "Should have at least 2 clean plans") + + val afterStartFilter = spark.sql(s"""call show_clean_plans(table => '$tableName', filter => 'plan_time > "$startTimeStr"')""") Review Comment: Can we add a test with a complex filter expression such as ``` - call show_cleans(table => 'my_table', filter => 'clean_time >= 20250101 AND state = COMPLETED') ``` ``` -- 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]
