libenchao commented on code in PR #2782:
URL: https://github.com/apache/calcite/pull/2782#discussion_r860898262
##########
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##########
@@ -8977,6 +8977,43 @@ public void _testGroupExpressionEquivalenceParams() {
.rewritesTo(expected2);
}
+ @Test void testDatePartWithRewrite() {
+ final String sql = "select week(date '2022-04-27'), year(date
'2022-04-27')";
+ final String expected = "SELECT EXTRACT(WEEK FROM DATE '2022-04-27'),"
+ + " EXTRACT(YEAR FROM DATE '2022-04-27')";
+ sql(sql)
+ .withValidatorCallRewrite(true)
+ .rewritesTo(expected);
+
+ final String noParamSql = "select ^week()^";
+ sql(noParamSql)
+ .withValidatorCallRewrite(true)
+ .fails("Invalid number of arguments to function 'WEEK'. Was expecting
1 arguments");
+
+ final String multiParamsSql = "select ^week(date '2022-04-27', 1)^";
+ sql(multiParamsSql)
+ .withValidatorCallRewrite(true)
+ .fails("Invalid number of arguments to function 'WEEK'. Was expecting
1 arguments");
+ }
+
+ @Test void testDatePartWithoutRewrite() {
Review Comment:
@chunweilei Thanks for the comment. From my perspective, this duplication is
ok, I see there are some
[tests](https://github.com/apache/calcite/blob/main/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java#L5774-L5779)
which also wrote this way.
If you still think it's better to have a variable to deduplicate it, I can
change it.
--
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]