You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "codope (via GitHub)" <gi...@apache.org> on 2023/08/05 15:05:40 UTC

[GitHub] [hudi] codope commented on a diff in pull request #9373: [HUDI-6651] Support IN SQL query with Record Index

codope commented on code in PR #9373:
URL: https://github.com/apache/hudi/pull/9373#discussion_r1285072066


##########
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:
   While this is a good way to validate pruning, but we're running file index again after the query. Test time is going to increase. Can we validate using physical plan?



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org