voonhous commented on code in PR #8298: URL: https://github.com/apache/hudi/pull/8298#discussion_r1148813369
########## hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestLazyPartitionPathFetching.scala: ########## @@ -0,0 +1,130 @@ +/* + * 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 + +class TestLazyPartitionPathFetching extends HoodieSparkSqlTestBase { + + test("Test querying with string column + partition pruning") { + withTempDir { tmp => + val tableName = generateTableName + spark.sql( + s""" + |create table $tableName ( + | id int, + | name string, + | price double, + | ts long, + | grass_date string + |) using hudi + | location '${tmp.getCanonicalPath}' + | tblproperties ( + | primaryKey ='id', + | type = 'cow', + | preCombineField = 'ts' + | ) + | PARTITIONED BY (grass_date) + """.stripMargin) + spark.sql(s"insert into $tableName values(1, 'a1', 10, 1000, date('2023-02-27'))") + spark.sql(s"insert into $tableName values(2, 'a2', 10, 1000, date('2023-02-28'))") + spark.sql(s"insert into $tableName values(3, 'a3', 10, 1000, date('2023-03-01'))") + + checkAnswer(s"select id, name, price, ts from $tableName where grass_date = '2023-03-01' order by id")( + Seq(3, "a3", 10.0, 1000) + ) + } + } + + test("Test querying with date column + partition pruning") { + withTempDir { tmp => + val tableName = generateTableName + spark.sql( + s""" + |create table $tableName ( + | id int, + | name string, + | price double, + | ts long, + | grass_date date + |) using hudi + | location '${tmp.getCanonicalPath}' + | tblproperties ( + | primaryKey ='id', + | type = 'cow', + | preCombineField = 'ts' + | ) + | PARTITIONED BY (grass_date) + """.stripMargin) + spark.sql(s"insert into $tableName values(1, 'a1', 10, 1000, date('2023-02-27'))") + spark.sql(s"insert into $tableName values(2, 'a2', 10, 1000, date('2023-02-28'))") + spark.sql(s"insert into $tableName values(3, 'a3', 10, 1000, date('2023-03-01'))") + + checkAnswer(s"select id, name, price, ts from $tableName where grass_date = date'2023-03-01' order by id")( + Seq(3, "a3", 10.0, 1000) + ) + } + } + + test("Test querying with date column + partition pruning (multi-level partitioning)") { + withTempDir { tmp => + val tableName = generateTableName + spark.sql( + s""" + |create table $tableName ( + | id int, + | name string, + | price double, + | ts long, + | grass_region string, + | grass_date date + |) using hudi + | location '${tmp.getCanonicalPath}' + | tblproperties ( + | primaryKey ='id', + | type = 'cow', + | preCombineField = 'ts' + | ) + | PARTITIONED BY (grass_region, grass_date) + """.stripMargin) + spark.sql(s"set schema.on.read.enable=true") + spark.sql(s"insert into $tableName values(1, 'a1', 10, 1000, 'ID', date('2023-02-27'))") + spark.sql(s"insert into $tableName values(2, 'a2', 10, 1000, 'ID', date('2023-02-28'))") + spark.sql(s"insert into $tableName values(3, 'a3', 10, 1000, 'ID', date('2023-03-01'))") + + // test (A) that is expected to fail + // must execute this first to prevent caching + // steps into prunePartition, causing partitionPath to be incorrectly constructed + checkAnswer(s"select id, name, price, ts from $tableName " + + s"where grass_date = date'2023-03-01' and grass_region='ID' order by id")( + Seq(3, "a3", 10.0, 1000) + ) + + // test (B) that is expected to pass + // if we execute the test (B) first, cached listings will be used, test (A) will pass + // no error + checkAnswer(s"select id, name, price, ts from $tableName where grass_date = date'2023-03-01' order by id")( + Seq(3, "a3", 10.0, 1000) + ) + + // TLDR: + // execution order of [B] = pass + // execution order of [B, A] = pass + // execution order of [A] = fail + // execution order of [A, B] = fail Review Comment: Sorry, will remove these as these are just comments that were used to aid debugging. Leaving these in the final PR will only confuse any other engineers working on this component. I will also simplify the tests to only test the paths that will trigger the error. -- 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]
