MCPcopy Create free account
hub / github.com/apache/impala / GoBackToWeekday

Function GoBackToWeekday

be/src/exprs/udf-builtins.cc:81–92  ·  view source on GitHub ↗

Returns the most recent date, no later than orig_date, which is on week_day week_day: 0==Sunday, 1==Monday, ...

Source from the content-addressed store, hash-verified

79// Returns the most recent date, no later than orig_date, which is on week_day
80// week_day: 0==Sunday, 1==Monday, ...
81date GoBackToWeekday(const date& orig_date, int week_day) {
82 int current_week_day = orig_date.day_of_week();
83 int diff = current_week_day - week_day;
84 if (diff == 0) return orig_date;
85 if (diff > 0) {
86 // ex. Weds(3) shifts to Tues(2), so we go back 1 day
87 return orig_date - date_duration(diff);
88 }
89 // ex. Tues(2) shifts to Weds(3), so we go back 6 days
90 DCHECK_LT(diff, 0);
91 return orig_date - date_duration(7 + diff);
92}
93
94// Maps the user facing name of a unit to a TruncUnit used by DateTrunc function
95// Returns the TruncUnit for the given string

Callers 5

TruncWeekFunction · 0.85
TruncWWFunction · 0.85
TruncWFunction · 0.85
TruncDayOfWeekFunction · 0.85
DoTruncFunction · 0.85

Calls 3

WeekDayMethod · 0.80
AddDaysMethod · 0.80
IsValidMethod · 0.45

Tested by

no test coverage detected