Skip to content

Commit

Permalink
Fix empty time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Dec 25, 2024
1 parent 9e5d869 commit 6015eaf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 7 additions & 10 deletions velox/functions/sparksql/specialforms/SparkCastHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Timestamp> SparkCastHooks::castStringToTimestamp(
const StringView& view) const {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions velox/functions/sparksql/specialforms/SparkCastHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6015eaf

Please sign in to comment.