Skip to content

Commit

Permalink
Make constant per query
Browse files Browse the repository at this point in the history
  • Loading branch information
acvictor committed Apr 3, 2024
1 parent 55a0168 commit d3664f6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions velox/functions/sparksql/DateTimeFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,22 @@ template <typename T>
struct CurrentTimestampFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE void call(out_type<Timestamp>& result) {
FOLLY_ALWAYS_INLINE void initialize(
const std::vector<TypePtr>& /*inputTypes*/,
const core::QueryConfig& /*config*/) {
auto now = std::chrono::system_clock::now();
auto epoch = std::chrono::duration_cast<std::chrono::microseconds>(
now.time_since_epoch())
.count();
result = Timestamp::fromMicros(epoch);
currentTimestamp_ = Timestamp::fromMicros(epoch);
}

FOLLY_ALWAYS_INLINE void call(out_type<Timestamp>& result) {
result = currentTimestamp_;
}

protected:
Timestamp currentTimestamp_;
};

template <typename T>
Expand Down

0 comments on commit d3664f6

Please sign in to comment.