@@ -228,6 +228,110 @@ struct MakeDateFunction {
228228 }
229229};
230230
231+ template <typename T>
232+ struct QuarterFunction : public InitSessionTimezone <T>,
233+ public TimestampWithTimezoneSupport<T> {
234+ VELOX_DEFINE_FUNCTION_TYPES (T);
235+
236+ FOLLY_ALWAYS_INLINE int32_t getQuarter (const std::tm& time) {
237+ return time.tm_mon / 3 + 1 ;
238+ }
239+
240+ FOLLY_ALWAYS_INLINE void call (
241+ int32_t & result,
242+ const arg_type<Timestamp>& timestamp) {
243+ result = getQuarter (getDateTime (timestamp, this ->timeZone_ ));
244+ }
245+
246+ FOLLY_ALWAYS_INLINE void call (int32_t & result, const arg_type<Date>& date) {
247+ result = getQuarter (getDateTime (date));
248+ }
249+
250+ FOLLY_ALWAYS_INLINE void call (
251+ int32_t & result,
252+ const arg_type<TimestampWithTimezone>& timestampWithTimezone) {
253+ auto timestamp = this ->toTimestamp (timestampWithTimezone);
254+ result = getQuarter (getDateTime (timestamp, nullptr ));
255+ }
256+ };
257+
258+ template <typename T>
259+ struct MonthFunction : public InitSessionTimezone <T>,
260+ public TimestampWithTimezoneSupport<T> {
261+ VELOX_DEFINE_FUNCTION_TYPES (T);
262+
263+ FOLLY_ALWAYS_INLINE int32_t getMonth (const std::tm& time) {
264+ return 1 + time.tm_mon ;
265+ }
266+
267+ FOLLY_ALWAYS_INLINE void call (
268+ int32_t & result,
269+ const arg_type<Timestamp>& timestamp) {
270+ result = getMonth (getDateTime (timestamp, this ->timeZone_ ));
271+ }
272+
273+ FOLLY_ALWAYS_INLINE void call (int32_t & result, const arg_type<Date>& date) {
274+ result = getMonth (getDateTime (date));
275+ }
276+
277+ FOLLY_ALWAYS_INLINE void call (
278+ int32_t & result,
279+ const arg_type<TimestampWithTimezone>& timestampWithTimezone) {
280+ auto timestamp = this ->toTimestamp (timestampWithTimezone);
281+ result = getMonth (getDateTime (timestamp, nullptr ));
282+ }
283+ };
284+
285+ template <typename T>
286+ struct DayFunction : public InitSessionTimezone <T>,
287+ public TimestampWithTimezoneSupport<T> {
288+ VELOX_DEFINE_FUNCTION_TYPES (T);
289+
290+ FOLLY_ALWAYS_INLINE void call (
291+ int32_t & result,
292+ const arg_type<Timestamp>& timestamp) {
293+ result = getDateTime (timestamp, this ->timeZone_ ).tm_mday ;
294+ }
295+
296+ FOLLY_ALWAYS_INLINE void call (int32_t & result, const arg_type<Date>& date) {
297+ result = getDateTime (date).tm_mday ;
298+ }
299+
300+ FOLLY_ALWAYS_INLINE void call (
301+ int32_t & result,
302+ const arg_type<TimestampWithTimezone>& timestampWithTimezone) {
303+ auto timestamp = this ->toTimestamp (timestampWithTimezone);
304+ result = getDateTime (timestamp, nullptr ).tm_mday ;
305+ }
306+ };
307+
308+ template <typename T>
309+ struct DayOfYearFunction : public InitSessionTimezone <T>,
310+ public TimestampWithTimezoneSupport<T> {
311+ VELOX_DEFINE_FUNCTION_TYPES (T);
312+
313+ FOLLY_ALWAYS_INLINE int32_t getDayOfYear (const std::tm& time) {
314+ return time.tm_yday + 1 ;
315+ }
316+
317+ FOLLY_ALWAYS_INLINE void call (
318+ int32_t & result,
319+ const arg_type<Timestamp>& timestamp) {
320+ result = getDayOfYear (getDateTime (timestamp, this ->timeZone_ ));
321+ }
322+
323+ FOLLY_ALWAYS_INLINE void call (int32_t & result, const arg_type<Date>& date) {
324+ result = getDayOfYear (getDateTime (date));
325+ }
326+
327+ FOLLY_ALWAYS_INLINE void call (
328+ int32_t & result,
329+ const arg_type<TimestampWithTimezone>& timestampWithTimezone) {
330+ auto timestamp = this ->toTimestamp (timestampWithTimezone);
331+ result = getDayOfYear (getDateTime (timestamp, nullptr ));
332+ }
333+ };
334+
231335template <typename T>
232336struct LastDayFunction {
233337 VELOX_DEFINE_FUNCTION_TYPES (T);
0 commit comments