MCPcopy Create free account
hub / github.com/apache/impala / ToUtcUnambiguous

Method ToUtcUnambiguous

be/src/exprs/timestamp-functions.cc:176–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176TimestampVal TimestampFunctions::ToUtcUnambiguous(FunctionContext* context,
177 const TimestampVal& ts_val, const StringVal& tz_string_val,
178 const BooleanVal& expect_pre_bool_val) {
179 if (ts_val.is_null || tz_string_val.is_null) return TimestampVal::null();
180 const TimestampValue& ts_value = TimestampValue::FromTimestampVal(ts_val);
181 if (!ts_value.HasDateAndTime()) return TimestampVal::null();
182
183 const StringValue& tz_string_value = StringValue::FromStringVal(tz_string_val);
184 const Timezone* timezone = TimezoneDatabase::FindTimezone(
185 string(tz_string_value.Ptr(), tz_string_value.Len()));
186 if (UNLIKELY(timezone == nullptr)) {
187 // Although this is an error, Hive ignores it. We will issue a warning but otherwise
188 // ignore the error too.
189 stringstream ss;
190 ss << "Unknown timezone '" << tz_string_value << "'" << endl;
191 context->AddWarning(ss.str().c_str());
192 return ts_val;
193 }
194
195 TimestampValue ts_value_ret = ts_value;
196 TimestampValue pre_utc_if_repeated;
197 TimestampValue post_utc_if_repeated;
198 ts_value_ret.LocalToUtc(*timezone, &pre_utc_if_repeated, &post_utc_if_repeated);
199
200 TimestampVal ts_val_ret;
201 if (LIKELY(ts_value_ret.HasDateAndTime())) {
202 ts_value_ret.ToTimestampVal(&ts_val_ret);
203 } else {
204 if (expect_pre_bool_val.is_null) {
205 const string& msg =
206 Substitute("Timestamp '$0' in timezone '$1' could not be converted to UTC",
207 ts_value.ToString(), tz_string_value.DebugString());
208 context->AddWarning(msg.c_str());
209 return TimestampVal::null();
210 }
211 if (expect_pre_bool_val.val) {
212 pre_utc_if_repeated.ToTimestampVal(&ts_val_ret);
213 } else {
214 if (pre_utc_if_repeated == post_utc_if_repeated) {
215 return TimestampVal::null();
216 } else {
217 post_utc_if_repeated.ToTimestampVal(&ts_val_ret);
218 }
219 }
220 }
221
222 return ts_val_ret;
223}
224
225
226// The purpose of making this .cc only is to avoid moving the code of

Callers

nothing calls this directly

Calls 10

SubstituteFunction · 0.85
HasDateAndTimeMethod · 0.80
AddWarningMethod · 0.80
LocalToUtcMethod · 0.80
ToTimestampValMethod · 0.80
PtrMethod · 0.45
LenMethod · 0.45
strMethod · 0.45
ToStringMethod · 0.45
DebugStringMethod · 0.45

Tested by

no test coverage detected