beliefer commented on code in PR #47666:
URL: https://github.com/apache/spark/pull/47666#discussion_r1771024143
##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala:
##########
@@ -1601,6 +1603,80 @@ class JDBCV2Suite extends QueryTest with
SharedSparkSession with ExplainSuiteHel
checkAnswer(df9, Seq(Row("alex")))
}
+ test("scan with filter push-down with date_trunc function") {
+ val df1 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('SECOND', time1) = timestamp'2024-09-05 11:23:45'")
+ checkFiltersRemoved(df1)
+ val expectedPlanFragment1 =
+ "PushedFilters: [(DATE_TRUNC('SECOND', TIME1)) = 1725560625000000]"
+ checkPushedInfo(df1, expectedPlanFragment1)
+ checkAnswer(df1, Seq(Row("adam")))
+
+ val df2 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('MINUTE', time1) = timestamp'2024-09-05 11:23:00'")
+ checkFiltersRemoved(df2)
+ val expectedPlanFragment2 =
+ "PushedFilters: [(DATE_TRUNC('MINUTE', TIME1)) = 1725560580000000]"
+ checkPushedInfo(df2, expectedPlanFragment2)
+ checkAnswer(df2, Seq(Row("adam")))
+
+ val df3 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('HOUR', time1) = timestamp'2024-09-05 11:00:00'")
+ checkFiltersRemoved(df3)
+ val expectedPlanFragment3 =
+ "PushedFilters: [(DATE_TRUNC('HOUR', TIME1)) = 1725559200000000]"
+ checkPushedInfo(df3, expectedPlanFragment3)
+ checkAnswer(df3, Seq(Row("adam")))
+
+ val df4 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('DAY', time1) = timestamp'2022-05-19 00:00:00'")
+ checkFiltersRemoved(df4)
+ val expectedPlanFragment4 =
+ "PushedFilters: [(DATE_TRUNC('DAY', TIME1)) = 1652943600000000]"
+ checkPushedInfo(df4, expectedPlanFragment4)
+ checkAnswer(df4, Seq(Row("amy")))
+
+ val df5 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('MONTH', time1) = timestamp'2022-05-01 00:00:00'")
+ checkFiltersRemoved(df5)
+ val expectedPlanFragment5 =
+ "PushedFilters: [(DATE_TRUNC('MONTH', TIME1)) = 1651388400000000]"
+ checkPushedInfo(df5, expectedPlanFragment5)
+ checkAnswer(df5, Seq(Row("amy"), Row("alex")))
+
+ val df6 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('YEAR', time1) = timestamp'2022-01-01 00:00:00'")
+ checkFiltersRemoved(df6)
+ val expectedPlanFragment6 =
+ "PushedFilters: [(DATE_TRUNC('YEAR', TIME1)) = 1641024000000000]"
+ checkPushedInfo(df6, expectedPlanFragment6)
+ checkAnswer(df6, Seq(Row("amy"), Row("alex")))
+
+ val df7 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('quarter', time1) = timestamp'2024-07-01 00:00:00'")
+ checkFiltersRemoved(df7)
+ val expectedPlanFragment7 =
+ "PushedFilters: [(DATE_TRUNC('quarter', TIME1)) = 1719817200000000]"
+ checkPushedInfo(df7, expectedPlanFragment7)
+ checkAnswer(df7, Seq(Row("adam")))
+
+ val df8 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('Millisecond', time1) = timestamp'2024-09-05 11:23:45.000'")
+ checkFiltersRemoved(df8)
+ val expectedPlanFragment8 =
+ "PushedFilters: [(DATE_TRUNC('Millisecond', TIME1)) = 1725560625000000]"
+ checkPushedInfo(df8, expectedPlanFragment8)
+ checkAnswer(df8, Seq(Row("adam")))
+
+ val df9 = sql("SELECT name FROM h2.test.datetime WHERE " +
+ "DATE_TRUNC('MicroseconD', time1) = timestamp'2024-09-05
11:23:45.000000'")
+ checkFiltersRemoved(df9)
+ val expectedPlanFragment9 =
+ "PushedFilters: [(DATE_TRUNC('MicroseconD', TIME1)) = 1725560625000000]"
+ checkPushedInfo(df9, expectedPlanFragment9)
+ checkAnswer(df9, Seq(Row("adam")))
Review Comment:
Please add test cases for all supported precisions.
Please add the negative test cases, such as: `MicroSecondS`.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]