Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,14 @@ class MiscOperatorSuite extends VeloxWholeStageTransformerSuite with AdaptiveSpa
assert(plan2.find(_.isInstanceOf[ProjectExecTransformer]).isDefined)
}

test("cast date to timestamp with GMT session timezone") {
withSQLConf(SQLConf.SESSION_LOCAL_TIMEZONE.key -> "GMT") {
runQueryAndCompare("SELECT cast(date'2023-01-02 01:01:01' as timestamp) as ts") {
checkGlutenPlan[ProjectExecTransformer]
}
}
}

test("cast timestamp to date") {
val query = "select cast(ts as date) from values (timestamp'2024-01-01 00:00:00') as tab(ts)"
runQueryAndCompare(query) {
Expand Down
11 changes: 11 additions & 0 deletions cpp/core/config/GlutenConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ parseConfMap(JNIEnv* env, const uint8_t* planData, const int32_t planDataLength)
return sparkConfs;
}

std::string normalizeSessionTimezone(std::string_view sessionTimezone) {
if (sessionTimezone == "GMT") {
return "UTC";
}
if (sessionTimezone.size() > 3 && sessionTimezone.substr(0, 3) == "GMT" &&
(sessionTimezone[3] == '+' || sessionTimezone[3] == '-')) {
return std::string("UTC").append(sessionTimezone.substr(3));
}
return std::string(sessionTimezone);
}

std::string printConfig(const std::unordered_map<std::string, std::string>& conf) {
std::ostringstream oss;
oss << std::endl;
Expand Down
3 changes: 3 additions & 0 deletions cpp/core/config/GlutenConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <jni.h>
#include <cstdint>
#include <string>
#include <string_view>
#include <unordered_map>

namespace gluten {
Expand Down Expand Up @@ -102,5 +103,7 @@ const std::string kDebugCudfDefault = "false";
std::unordered_map<std::string, std::string>
parseConfMap(JNIEnv* env, const uint8_t* planData, const int32_t planDataLength);

std::string normalizeSessionTimezone(std::string_view sessionTimezone);

std::string printConfig(const std::unordered_map<std::string, std::string>& conf);
} // namespace gluten
3 changes: 2 additions & 1 deletion cpp/velox/compute/WholeStageResultIterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ std::unordered_map<std::string, std::string> WholeStageResultIterator::getQueryC
std::to_string(veloxCfg_->get<uint64_t>(kVeloxPreferredBatchBytes, 10L << 20));
try {
configs[velox::core::QueryConfig::kSparkAnsiEnabled] = veloxCfg_->get<std::string>(kAnsiEnabled, "false");
configs[velox::core::QueryConfig::kSessionTimezone] = veloxCfg_->get<std::string>(kSessionTimezone, "");
configs[velox::core::QueryConfig::kSessionTimezone] =
normalizeSessionTimezone(veloxCfg_->get<std::string>(kSessionTimezone, ""));
// Adjust timestamp according to the above configured session timezone.
configs[velox::core::QueryConfig::kAdjustTimestampToTimezone] = "true";

Expand Down
2 changes: 1 addition & 1 deletion cpp/velox/substrait/SubstraitToVeloxPlanValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SubstraitToVeloxPlanValidator {
public:
SubstraitToVeloxPlanValidator(memory::MemoryPool* pool) {
std::unordered_map<std::string, std::string> configs{
{velox::core::QueryConfig::kSparkPartitionId, "0"}, {velox::core::QueryConfig::kSessionTimezone, "GMT"}};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the GMT to other value is enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, addressed. I updated kSessionTimezone in to UTC.

{velox::core::QueryConfig::kSparkPartitionId, "0"}, {velox::core::QueryConfig::kSessionTimezone, "UTC"}};
veloxCfg_ = std::make_shared<facebook::velox::config::ConfigBase>(std::move(configs));
planConverter_ = std::make_unique<SubstraitToVeloxPlanConverter>(
pool, veloxCfg_.get(), std::vector<std::shared_ptr<ResultIterator>>{}, std::nullopt, std::nullopt, true);
Expand Down
4 changes: 3 additions & 1 deletion cpp/velox/utils/VeloxWriterUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ std::unique_ptr<WriterOptions> makeParquetWriteOption(const std::unordered_map<s
writeOption->flushPolicyFactory = [maxRowGroupRows, maxRowGroupBytes]() {
return std::make_unique<LambdaFlushPolicy>(maxRowGroupRows, maxRowGroupBytes, [&]() { return false; });
};
writeOption->parquetWriteTimestampTimeZone = getConfigValue(sparkConfs, kSessionTimezone, std::nullopt);
if (auto it = sparkConfs.find(kSessionTimezone); it != sparkConfs.end()) {
writeOption->parquetWriteTimestampTimeZone = normalizeSessionTimezone(it->second);
}
writeOption->arrowMemoryPool =
getDefaultMemoryManager()->getOrCreateArrowMemoryPool("VeloxParquetWrite.ArrowMemoryPool");
if (auto it = sparkConfs.find(kParquetDataPageSize); it != sparkConfs.end()) {
Expand Down
Loading