cloud-fan commented on a change in pull request #28805:
URL: https://github.com/apache/spark/pull/28805#discussion_r444663796



##########
File path: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveTableScanSuite.scala
##########
@@ -187,6 +189,60 @@ class HiveTableScanSuite extends HiveComparisonTest with 
SQLTestUtils with TestH
     }
   }
 
+  test("SPARK-28169: Convert scan predicate condition to CNF") {
+    withTable("t", "temp") {
+      sql(
+        s"""
+           |CREATE TABLE t(i int)
+           |PARTITIONED BY (p int)
+           |STORED AS textfile""".stripMargin)
+      spark.range(0, 1000, 1).selectExpr("id as col")
+        .createOrReplaceTempView("temp")
+
+      for (part <- Seq(1, 2, 3, 4)) {
+        sql(
+          s"""
+             |INSERT OVERWRITE TABLE t PARTITION (p='$part')
+             |select col from temp""".stripMargin)
+      }
+
+      val scan1 = getHiveTableScanExec(
+        "SELECT * FROM t WHERE p = '1' OR (p = '2' AND i = 1)")
+      val scan2 = getHiveTableScanExec(
+        "SELECT * FROM t WHERE (p = '1' and i = 2) or (i = 1 or p = '2')")
+      val scan3 = getHiveTableScanExec(
+        "SELECT * FROM t WHERE (p = '1' and i = 2) or (p = '3' and i = 3 )")
+      val scan4 = getHiveTableScanExec(
+        "SELECT * FROM t WHERE (p = '1' and i = 2) or (p = '2' or p = '3')")
+      val scan5 = getHiveTableScanExec(
+        "SELECT * FROM t")
+      val scan6 = getHiveTableScanExec(
+        "SELECT * FROM t where p = '1' and i = 2")
+
+      val scan7 = getHiveTableScanExec(
+        """
+          |SELECT i, COUNT(1) FROM (
+          |SELECT * FROM t where  p = '1' OR (p = '2' AND i = 1)
+          |) TMP GROUP BY i
+        """.stripMargin)
+
+      assert(scan1.prunedPartitions.map(_.toString) ==
+        Stream("t(p=1)", "t(p=2)"))
+      assert(scan2.prunedPartitions.map(_.toString) ==
+        Stream("t(p=1)", "t(p=2)", "t(p=3)", "t(p=4)"))
+      assert(scan3.prunedPartitions.map(_.toString) ==
+        Stream("t(p=1)", "t(p=3)"))
+      assert(scan4.prunedPartitions.map(_.toString) ==
+        Stream("t(p=1)", "t(p=2)", "t(p=3)"))
+      assert(scan5.prunedPartitions.map(_.toString) ==
+        Stream("t(p=1)", "t(p=2)", "t(p=3)", "t(p=4)"))
+      assert(scan6.prunedPartitions.map(_.toString) ==
+        Stream("t(p=1)"))
+      assert(scan7.prunedPartitions.map(_.toString) ==
+        Stream("t(p=1)", "t(p=2)"))
+    }
+  }
+

Review comment:
       Can we test `PruneFileSourcePartitions` as well?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to