-
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 1 commit
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 |
---|---|---|
|
@@ -30,14 +30,19 @@ public class SparkFunctions { | |
private SparkFunctions() {} | ||
|
||
private static final Map<String, UnboundFunction> FUNCTIONS = | ||
ImmutableMap.of( | ||
"iceberg_version", new IcebergVersionFunction(), | ||
"years", new YearsFunction(), | ||
"months", new MonthsFunction(), | ||
"days", new DaysFunction(), | ||
"hours", new HoursFunction(), | ||
"bucket", new BucketFunction(), | ||
"truncate", new TruncateFunction()); | ||
new ImmutableMap.Builder<String, UnboundFunction>() | ||
.put("iceberg_version", new IcebergVersionFunction()) | ||
.put("years", new YearsFunction()) | ||
.put("year", new YearsFunction()) | ||
.put("months", new MonthsFunction()) | ||
.put("month", new MonthsFunction()) | ||
.put("days", new DaysFunction()) | ||
.put("day", new DaysFunction()) | ||
.put("hours", new HoursFunction()) | ||
.put("hour", new HoursFunction()) | ||
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. These function classes contain examples with plural styles in javadoc. Can we add another example or just update them? 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. That's a good point. Let me update the javadoc of those functions to add examples with the singular form. |
||
.put("bucket", new BucketFunction()) | ||
.put("truncate", new TruncateFunction()) | ||
.build(); | ||
|
||
private static final Map<Class<?>, UnboundFunction> CLASS_TO_FUNCTIONS = | ||
ImmutableMap.of( | ||
|
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.
We could extract a constant instead of initializing two instances.
(This comment might be conflicted with my another comment in TestSparkDaysFunction)