Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Dec 25, 2024
1 parent 8ebd3a8 commit bc09ed2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions velox/functions/sparksql/specialforms/SparkCastExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exec::ExprPtr SparkCastCallToSpecialForm::constructSpecialForm(
const TypePtr& type,
std::vector<exec::ExprPtr>&& compiledChildren,
bool trackCpuUsage,
const core::QueryConfig& /*config*/) {
const core::QueryConfig& config) {
VELOX_CHECK_EQ(
compiledChildren.size(),
1,
Expand All @@ -33,14 +33,14 @@ exec::ExprPtr SparkCastCallToSpecialForm::constructSpecialForm(
std::move(compiledChildren[0]),
trackCpuUsage,
false,
std::make_shared<SparkCastHooks>());
std::make_shared<SparkCastHooks>(config));
}

exec::ExprPtr SparkTryCastCallToSpecialForm::constructSpecialForm(
const TypePtr& type,
std::vector<exec::ExprPtr>&& compiledChildren,
bool trackCpuUsage,
const core::QueryConfig& /*config*/) {
const core::QueryConfig& config) {
VELOX_CHECK_EQ(
compiledChildren.size(),
1,
Expand All @@ -51,6 +51,6 @@ exec::ExprPtr SparkTryCastCallToSpecialForm::constructSpecialForm(
std::move(compiledChildren[0]),
trackCpuUsage,
true,
std::make_shared<SparkCastHooks>());
std::make_shared<SparkCastHooks>(config));
}
} // namespace facebook::velox::functions::sparksql
6 changes: 6 additions & 0 deletions velox/functions/sparksql/specialforms/SparkCastHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace facebook::velox::functions::sparksql {

SparkCastHooks(const core::QueryConfig& config) : config_(config) {}

Expected<Timestamp> SparkCastHooks::castStringToTimestamp(
const StringView& view) const {
return util::fromTimestampString(
Expand Down Expand Up @@ -83,6 +85,10 @@ const TimestampToStringOptions& SparkCastHooks::timestampToStringOptions()
.zeroPaddingYear = true,
.dateTimeSeparator = ' ',
};
const auto sessionTzName = config_.sessionTimezone();
if (!sessionTzName.empty()) {
options.timeZone = tz::locateZone(sessionTzName);
}
return options;
}

Expand Down
5 changes: 5 additions & 0 deletions velox/functions/sparksql/specialforms/SparkCastHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace facebook::velox::functions::sparksql {
// This class provides cast hooks following Spark semantics.
class SparkCastHooks : public exec::CastHooks {
public:
explicit SparkCastHooks(const core::QueryConfig& config);

// TODO: Spark hook allows more string patterns than Presto.
Expected<Timestamp> castStringToTimestamp(
const StringView& view) const override;
Expand Down Expand Up @@ -59,5 +61,8 @@ class SparkCastHooks : public exec::CastHooks {
}

exec::PolicyType getPolicy() const override;

private:
const core::QueryConfig& config_;
};
} // namespace facebook::velox::functions::sparksql

0 comments on commit bc09ed2

Please sign in to comment.