From 6015eafdae62da51a0c645e77e043db6a1b54e46 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Wed, 25 Dec 2024 20:37:27 +0800 Subject: [PATCH] Fix empty time zone --- .../sparksql/specialforms/SparkCastHooks.cpp | 17 +++++++---------- .../sparksql/specialforms/SparkCastHooks.h | 6 ++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/velox/functions/sparksql/specialforms/SparkCastHooks.cpp b/velox/functions/sparksql/specialforms/SparkCastHooks.cpp index 3c07b149fb20..05cd28fdd68d 100644 --- a/velox/functions/sparksql/specialforms/SparkCastHooks.cpp +++ b/velox/functions/sparksql/specialforms/SparkCastHooks.cpp @@ -22,7 +22,12 @@ namespace facebook::velox::functions::sparksql { SparkCastHooks::SparkCastHooks(const velox::core::QueryConfig& config) - : config_(config) {} + : config_(config) { + const auto sessionTzName = config.sessionTimezone(); + if (!sessionTzName.empty()) { + timestampToStringOptions_.timeZone = tz::locateZone(sessionTzName); + } +} Expected SparkCastHooks::castStringToTimestamp( const StringView& view) const { @@ -80,15 +85,7 @@ StringView SparkCastHooks::removeWhiteSpaces(const StringView& view) const { const TimestampToStringOptions& SparkCastHooks::timestampToStringOptions() const { - static TimestampToStringOptions options = { - .precision = TimestampToStringOptions::Precision::kMicroseconds, - .leadingPositiveSign = true, - .skipTrailingZeros = true, - .zeroPaddingYear = true, - .dateTimeSeparator = ' ', - .timeZone = tz::locateZone(config_.sessionTimezone()), - }; - return options; + return timestampToStringOptions_; } exec::PolicyType SparkCastHooks::getPolicy() const { diff --git a/velox/functions/sparksql/specialforms/SparkCastHooks.h b/velox/functions/sparksql/specialforms/SparkCastHooks.h index f30cb8af5a6f..060d82ef5214 100644 --- a/velox/functions/sparksql/specialforms/SparkCastHooks.h +++ b/velox/functions/sparksql/specialforms/SparkCastHooks.h @@ -65,5 +65,11 @@ class SparkCastHooks : public exec::CastHooks { private: const core::QueryConfig& config_; + TimestampToStringOptions timestampToStringOptions_ = { + .precision = TimestampToStringOptions::Precision::kMicroseconds, + .leadingPositiveSign = true, + .skipTrailingZeros = true, + .zeroPaddingYear = true, + .dateTimeSeparator = ' '}; }; } // namespace facebook::velox::functions::sparksql