-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-27987: Implement YESTERDAY UDF in Hive #4985
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
Conversation
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFYesterday.java
Outdated
Show resolved
Hide resolved
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFYesterday.java
Show resolved
Hide resolved
|
Googling some database systems, I didn't find ones with YESTERDAY or a similar UDF. But I imagine this UDF would be helpful at this point. I'm not confident though. |
Thank you for your review! I understand your confusion, actually clickhouse has similar UDF: https://clickhouse.com/docs/en/sql-reference/functions/date-time-functions#yesterday, and this function is widely used by both me and my colleagues in our daily work. |
|
|
@okumin Could you please check if this fix is ok? Thanks. |
|
@MRKKmrkk Thanks for sharing the use case. I'm putting some thoughts here.
|
| @NDV(maxNdv = 1) | ||
| public class GenericUDFYesterday extends GenericUDF { | ||
|
|
||
| protected DateWritableV2 yesterday; |
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.
This can be private.
| public DateWritableV2 getYesterday() { | ||
| return yesterday; | ||
| } | ||
|
|
||
| public void setYesterday(DateWritableV2 yesterday) { | ||
| this.yesterday = yesterday; | ||
| } |
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 should remove getYesterday and setYesterday as we never use it.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |

What changes were proposed in this pull request?
Implement YESTERDAY UDF in Hive
Why are the changes needed?
In my daily work, I frequently need to examine data from the previous day. Currently, in Hive, the only available method to obtain the date of yesterday is by using calculations like date_sub(current_date, 1). It would be convenient if Hive could introduce a method named 'yesterday' to facilitate the quick and easy retrieval of the date corresponding to the previous day.
Does this PR introduce any user-facing change?
No
Is the change a dependency upgrade?
No
How was this patch tested?
Created qtests as part of this change