Skip to content

Commit 335df89

Browse files
Si Wangmeta-codesync[bot]
authored andcommitted
Revert D86372458: feat: InputGenerator Support For Time with Time zone
Differential Revision: D86372458 Original commit changeset: f38061f96307 Original Phabricator Diff: D86372458 fbshipit-source-id: 49673dec4c62fb32d84e03aa54a3dd0dd6db4ce1
1 parent c6474fc commit 335df89

File tree

9 files changed

+73
-289
lines changed

9 files changed

+73
-289
lines changed

velox/exec/fuzzer/PrestoQueryRunnerIntermediateTypeTransforms.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "velox/functions/prestosql/types/QDigestType.h"
2626
#include "velox/functions/prestosql/types/SfmSketchType.h"
2727
#include "velox/functions/prestosql/types/TDigestType.h"
28-
#include "velox/functions/prestosql/types/TimeWithTimezoneType.h"
2928
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h"
3029
#include "velox/parse/Expressions.h"
3130
#include "velox/parse/TypeResolver.h"
@@ -70,9 +69,6 @@ intermediateTypeTransforms() {
7069
{TIME(),
7170
std::make_shared<IntermediateTypeTransformUsingCast>(
7271
TIME(), VARCHAR())},
73-
{TIME_WITH_TIME_ZONE(),
74-
std::make_shared<IntermediateTypeTransformUsingCast>(
75-
TIME_WITH_TIME_ZONE(), VARCHAR())},
7672
{BINGTILE(),
7773
std::make_shared<IntermediateTypeTransformUsingCast>(
7874
BINGTILE(), BIGINT())},

velox/functions/prestosql/types/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ velox_add_library(
3232
TDigestRegistration.cpp
3333
TimestampWithTimeZoneRegistration.cpp
3434
TimeWithTimezoneRegistration.cpp
35-
TimeWithTimezoneType.cpp
3635
SetDigestRegistration.cpp
3736
UuidRegistration.cpp
3837
VarcharEnumRegistration.cpp

velox/functions/prestosql/types/TimeWithTimezoneRegistration.cpp

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,85 @@
1818
#include "velox/expression/CastExpr.h"
1919
#include "velox/external/tzdb/time_zone.h"
2020
#include "velox/functions/prestosql/types/TimeWithTimezoneType.h"
21-
#include "velox/functions/prestosql/types/fuzzer_utils/TimeWithTimezoneInputGenerator.h"
21+
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h"
2222
#include "velox/type/Time.h"
2323
#include "velox/type/Type.h"
2424
#include "velox/type/tz/TimeZoneMap.h"
2525
#include "velox/vector/DecodedVector.h"
2626

2727
namespace facebook::velox {
2828

29+
folly::dynamic TimeWithTimezoneType::serialize() const {
30+
folly::dynamic obj = folly::dynamic::object;
31+
obj["name"] = "Type";
32+
obj["type"] = name();
33+
return obj;
34+
}
35+
36+
StringView TimeWithTimezoneType::valueToString(
37+
int64_t value,
38+
char* const startPos) const {
39+
// TIME WITH TIME ZONE is encoded similarly to TIMESTAMP WITH TIME ZONE
40+
// with the most significnat 52 bits representing the time component and the
41+
// least 12 bits representing the timezone minutes. This is different from
42+
// TIMESTAMP WITH TIMEZONE where the last 12 bits represent the timezone
43+
// offset. The timezone offset minutes are stored by value, encoded in the
44+
// type itself. This allows the type to be used in a timezone-agnostic manner.
45+
//
46+
// The time component is a 52 bit value representing the number of
47+
// milliseconds since midnight in UTC.
48+
49+
int64_t millisUtc = util::unpackMillisUtc(value);
50+
51+
// Ensure time component is within valid range
52+
VELOX_CHECK_GE(millisUtc, 0, "Time component is negative");
53+
VELOX_CHECK_LE(millisUtc, util::kMillisInDay, "Time component is too large");
54+
55+
// TimeZone's are encoded as a 12 bit value.
56+
// This represents a range of -14:00 to +14:00, with 0 representing UTC.
57+
// The range is from -840 to 840 minutes, we thus encode by doing bias
58+
// encoding and taking 840 as the bias.
59+
auto timezoneMinutes = util::unpackZoneKeyId(value);
60+
61+
VELOX_CHECK_GE(timezoneMinutes, 0, "Timezone offset is less than -14:00");
62+
VELOX_CHECK_LE(
63+
timezoneMinutes, 1680, "Timezone offset is greater than +14:00");
64+
65+
// Decode timezone offset from bias-encoded value
66+
int16_t offsetMinutes = util::decodeTimezoneOffset(timezoneMinutes);
67+
auto decodedMinutes = std::abs(offsetMinutes);
68+
69+
const auto isBehindUTCString = (offsetMinutes >= 0) ? "+" : "-";
70+
71+
// Convert UTC time to local time using utility function
72+
// Example: If UTC time is 06:30:00 and timezone is +05:30,
73+
// the local time is 12:00:00
74+
int64_t millisLocal = util::utcToLocalTime(millisUtc, offsetMinutes);
75+
76+
int64_t hours = millisLocal / util::kMillisInHour;
77+
int64_t remainingMs = millisLocal % util::kMillisInHour;
78+
int64_t minutes = remainingMs / util::kMillisInMinute;
79+
remainingMs = remainingMs % util::kMillisInMinute;
80+
int64_t seconds = remainingMs / util::kMillisInSecond;
81+
int64_t millis = remainingMs % util::kMillisInSecond;
82+
83+
int16_t offsetHours = decodedMinutes / util::kMinutesInHour;
84+
int16_t remainingOffsetMinutes = decodedMinutes % util::kMinutesInHour;
85+
86+
fmt::format_to_n(
87+
startPos,
88+
kTimeWithTimezoneToVarcharRowSize,
89+
"{:02d}:{:02d}:{:02d}.{:03d}{}{:02d}:{:02d}",
90+
hours,
91+
minutes,
92+
seconds,
93+
millis,
94+
isBehindUTCString,
95+
offsetHours,
96+
remainingOffsetMinutes);
97+
return StringView{startPos, kTimeWithTimezoneToVarcharRowSize};
98+
}
99+
29100
namespace {
30101
void castToTime(
31102
const BaseVector& input,
@@ -279,8 +350,7 @@ class TimeWithTimezoneTypeFactory : public CustomTypeFactory {
279350

280351
AbstractInputGeneratorPtr getInputGenerator(
281352
const InputGeneratorConfig& config) const override {
282-
return std::make_shared<fuzzer::TimeWithTimezoneInputGenerator>(
283-
config.seed_, config.nullRatio_);
353+
return nullptr;
284354
}
285355
};
286356

velox/functions/prestosql/types/TimeWithTimezoneType.cpp

Lines changed: 0 additions & 94 deletions
This file was deleted.

velox/functions/prestosql/types/fuzzer_utils/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
velox_add_library(
1515
velox_presto_types_fuzzer_utils
1616
TimestampWithTimeZoneInputGenerator.cpp
17-
TimeWithTimezoneInputGenerator.cpp
1817
HyperLogLogInputGenerator.cpp
1918
P4HyperLogLogInputGenerator.cpp
2019
SfmSketchInputGenerator.cpp

velox/functions/prestosql/types/fuzzer_utils/TimeWithTimezoneInputGenerator.cpp

Lines changed: 0 additions & 57 deletions
This file was deleted.

velox/functions/prestosql/types/fuzzer_utils/TimeWithTimezoneInputGenerator.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

velox/functions/prestosql/types/fuzzer_utils/tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
add_executable(
1616
velox_presto_types_fuzzer_utils_test
1717
TimestampWithTimeZoneInputGeneratorTest.cpp
18-
TimeWithTimezoneInputGeneratorTest.cpp
1918
HyperLogLogInputGeneratorTest.cpp
2019
P4HyperLogLogInputGeneratorTest.cpp
2120
SfmSketchInputGeneratorTest.cpp

0 commit comments

Comments
 (0)