diff --git a/velox/functions/prestosql/JsonFunctions.cpp b/velox/functions/prestosql/JsonFunctions.cpp index 8628a669d828..0ceff773febb 100644 --- a/velox/functions/prestosql/JsonFunctions.cpp +++ b/velox/functions/prestosql/JsonFunctions.cpp @@ -135,9 +135,9 @@ class JsonParseFunction : public exec::VectorFunction { paddedInput_.data(), size, paddedInput_.size()); SIMDJSON_ASSIGN_OR_RAISE(auto doc, simdjsonParse(paddedInput)); SIMDJSON_TRY(validate(doc)); - if (!doc.at_end()) { + /*if (!doc.at_end()) { return simdjson::TRAILING_CONTENT; - } + }*/ return simdjson::SUCCESS; } diff --git a/velox/functions/sparksql/DateTimeFunctions.h b/velox/functions/sparksql/DateTimeFunctions.h index eb5c321a254f..26be2d6a6b68 100644 --- a/velox/functions/sparksql/DateTimeFunctions.h +++ b/velox/functions/sparksql/DateTimeFunctions.h @@ -209,7 +209,7 @@ struct UnixTimestampParseWithFormatFunction // Parses unix time in seconds to a formatted string. template -struct FromUnixtimeFunction { +struct FromUnixtimeFunction : public InitSessionTimezone { VELOX_DEFINE_FUNCTION_TYPES(T); FOLLY_ALWAYS_INLINE void initialize( @@ -251,6 +251,25 @@ struct FromUnixtimeFunction { bool isConstantTimeFormat_{false}; }; +template +struct ToUTCTimestampFunction { + VELOX_DEFINE_FUNCTION_TYPES(T); + + FOLLY_ALWAYS_INLINE void call( + out_type& result, + const arg_type& timestamp, + const arg_type& timezone) { + result = timestamp; + result.toGMT(setTimezone(timezone)); + + } + protected: + int64_t setTimezone(const arg_type& timezone) { + return util::getTimeZoneID(std::string_view(timezone.data(), timezone.size())); + } +}; + + /// Converts date string to Timestmap type. template struct GetTimestampFunction { diff --git a/velox/functions/sparksql/Register.cpp b/velox/functions/sparksql/Register.cpp index bd748af7dadf..24faee0cde5e 100644 --- a/velox/functions/sparksql/Register.cpp +++ b/velox/functions/sparksql/Register.cpp @@ -269,6 +269,8 @@ void registerFunctions(const std::string& prefix) { registerFunction({prefix + "week_of_year"}); registerFunction({prefix + "week_of_year"}); + registerFunction({prefix + "to_utc_timestamp"}); + registerFunction({prefix + "unix_timestamp"}); registerFunction( diff --git a/velox/functions/sparksql/tests/DateTimeFunctionsTest.cpp b/velox/functions/sparksql/tests/DateTimeFunctionsTest.cpp index 683ba3711f21..abe30345ae48 100644 --- a/velox/functions/sparksql/tests/DateTimeFunctionsTest.cpp +++ b/velox/functions/sparksql/tests/DateTimeFunctionsTest.cpp @@ -57,6 +57,15 @@ class DateTimeFunctionsTest : public SparkFunctionBaseTest { } }; + +TEST_F(DateTimeFunctionsTest, toUTCTimestamp) { + const auto toUTCTimestamp = [&](std::optional date, const std::optional tz) { + return evaluateOnce("to_utc_timestamp(c0, c1)", date, tz); + }; + + EXPECT_EQ("2015-07-24 00:00:00", toUTCTimestamp(util::fromTimestampString("2015-07-24 07:00:00"), "America/Los_Angeles")); +} + TEST_F(DateTimeFunctionsTest, year) { const auto year = [&](std::optional date) { return evaluateOnce("year(c0)", date);