codope commented on code in PR #9373:
URL: https://github.com/apache/hudi/pull/9373#discussion_r1285073881
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestRecordLevelIndexWithSQL.scala:
##########
@@ -45,12 +52,71 @@ class TestRecordLevelIndexWithSQL extends
RecordLevelIndexTestBase {
validate = false)
createTempTable(hudiOpts)
- val reckey =
mergedDfList.last.limit(1).collect()(0).getAs("_row_key").toString
- spark.sql("select * from " + sqlTempTable + " where '" + reckey + "' =
_row_key").show(false)
+ testInQuery(hudiOpts)
+ testEqualToQuery(hudiOpts)
+ }
+
+ def testEqualToQuery(hudiOpts: Map[String, String]): Unit = {
+ val reckey = mergedDfList.last.limit(1).collect().map(row =>
row.getAs("_row_key").toString)
+ val dataFilter = EqualTo(attribute("_row_key"), Literal(reckey(0)))
+ assertEquals(1, spark.sql("select * from " + sqlTempTable + " where " +
dataFilter.sql).count())
+ verifyPruningFileCount(hudiOpts, dataFilter, 1)
+ }
+
+ def testInQuery(hudiOpts: Map[String, String]): Unit = {
+ var reckey = mergedDfList.last.limit(1).collect().map(row =>
row.getAs("_row_key").toString)
+ var dataFilter = In(attribute("_row_key"), reckey.map(l =>
literal(l)).toList)
+ assertEquals(1, spark.sql("select * from " + sqlTempTable + " where " +
dataFilter.sql).count())
+ var numFiles = if (isTableMOR()) 2 else 1
+ verifyPruningFileCount(hudiOpts, dataFilter, numFiles)
+
+ reckey = mergedDfList.last.limit(2).collect().map(row =>
row.getAs("_row_key").toString)
+ dataFilter = In(attribute("_row_key"), reckey.map(l => literal(l)).toList)
+ assertEquals(2, spark.sql("select * from " + sqlTempTable + " where " +
dataFilter.sql).count())
+ numFiles = if (isTableMOR()) 2 else 2
+ verifyPruningFileCount(hudiOpts, dataFilter, numFiles)
+ }
+
+ private def attribute(partition: String): AttributeReference = {
+ AttributeReference(partition, StringType, true)()
+ }
+
+ private def literal(value: String): Literal = {
+ Literal.create(value)
+ }
+
+ private def verifyPruningFileCount(opts: Map[String, String], dataFilter:
Expression, numFiles: Int): Unit = {
+ metaClient = HoodieTableMetaClient.reload(metaClient)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, opts + ("path" ->
basePath))
+ fileIndex.setIncludeLogFiles(isTableMOR())
+ val filteredPartitionDirectories = fileIndex.listFiles(Seq(),
Seq(dataFilter))
Review Comment:
Can we also add some negative tests i.e. when filter does not have equality
of IN clause on record key, then the usual scanning happens.
--
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]