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