-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spark: Support singular form of years, months, days, and hours functions #12117
base: main
Are you sure you want to change the base?
Changes from 2 commits
87c408b
ccf99c7
d1e6c4b
7f6ed48
9ed424e
2ea1c19
519815a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,9 @@ public void testDates() { | |
assertThat(scalarSql("SELECT system.days(date('2017-12-01'))")) | ||
.as("Expected to produce 2017-12-01") | ||
.isEqualTo(Date.valueOf("2017-12-01")); | ||
assertThat(scalarSql("SELECT system.day(date('2017-12-01'))")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also update negative test cases? e.g. testWrongNumberOfArguments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't repeat all the test cases, as it does not seem necessary. I just added a sample of each (posititive) case with the singular form to demonstrate that the form can be used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It hides the fact that these functions can throw different function names which users specified. By the way, I'm not requesting repeating all the test cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I see what you're getting at. |
||
.as("Expected to produce 2017-12-01") | ||
.isEqualTo(Date.valueOf("2017-12-01")); | ||
assertThat(scalarSql("SELECT system.days(date('1970-01-01'))")) | ||
.as("Expected to produce 1970-01-01") | ||
.isEqualTo(Date.valueOf("1970-01-01")); | ||
|
@@ -53,6 +56,9 @@ public void testTimestamps() { | |
assertThat(scalarSql("SELECT system.days(TIMESTAMP '2017-12-01 10:12:55.038194 UTC+00:00')")) | ||
.as("Expected to produce 2017-12-01") | ||
.isEqualTo(Date.valueOf("2017-12-01")); | ||
assertThat(scalarSql("SELECT system.day(TIMESTAMP '2017-12-01 10:12:55.038194 UTC+00:00')")) | ||
.as("Expected to produce 2017-12-01") | ||
.isEqualTo(Date.valueOf("2017-12-01")); | ||
assertThat(scalarSql("SELECT system.days(TIMESTAMP '1970-01-01 00:00:01.000001 UTC+00:00')")) | ||
.as("Expected to produce 1970-01-01") | ||
.isEqualTo(Date.valueOf("1970-01-01")); | ||
|
@@ -67,6 +73,9 @@ public void testTimestampNtz() { | |
assertThat(scalarSql("SELECT system.days(TIMESTAMP_NTZ '2017-12-01 10:12:55.038194 UTC')")) | ||
.as("Expected to produce 2017-12-01") | ||
.isEqualTo(Date.valueOf("2017-12-01")); | ||
assertThat(scalarSql("SELECT system.day(TIMESTAMP_NTZ '2017-12-01 10:12:55.038194 UTC')")) | ||
.as("Expected to produce 2017-12-01") | ||
.isEqualTo(Date.valueOf("2017-12-01")); | ||
assertThat(scalarSql("SELECT system.days(TIMESTAMP_NTZ '1970-01-01 00:00:01.000001 UTC')")) | ||
.as("Expected to produce 1970-01-01") | ||
.isEqualTo(Date.valueOf("1970-01-01")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ebyhr if I understand you correctly, you also suggest introducing a constructor that takes a
String name
and then havename()
return this name, right?So
new DaysFunction("day")
would return "day" when itsname()
is called, whilenew DaysFunction("days")
would return "days".I think that introduces more complexity than it's worth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want the function to be constructed with an arbitrary name. We really just want the name to be either "day" or "days" in this case. So we can have a constructor with a boolean.