From d3664f6fd91466a18cafd67ed29661972341cddb Mon Sep 17 00:00:00 2001 From: Ankita Victor Date: Wed, 3 Apr 2024 19:28:52 +0530 Subject: [PATCH] Make constant per query --- velox/functions/sparksql/DateTimeFunctions.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/velox/functions/sparksql/DateTimeFunctions.h b/velox/functions/sparksql/DateTimeFunctions.h index c1596da65399..58f1a01a8327 100644 --- a/velox/functions/sparksql/DateTimeFunctions.h +++ b/velox/functions/sparksql/DateTimeFunctions.h @@ -111,13 +111,22 @@ template struct CurrentTimestampFunction { VELOX_DEFINE_FUNCTION_TYPES(T); - FOLLY_ALWAYS_INLINE void call(out_type& result) { + FOLLY_ALWAYS_INLINE void initialize( + const std::vector& /*inputTypes*/, + const core::QueryConfig& /*config*/) { auto now = std::chrono::system_clock::now(); auto epoch = std::chrono::duration_cast( now.time_since_epoch()) .count(); - result = Timestamp::fromMicros(epoch); + currentTimestamp_ = Timestamp::fromMicros(epoch); + } + + FOLLY_ALWAYS_INLINE void call(out_type& result) { + result = currentTimestamp_; } + + protected: + Timestamp currentTimestamp_; }; template